protected CreateSimpleLexer sourceDecorator(Map<String,Object> options) throws Exception {
  List<List<Object>> shortcutStylePatterns=new ArrayList<List<Object>>();
  List<List<Object>> fallthroughStylePatterns=new ArrayList<List<Object>>();
  if (Util.getVariableValueAsBoolean(options.get("tripleQuotedStrings"))) {
    shortcutStylePatterns.add(Arrays.asList(new Object[]{PR_STRING,Pattern.compile("^(?:\\'\\'\\'(?:[^\\'\\\\]|\\\\[\\s\\S]|\\'{1,2}(?=[^\\']))*(?:\\'\\'\\'|$)|\\\"\\\"\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S]|\\\"{1,2}(?=[^\\\"]))*(?:\\\"\\\"\\\"|$)|\\'(?:[^\\\\\\']|\\\\[\\s\\S])*(?:\\'|$)|\\\"(?:[^\\\\\\\"]|\\\\[\\s\\S])*(?:\\\"|$))"),null,"'\""}));
  }
 else   if (Util.getVariableValueAsBoolean(options.get("multiLineStrings"))) {
    shortcutStylePatterns.add(Arrays.asList(new Object[]{PR_STRING,Pattern.compile("^(?:\\'(?:[^\\\\\\']|\\\\[\\s\\S])*(?:\\'|$)|\\\"(?:[^\\\\\\\"]|\\\\[\\s\\S])*(?:\\\"|$)|\\`(?:[^\\\\\\`]|\\\\[\\s\\S])*(?:\\`|$))"),null,"'\"`"}));
  }
 else {
    shortcutStylePatterns.add(Arrays.asList(new Object[]{PR_STRING,Pattern.compile("^(?:\\'(?:[^\\\\\\'\r\n]|\\\\.)*(?:\\'|$)|\\\"(?:[^\\\\\\\"\r\n]|\\\\.)*(?:\\\"|$))"),null,"\"'"}));
  }
  if (Util.getVariableValueAsBoolean(options.get("verbatimStrings"))) {
    fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_STRING,Pattern.compile("^@\\\"(?:[^\\\"]|\\\"\\\")*(?:\\\"|$)"),null}));
  }
  Object hc=options.get("hashComments");
  if (Util.getVariableValueAsBoolean(hc)) {
    if (Util.getVariableValueAsBoolean(options.get("cStyleComments"))) {
      if ((hc instanceof Integer) && (Integer)hc > 1) {
        shortcutStylePatterns.add(Arrays.asList(new Object[]{PR_COMMENT,Pattern.compile("^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)"),null,"#"}));
      }
 else {
        shortcutStylePatterns.add(Arrays.asList(new Object[]{PR_COMMENT,Pattern.compile("^#(?:(?:define|e(?:l|nd)if|else|error|ifn?def|include|line|pragma|undef|warning)\\b|[^\r\n]*)"),null,"#"}));
      }
      fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_STRING,Pattern.compile("^<(?:(?:(?:\\.\\.\\/)*|\\/?)(?:[\\w-]+(?:\\/[\\w-]+)+)?[\\w-]+\\.h(?:h|pp|\\+\\+)?|[a-z]\\w*)>"),null}));
    }
 else {
      shortcutStylePatterns.add(Arrays.asList(new Object[]{PR_COMMENT,Pattern.compile("^#[^\r\n]*"),null,"#"}));
    }
  }
  if (Util.getVariableValueAsBoolean(options.get("cStyleComments"))) {
    fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_COMMENT,Pattern.compile("^\\/\\/[^\r\n]*"),null}));
    fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_COMMENT,Pattern.compile("^\\/\\*[\\s\\S]*?(?:\\*\\/|$)"),null}));
  }
  Object regexLiterals=options.get("regexLiterals");
  if (Util.getVariableValueAsBoolean(regexLiterals)) {
    String regexExcls=Util.getVariableValueAsInteger(regexLiterals) > 1 ? "" : "\n\r";
    String regexAny=!regexExcls.isEmpty() ? "." : "[\\S\\s]";
    String REGEX_LITERAL="/(?=[^/*" + regexExcls + "])"+ "(?:[^/\\x5B\\x5C"+ regexExcls+ "]"+ "|\\x5C"+ regexAny+ "|\\x5B(?:[^\\x5C\\x5D"+ regexExcls+ "]"+ "|\\x5C"+ regexAny+ ")*(?:\\x5D|$))+"+ "/";
    fallthroughStylePatterns.add(Arrays.asList(new Object[]{"lang-regex",Pattern.compile("^" + REGEXP_PRECEDER_PATTERN + "("+ REGEX_LITERAL+ ")")}));
  }
  Pattern types=(Pattern)options.get("types");
  if (Util.getVariableValueAsBoolean(types)) {
    fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_TYPE,types}));
  }
  String keywords=(String)options.get("keywords");
  if (keywords != null) {
    keywords=keywords.replaceAll("^ | $","");
    if (keywords.length() != 0) {
      fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_KEYWORD,Pattern.compile("^(?:" + keywords.replaceAll("[\\s,]+","|") + ")\\b"),null}));
    }
  }
  shortcutStylePatterns.add(Arrays.asList(new Object[]{PR_PLAIN,Pattern.compile("^\\s+"),null," \r\n\t" + Character.toString((char)0xA0)}));
  fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_LITERAL,Pattern.compile("^@[a-z_$][a-z_$@0-9]*",Pattern.CASE_INSENSITIVE),null}));
  fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_TYPE,Pattern.compile("^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\\w+_t\\b)"),null}));
  fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_PLAIN,Pattern.compile("^[a-z_$][a-z_$@0-9]*",Pattern.CASE_INSENSITIVE),null}));
  fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_LITERAL,Pattern.compile("^(?:" + "0x[a-f0-9]+" + "|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)"+ "(?:e[+\\-]?\\d+)?" + ')' + "[a-z]*",Pattern.CASE_INSENSITIVE),null,"0123456789"}));
  fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_PLAIN,Pattern.compile("^\\\\[\\s\\S]?"),null}));
  String punctuation="^.[^\\s\\w.$@'\"`/\\\\]*";
  if (Util.getVariableValueAsBoolean(options.get("regexLiterals"))) {
    punctuation+="(?!\\s*/)";
  }
  fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_PUNCTUATION,Pattern.compile(punctuation),null}));
  return new CreateSimpleLexer(shortcutStylePatterns,fallthroughStylePatterns);
}

