// identifier, verbatim identifier, or keyword private bool id_key(bool verbatimFlag) { bool errorFlag; while (nextchar()) { if (UnicodeHelp.isIdentifierPartCharacter(ce.Current)) { tmp.Append(ce.Current); continue; } if (ce.Current == '\\') { tmp.Append(ce.Current); if (!nextchar()) { return(malformed("identifier", tmp)); } tmp.Append(ce.Current); errorFlag = true; char ch = unicodeEscape(ref errorFlag); if (errorFlag) { return(malformed("identifier", tmp)); } verbatimFlag = true; continue; } break; } if (verbatimFlag) { return(ret("identifier", tmp)); } string str = System.String.Intern(tmp.ToString()); string t = keyword(str); if (t != null) { return(ret(t, t)); } return(ret("identifier", str)); }
public override bool MoveNext() { string str; if (buffered != null) { _current = buffered; buffered = null; return(true); } if (atEOI) { // if (yieldEOF) { // return success = false; // } // yieldEOF = true; return(ret("<EOF>")); } colno = ce.Location - startColumn + 1; fileOffset = ce.Location; tmp.Length = 0; switch (ce.Current) { case '#': return(preproc()); case '"': tmp.Append('"'); return(stringLiteral()); case '\'': tmp.Append('\''); return(characterLiteral()); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return(number()); case '\u0009': nextchar(); return(ret("WHITESPACE", "\u0009")); case '\u000b': nextchar(); return(ret("WHITESPACE", "\u000b")); case '\u000c': nextchar(); return(ret("WHITESPACE", "\u000c")); case '\u001a': nextchar(); return(ret("WHITESPACE", "\u001a")); case '\u000d': str = "\u000d"; if (nextchar()) { if (ce.Current == '\u000a') { str = "\u000d\u000a"; nextchar(); } } startColumn = ce.Location; lineno++; return(ret("NEWLINE", str)); case '\u000a': nextchar(); startColumn = ce.Location; lineno++; return(ret("NEWLINE", "\u000a")); case '\u2028': nextchar(); startColumn = ce.Location; lineno++; return(ret("NEWLINE", "\u2028")); case '\u2029': nextchar(); startColumn = ce.Location; lineno++; return(ret("NEWLINE", "\u2029")); case '/': if (!nextchar()) { return(ret("/")); } if (ce.Current == '=') { nextchar(); return(ret("/=")); } tmp.Append("/"); if (ce.Current == '/') // begin "//" comment { tmp.Append('/'); return(slashslashComment()); } if (ce.Current == '*') // begin "/*" comment { tmp.Append('*'); return(slashstarComment()); } return(ret("/")); case '.': if (!nextchar()) { return(ret(".")); } if (ce.Current < '0' || ce.Current > '9') { return(ret(".")); } tmp.Append("."); while (nextchar() && ce.Current >= '0' && ce.Current <= '9') { tmp.Append(ce.Current); } return(dotRealLiteral()); case '+': if (!nextchar()) { return(ret("+")); } switch (ce.Current) { case '+': nextchar(); return(ret("++")); case '=': nextchar(); return(ret("+=")); default: return(ret("+")); } case ';': nextchar(); return(ret(";")); case '[': nextchar(); return(ret("[")); case '{': nextchar(); return(ret("{")); case '(': nextchar(); return(ret("(")); case '%': if (!nextchar()) { return(ret("%")); } switch (ce.Current) { case '=': nextchar(); return(ret("%=")); default: return(ret("%")); } case '-': if (!nextchar()) { return(ret("-")); } switch (ce.Current) { case '-': nextchar(); return(ret("--")); case '=': nextchar(); return(ret("-=")); case '>': nextchar(); return(ret("->")); default: return(ret("-")); } case '=': if (!nextchar()) { return(ret("=")); } switch (ce.Current) { case '=': nextchar(); return(ret("==")); default: return(ret("=")); } case ']': nextchar(); return(ret("]")); case '}': nextchar(); return(ret("}")); case '*': if (!nextchar()) { return(ret("*")); } switch (ce.Current) { case '=': nextchar(); return(ret("*=")); default: return(ret("*")); } case ':': if (!nextchar()) { return(ret(":")); } switch (ce.Current) { case ':': nextchar(); return(ret("::")); default: return(ret(":")); } case '?': nextchar(); return(ret("?")); case ',': nextchar(); return(ret(",")); case '<': if (!nextchar()) { return(ret("<")); } switch (ce.Current) { case '=': nextchar(); return(ret("<=")); case '<': if (!nextchar()) { return(ret("<<")); } switch (ce.Current) { case '=': nextchar(); return(ret("<<=")); default: return(ret("<<")); } default: return(ret("<")); } case '|': if (!nextchar()) { return(ret("|")); } switch (ce.Current) { case '=': nextchar(); return(ret("|=")); case '|': nextchar(); return(ret("||")); default: return(ret("|")); } case '!': if (!nextchar()) { return(ret("!")); } switch (ce.Current) { case '=': nextchar(); return(ret("!=")); default: return(ret("!")); } case ')': nextchar(); return(ret(")")); case '&': if (!nextchar()) { return(ret("&")); } switch (ce.Current) { case '=': nextchar(); return(ret("&=")); case '&': nextchar(); return(ret("&&")); default: return(ret("&")); } case '>': if (!nextchar()) { return(ret(">")); } switch (ce.Current) { case '=': nextchar(); return(ret(">=")); default: return(ret(">")); } case '^': if (!nextchar()) { return(ret("^")); } switch (ce.Current) { case '=': nextchar(); return(ret("^=")); default: return(ret("^")); } case '~': nextchar(); return(ret("~")); } if (UnicodeHelp.isZs(ce.Current)) { string t = ce.Current.ToString(); t = System.String.Intern(t); nextchar(); return(ret("WHITESPACE", t)); } // identifier, keyword, verbatim identifier, or verbatim string if (ce.Current == '@') { tmp.Append('@'); if (!nextchar()) { return(ret("UNRECOGNIZED", "@")); } tmp.Append(ce.Current); if (ce.Current == '"') { return(verbatimString()); } return(id_key(true)); } if (UnicodeHelp.isLetterCharacter(ce.Current) || ce.Current == '_') { tmp.Append(ce.Current); return(id_key(false)); } str = ce.Current.ToString(); nextchar(); return(ret("UNRECOGNIZED", str)); }