func newScanner() *switchScanner { var ( c = scan.Char merge = scan.Merge or = scan.Or con = scan.Con CHAR = c(`\x00-\x7F`) OCTET = c(`\x00-\xFF`) CR = c(`\r`) LF = c(`\n`) CRLF = con(CR, LF) SP = c(` `) HT = c(`\t`) LWS = con(CRLF.ZeroOrOne(), or(SP, HT).OneOrMore()) CTL = c(`\x00-\x1F\x7F`) //TEXT = or(OCTET.Exclude(CTL), LWS) separators = merge(c(`\(\)<>@,;:\\"/\[\]\?=\{\}`), SP, HT) token = CHAR.Exclude(CTL, separators).OneOrMore() quotedPair = con(c(`\\`), CHAR) ctext = or(OCTET.Exclude(CTL, c(`()`), c(`;`)), LWS) leftParen = c(`(`) rightParen = c(`)`) productToken = token productSep = c(`/`) commentSep = or(c(`;`), LWS).OneOrMore() commentText = or(ctext, quotedPair).OneOrMore() m = scan.NewMatcher( productToken, productSep, LWS, leftParen, ) mc = scan.NewMapMatcher(scan.MM{ {leftParen, tLeftParen}, {rightParen, tRightParen}, {commentSep, tCommentSep}, {commentText, tCommentText}, }) scanner = &switchScanner{scan.Scanner{Matcher: m}, m, mc, 0} ) return scanner }
matcher = scan.NewMapMatcher(scan.MM{ {newline, tNewline}, {whitespaces, tWhitespace}, {s(`if`), int(token.IF)}, {s(`break`), int(token.BREAK)}, {s(`case`), int(token.CASE)}, {s(`chan`), int(token.CHAN)}, {s(`const`), int(token.CONST)}, {s(`continue`), int(token.CONTINUE)}, {s(`default`), int(token.DEFAULT)}, {s(`defer`), int(token.DEFER)}, {s(`else`), int(token.ELSE)}, {s(`fallthrough`), int(token.FALLTHROUGH)}, {s(`for`), int(token.FOR)}, {s(`func`), int(token.FUNC)}, {s(`goto`), int(token.GOTO)}, {s(`go`), int(token.GO)}, {s(`import`), int(token.IMPORT)}, {s(`interface`), int(token.INTERFACE)}, {s(`map`), int(token.MAP)}, {s(`package`), int(token.PACKAGE)}, {s(`range`), int(token.RANGE)}, {s(`return`), int(token.RETURN)}, {s(`select`), int(token.SELECT)}, {s(`struct`), int(token.STRUCT)}, {s(`switch`), int(token.SWITCH)}, {s(`type`), int(token.TYPE)}, {s(`var`), int(token.VAR)}, {identifier, int(token.IDENT)}, {lineComment, tLineComment}, {generalCommentSL, tGeneralCommentSL}, {generalCommentML, tGeneralCommentML}, {runeLit, int(token.CHAR)}, {imaginaryLit, int(token.IMAG)}, {floatLit, int(token.FLOAT)}, {intLit, int(token.INT)}, {rawStringLit, tRawStringLit}, {interpretedStringLit, tInterpretedStringLit}, {s(`...`), int(token.ELLIPSIS)}, {s(`.`), int(token.PERIOD)}, {s(`(`), int(token.LPAREN)}, {s(`)`), int(token.RPAREN)}, {s(`{`), int(token.LBRACE)}, {s(`}`), int(token.RBRACE)}, {s(`,`), int(token.COMMA)}, {s(`==`), int(token.EQL)}, {s(`=`), int(token.ASSIGN)}, {s(`:=`), int(token.DEFINE)}, {s(`:`), int(token.COLON)}, {s(`+=`), int(token.ADD_ASSIGN)}, {s(`++`), int(token.INC)}, {s(`+`), int(token.ADD)}, {s(`-=`), int(token.SUB_ASSIGN)}, {s(`--`), int(token.DEC)}, {s(`-`), int(token.SUB)}, {s(`*=`), int(token.MUL_ASSIGN)}, {s(`*`), int(token.MUL)}, {s(`/=`), int(token.QUO_ASSIGN)}, {s(`/`), int(token.QUO)}, {s(`%=`), int(token.REM_ASSIGN)}, {s(`%`), int(token.REM)}, {s(`|=`), int(token.OR_ASSIGN)}, {s(`||`), int(token.LOR)}, {s(`|`), int(token.OR)}, {s(`^=`), int(token.XOR_ASSIGN)}, {s(`^`), int(token.XOR)}, {s(`<<=`), int(token.SHL_ASSIGN)}, {s(`<<`), int(token.SHL)}, {s(`>>=`), int(token.SHR_ASSIGN)}, {s(`>>`), int(token.SHR)}, {s(`&^=`), int(token.AND_NOT_ASSIGN)}, {s(`&^`), int(token.AND_NOT)}, {s(`&=`), int(token.AND_ASSIGN)}, {s(`&&`), int(token.LAND)}, {s(`&`), int(token.AND)}, {s(`!=`), int(token.NEQ)}, {s(`!`), int(token.NOT)}, {s(`<=`), int(token.LEQ)}, {s(`<-`), int(token.ARROW)}, {s(`<`), int(token.LSS)}, {s(`>=`), int(token.GEQ)}, {s(`>`), int(token.GTR)}, {s(`[`), int(token.LBRACK)}, {s(`]`), int(token.RBRACK)}, {s(`;`), int(token.SEMICOLON)}, {scan.Pat(`.`), int(token.ILLEGAL)}, })