protected CreateSimpleLexer sourceDecorator ( Map < String , Object > options ) throws Exception { List < List < Object > > shortcutStylePatterns = new ArrayList < List < Object > > ( ) ; List < List < Object > > fallthroughStylePatterns = new ArrayList < List < Object > > ( ) ; if ( Util . getVariableValueAsBoolean ( options . get ( "tripleQuotedStrings" ) ) ) { shortcutStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_STRING , Pattern . compile ( "^(?:\\'\\'\\'(?:[^\\'\\\\]|\\\\[\\s\\S]|\\'{1,2}(?=[^\\']))*(?:\\'\\'\\'|$)|\\\"\\\"\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S]|\\\"{1,2}(?=[^\\\"]))*(?:\\\"\\\"\\\"|$)|\\'(?:[^\\\\\\']|\\\\[\\s\\S])*(?:\\'|$)|\\\"(?:[^\\\\\\\"]|\\\\[\\s\\S])*(?:\\\"|$))" ) , null , "'\"" } ) ) ; } else if ( Util . getVariableValueAsBoolean ( options . get ( "multiLineStrings" ) ) ) { shortcutStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_STRING , Pattern . compile ( "^(?:\\'(?:[^\\\\\\']|\\\\[\\s\\S])*(?:\\'|$)|\\\"(?:[^\\\\\\\"]|\\\\[\\s\\S])*(?:\\\"|$)|\\`(?:[^\\\\\\`]|\\\\[\\s\\S])*(?:\\`|$))" ) , null , "'\"`" } ) ) ; } else { shortcutStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_STRING , Pattern . compile ( "^(?:\\'(?:[^\\\\\\'\r\n]|\\\\.)*(?:\\'|$)|\\\"(?:[^\\\\\\\"\r\n]|\\\\.)*(?:\\\"|$))" ) , null , "\"'" } ) ) ; } if ( Util . getVariableValueAsBoolean ( options . get ( "verbatimStrings" ) ) ) { fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_STRING , Pattern . compile ( "^@\\\"(?:[^\\\"]|\\\"\\\")*(?:\\\"|$)" ) , null } ) ) ; } Object hc = options . get ( "hashComments" ) ; if ( Util . getVariableValueAsBoolean ( hc ) ) { if ( Util . getVariableValueAsBoolean ( options . get ( "cStyleComments" ) ) ) { if ( ( hc instanceof Integer ) && ( Integer ) hc > 1 ) { shortcutStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_COMMENT , Pattern . compile ( "^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)" ) , null , "#" } ) ) ; } else { shortcutStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_COMMENT , Pattern . compile ( "^#(?:(?:define|e(?:l|nd)if|else|error|ifn?def|include|line|pragma|undef|warning)\\b|[^\r\n]*)" ) , null , "#" } ) ) ; } fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_STRING , Pattern . compile ( "^<(?:(?:(?:\\.\\.\\/)*|\\/?)(?:[\\w-]+(?:\\/[\\w-]+)+)?[\\w-]+\\.h(?:h|pp|\\+\\+)?|[a-z]\\w*)>" ) , null } ) ) ; } else { shortcutStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_COMMENT , Pattern . compile ( "^#[^\r\n]*" ) , null , "#" } ) ) ; } } if ( Util . getVariableValueAsBoolean ( options . get ( "cStyleComments" ) ) ) { fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_COMMENT , Pattern . compile ( "^\\/\\/[^\r\n]*" ) , null } ) ) ; fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_COMMENT , Pattern . compile ( "^\\/\\*[\\s\\S]*?(?:\\*\\/|$)" ) , null } ) ) ; } Object regexLiterals = options . get ( "regexLiterals" ) ; if ( Util . getVariableValueAsBoolean ( regexLiterals ) ) { String regexExcls = Util . getVariableValueAsInteger ( regexLiterals ) > 1 ? "" : "\n\r" ; String regexAny = ! regexExcls . isEmpty ( ) ? "." : "[\\S\\s]" ; String REGEX_LITERAL = "/(?=[^/*" + regexExcls + "])" + "(?:[^/\\x5B\\x5C" + regexExcls + "]" + "|\\x5C" + regexAny + "|\\x5B(?:[^\\x5C\\x5D" + regexExcls + "]" + "|\\x5C" + regexAny + ")*(?:\\x5D|$))+" + "/" ; fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { "lang-regex" , Pattern . compile ( "^" + REGEXP_PRECEDER_PATTERN + "(" + REGEX_LITERAL + ")" ) } ) ) ; } Pattern types = ( Pattern ) options . get ( "types" ) ; if ( Util . getVariableValueAsBoolean ( types ) ) { fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_TYPE , types } ) ) ; } String keywords = ( String ) options . get ( "keywords" ) ; if ( keywords != null ) { keywords = keywords . replaceAll ( "^ | $" , "" ) ; if ( keywords . length ( ) != 0 ) { fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_KEYWORD , Pattern . compile ( "^(?:" + keywords . replaceAll ( "[\\s,]+" , "|" ) + ")\\b" ) , null } ) ) ; } } shortcutStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_PLAIN , Pattern . compile ( "^\\s+" ) , null , " \r\n\t" + Character . toString ( ( char ) 0xA0 ) } ) ) ; fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_LITERAL , Pattern . compile ( "^@[a-z_$][a-z_$@0-9]*" , Pattern . CASE_INSENSITIVE ) , null } ) ) ; fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_TYPE , Pattern . compile ( "^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\\w+_t\\b)" ) , null } ) ) ; fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_PLAIN , Pattern . compile ( "^[a-z_$][a-z_$@0-9]*" , Pattern . CASE_INSENSITIVE ) , null } ) ) ; fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_LITERAL , Pattern . compile ( "^(?:" + "0x[a-f0-9]+" + "|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)" + "(?:e[+\\-]?\\d+)?" + ')' + "[a-z]*" , Pattern . CASE_INSENSITIVE ) , null , "0123456789" } ) ) ; fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_PLAIN , Pattern . compile ( "^\\\\[\\s\\S]?" ) , null } ) ) ; String punctuation = "^.[^\\s\\w.$@'\"`/\\\\]*" ; if ( Util . getVariableValueAsBoolean ( options . get ( "regexLiterals" ) ) ) { punctuation += "(?!\\s*/)" ; } fallthroughStylePatterns . add ( Arrays . asList ( new Object [ ] { PR_PUNCTUATION , Pattern . compile ( punctuation ) , null } ) ) ; return new CreateSimpleLexer ( shortcutStylePatterns , fallthroughStylePatterns ) ; }
returns a function that produces a list of decorations from source text . this code treats " , ' , and ` as string delimiters , and \ as a string escape . it does not recognize perl ' s qq ( ) style strings . it has no special handling for double delimiter escapes as in basic , or the tripled delimiters used in python , but should work on those regardless although in those cases a single string literal may be broken up into multiple adjacent string literals . it recognizes c , c + + , and shell style comments .
