// Create a StringMatcher object populated with rules to help match // all ECMAScript tokens. private static StringMatcher CreateMatcher() { StringMatcher matcher = new StringMatcher(); string[] operators = new string[] { "{", "}", "(", ")", "[", "]", ".", ";", ",", "<", ">", ">=", "<=", "==", "!=", "===", "!==", "+", "-", "*", "%", "++", "--", "<<", ">>", ">>>", "&", "|", "^", "!", "~", "&&", "||", "?", ":", "=", "+=", "-=", "*=", "%=", "<<=", ">>=", ">>>=", "&=", "|=", "^=", "/", "/=" }; string[] keywords = new string[] { "break", "else", "new", "var", "case", "finally", "return", "void", "catch", "for", "switch", "while", "continue", "function", "this", "with", "default", "if", "throw", "delete", "in", "try", "do", "instanceof", "typeof", "null", "true", "false" }; string[] reserveds = new string[] { "abstract", "enum", "int", "short", "boolean", "export", "interface", "static", "byte", "extends", "long", "super", "char", "final", "native", "synchronized", "class", "float", "package", "throws", "const", "goto", "private", "transient", "debugger", "implements", "protected", "volatile", "double", "import", "public" }; int i; for (i=0; i<26; i++) { matcher.AddString(new String((char)('a' + i), 1), (int)TokDispatch.ident); matcher.AddString(new String((char)('A' + i), 1), (int)TokDispatch.ident); } matcher.AddString("_", (int)TokDispatch.ident); for (i=0; i<10; i++) { matcher.AddString(new String((char)('0' + i), 1), (int)TokDispatch.digit); } matcher.AddString("'", (int)TokDispatch.stringLit); matcher.AddString("\"", (int)TokDispatch.stringLit); matcher.AddString("/", (int)TokDispatch.stringLit); // HACK SN 7/14/01: distinguish between '/', '/=', and regexps for (i=0; i<operators.Length; i++) matcher.AddString(operators[i], (int)TokDispatch.op); for (i=0; i<keywords.Length; i++) matcher.AddString(keywords[i], (int)TokDispatch.keyword, true); for (i=0; i<reserveds.Length; i++) matcher.AddString(reserveds[i], (int)TokDispatch.reserved, true); matcher.AddString("/*", (int)TokDispatch.comment); matcher.AddString("//", (int)TokDispatch.comment); // HACK SN 7/12/01: verify that this is the complete set of whitespace chars matcher.AddString(" ", (int)TokDispatch.ws); matcher.AddString("\t", (int)TokDispatch.ws); matcher.AddString("\n", (int)TokDispatch.ws); matcher.AddString("\r", (int)TokDispatch.ws); return matcher; } // CreateMatcher
// Create a StringMatcher object populated with rules to help match // all ECMAScript tokens. private static StringMatcher CreateMatcher() { StringMatcher matcher = new StringMatcher(); string[] operators = new string[] { "{", "}", "(", ")", "[", "]", ".", ";", ",", "<", ">", ">=", "<=", "==", "!=", "===", "!==", "+", "-", "*", "%", "++", "--", "<<", ">>", ">>>", "&", "|", "^", "!", "~", "&&", "||", "?", ":", "=", "+=", "-=", "*=", "%=", "<<=", ">>=", ">>>=", "&=", "|=", "^=", "/", "/=" }; string[] keywords = new string[] { "break", "else", "new", "var", "case", "finally", "return", "void", "catch", "for", "switch", "while", "continue", "function", "this", "with", "default", "if", "throw", "delete", "in", "try", "do", "instanceof", "typeof", "null", "true", "false" }; string[] reserveds = new string[] { "abstract", "enum", "int", "short", "boolean", "export", "interface", "static", "byte", "extends", "long", "super", "char", "final", "native", "synchronized", "class", "float", "package", "throws", "const", "goto", "private", "transient", "debugger", "implements", "protected", "volatile", "double", "import", "public" }; int i; for (i = 0; i < 26; i++) { matcher.AddString(new String((char)('a' + i), 1), (int)TokDispatch.ident); matcher.AddString(new String((char)('A' + i), 1), (int)TokDispatch.ident); } matcher.AddString("_", (int)TokDispatch.ident); for (i = 0; i < 10; i++) { matcher.AddString(new String((char)('0' + i), 1), (int)TokDispatch.digit); } matcher.AddString("'", (int)TokDispatch.stringLit); matcher.AddString("\"", (int)TokDispatch.stringLit); matcher.AddString("/", (int)TokDispatch.stringLit); // HACK SN 7/14/01: distinguish between '/', '/=', and regexps for (i = 0; i < operators.Length; i++) { matcher.AddString(operators[i], (int)TokDispatch.op); } for (i = 0; i < keywords.Length; i++) { matcher.AddString(keywords[i], (int)TokDispatch.keyword, true); } for (i = 0; i < reserveds.Length; i++) { matcher.AddString(reserveds[i], (int)TokDispatch.reserved, true); } matcher.AddString("/*", (int)TokDispatch.comment); matcher.AddString("//", (int)TokDispatch.comment); // HACK SN 7/12/01: verify that this is the complete set of whitespace chars matcher.AddString(" ", (int)TokDispatch.ws); matcher.AddString("\t", (int)TokDispatch.ws); matcher.AddString("\n", (int)TokDispatch.ws); matcher.AddString("\r", (int)TokDispatch.ws); return(matcher); } // CreateMatcher