1 #include <sngcpp/pp/PP.hpp>
2
3 classmap TextClassMap;
4
5 prefix "sngcpp/pp";
6
7 tokens TextTokens
8 {
9 (DEFINED, "'defined'"), (ANGLEHEADERNAME, "angleheadername"), (QUOTEHEADERNAME, "quoteheadername"), (PPNUMBER, "preprocessing number"), (CHARLITERAL, "character literal"),
10 (STRINGLITERAL, "string literal"), (CHAR, "character"),
11 (ID, "identifier"), (COLONCOLON, "'::'"), (COMMA, "','"), (ASSIGN, "'='"), (MULASSIGN, "'*='"), (DIVASSIGN, "'/='"), (REMASSIGN, "'%='"), (ADDASSIGN, "'+='"), (SUBASSIGN, "'-='"),
12 (SHIFTRIGHTASSIGN, "'>>='"), (SHIFTLEFTASSIGN, "'<<='"), (ANDASSIGN, "'&='"), (XORASSIGN, "'^='"), (ORASSIGN, "'|='"), (QUEST, "'?'"), (COLON, "':'"),
13 (OROR, "'||'"), (AMPAMP, "'&&'"), (OR, "'|'"), (XOR, "'^'"), (AMP, "'&'"), (EQ, "'=='"), (NEQ, "'!='"), (LEQ, "'<='"), (GEQ, "'>='"), (SPACESHIP, "<=>"), (LANGLE, "'<'"), (RANGLE, "'>'"),
14 (SHIFTLEFT, "'<<'"), (SHIFTRIGHT, "'>>'"), (PLUS, "'+'"), (MINUS, "'-'"), (STAR, "'*'"), (DIV, "'/'"), (MOD, "'%'"), (DOTSTAR, "'.*'"), (ARROWSTAR, "'->*'"), (LPAREN, "'('"), (RPAREN, "')'"),
15 (PLUSPLUS, "'++'"), (MINUSMINUS, "'--'"), (EXCLAMATION, "'!'"), (TILDE, "'~'"),
16 (LBRACKET, "'['"), (RBRACKET, "']'"), (LBRACE, "'{'"), (RBRACE, "'}'"), (DOT, "'.'"), (ARROW, "'->'"), (SEMICOLON, "';'"), (ELLIPSES, "'...'"),
17 (KEYWORD, "keyword"), (WS, "white space"), (BLOCKCOMMENT, "block comment"), (LINECOMMENT, "line comment"),
18 (MAX, "max")
19 }
20
21 expressions
22 {
23 ws = "[\t ]+";
24 newline = "\r\n|\n|\r";
25 linecontinuation = "\\{newline}";
26 linecomment = "//[^\n\r]*{newline}";
27 blockcomment = "/\*([^*]|\*[^/])*\*/";
28 id = "{idstart}{idcont}*";
29 digit = "[0-9]";
30 nondigit = "[a-zA-Z_]";
31 hexdigit = "[0-9a-fA-F]";
32 hexquad = "{hexdigit}{hexdigit}{hexdigit}{hexdigit}";
33 universalcharactername = "\\u{hexquad}|\\U{hexquad}{hexquad}";
34 identifiernondigit = "{nondigit}|{universalcharactername}";
35 sign = "\+|-";
36 ppnumber = "({digit}+\.?|\.{digit}+)([eE]{sign}|{identifiernondigit})*";
37 octaldigit = "[0-7]";
38 simpleescape = "\\['\"\?\\abfnrtv]";
39 octalescape = "\\{octaldigit}|\\{octaldigit}{octaldigit}|\\{octaldigit}{octaldigit}{octaldigit}";
40 hexescape = "\\x{hexdigit}+";
41 escape = "{simpleescape}|{octalescape}|{hexescape}";
42 cchar = "[^\r\n\\']|{escape}|{universalcharactername}";
43 characterliteral = "[uUL]?'{cchar}+'";
44 encodingprefix = "u8|u|U|L";
45 schar = "[^\r\n\\\"]|{escape}|{universalcharactername}";
46 stringliteral = "{encodingprefix}?\"{schar}*\"|{encodingprefix}?R\"[^\n\r\"]*\"";
47 }
48
49 lexer api(SNGCPP_PP_API) TextLexer
50 {
51 "{ws}" { return WS; }
52 "{linecontinuation}" {}
53 "{blockcomment}" { pp->Emit(U" ", token.match, BLOCKCOMMENT); }
54 "{linecomment}" { pp->Emit(U" ", token.match, LINECOMMENT); }
55 "{newline}" {}
56 "{id}" { if (pp->IsKeywordToken(token)) return KEYWORD; else return ID; }
57 "{ppnumber}" { return PPNUMBER; }
58 "{characterliteral}" { return CHARLITERAL; }
59 "{stringliteral}" { return STRINGLITERAL; }
60 "::" { return COLONCOLON; }
61 "," { return COMMA; }
62 "=" { return ASSIGN; }
63 "\*=" { return MULASSIGN; }
64 "/=" { return DIVASSIGN; }
65 "%=" { return REMASSIGN; }
66 "\+=" { return ADDASSIGN; }
67 "-=" { return SUBASSIGN; }
68 ">>=" { return SHIFTRIGHTASSIGN; }
69 "<<=" { return SHIFTLEFTASSIGN; }
70 "&=" { return ANDASSIGN; }
71 "^=" { return XORASSIGN; }
72 "\|=" { return ORASSIGN; }
73 "\?" { return QUEST; }
74 ":" { return COLON; }
75 "\|\|" { return OROR; }
76 "&&" { return AMPAMP; }
77 "\|" { return OR; }
78 "^" { return XOR; }
79 "&" { return AMP; }
80 "==" { return EQ; }
81 "!=" { return NEQ; }
82 "<=" { return LEQ; }
83 ">=" { return GEQ; }
84 "<=>" { return SPACESHIP; }
85 "<" { return LANGLE; }
86 ">" { return RANGLE; }
87 "<<" { return SHIFTLEFT; }
88 ">>" { return SHIFTRIGHT; }
89 "\+" { return PLUS; }
90 "-" { return MINUS; }
91 "\*" { return STAR; }
92 "/" { return DIV; }
93 "%" { return MOD; }
94 "\.\*" { return DOTSTAR; }
95 "->\*" { return ARROWSTAR; }
96 "\(" { return LPAREN; }
97 "\)" { return RPAREN; }
98 "\+\+" { return PLUSPLUS; }
99 "--" { return MINUSMINUS; }
100 "!" { return EXCLAMATION; }
101 "~" { return TILDE; }
102 "\[" { return LBRACKET; }
103 "\]" { return RBRACKET; }
104 "\." { return DOT; }
105 "->" { return ARROW; }
106 ";" { return SEMICOLON; }
107 "\.\.\." { return ELLIPSES; }
108 "\{" { return LBRACE; }
109 "\}" { return RBRACE; }
110
111 variables
112 {
113 sngcpp::pp::PP* pp;
114 }
115 }