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