1
2
3
4
5
6 #include <sngcm/cmlexer/CmajorLexerApi.hpp>
7
8 classmap ParserFileTokenLexerClassMap;
9
10 prefix "sngcm/cmlexer";
11
12 tokens ParserFileTokenLexerTokens
13 {
14 (PARSER, "'parser'"), (MAIN, "'main'"), (USELEXER, "'uselexer'"), (RULEINFO, "'ruleinfo'"), (EMPTY, "'empty'"), (ANY, "'any'"), (VAR, "'var'"), (PRODUCES, "'::='"),
15 (ASSERT, "'assert'"), (ELIF, "'elif'"), (ENDIF, "'endif'"), (BOOL, "'bool'"), (TRUE, "'true'"), (FALSE, "'false'"),
16 (SBYTE, "'sbyte'"), (BYTE, "'byte'"), (SHORT, "'short'"), (USHORT, "'ushort'"), (INT, "'int'"),
17 (UINT, "'uint'"), (LONG, "'long'"), (ULONG, "'ulong'"), (FLOAT, "'float'"), (DOUBLE, "'double'"), (CHAR, "'char'"), (WCHAR, "'wchar'"), (UCHAR, "'uchar'"), (VOID, "'void'"),
18 (ENUM, "'enum'"), (CAST, "'cast'"), (INTERFACE, "'interface'"), (NAMESPACE, "'namespace'"), (USING, "'using'"),
19 (STATIC, "'static'"), (EXTERN, "'extern'"), (AS, "'as'"), (IS, "'is'"), (EXPLICIT, "'explicit'"), (DELEGATE, "'delegate'"), (INLINE, "'inline'"), (CDECL, "'cdecl'"), (NOTHROW, "'nothrow'"),
20 (PUBLIC, "'public'"), (PROTECTED, "'protected'"), (PRIVATE, "'private'"), (INTERNAL, "'internal'"), (VIRTUAL, "'virtual'"), (ABSTRACT, "'abstract'"), (OVERRIDE, "'override'"),
21 (SUPPRESS, "'suppress'"), (OPERATOR, "'operator'"), (CLASS, "'class'"), (RETURN, "'return'"),
22 (IF, "'if'"), (ELSE, "'else'"), (SWITCH, "'switch'"), (CASE, "'case'"), (DEFAULT, "'default'"),
23 (WHILE, "'while'"), (DO, "'do'"), (FOR, "'for'"), (BREAK, "'break'"), (CONTINUE, "'continue'"), (GOTO, "'goto'"), (TYPEDEF, "'typedef'"), (TYPENAME, "'typename'"), (TYPEID, "'typeid'"),
24 (CONST, "'const'"), (CONSTEXPR, "'constexpr'"), (NULLLIT, "'null'"), (THIS, "'this'"), (BASE, "'base'"), (CONSTRUCT, "'construct'"), (DESTROY, "'destroy'"),
25 (NEW, "'new'"), (DELETE, "'delete'"), (SIZEOF, "'sizeof'"), (TRY, "'try'"), (CATCH, "'catch'"), (THROW, "'throw'"),
26 (CONCEPT, "'concept'"), (WHERE, "'where'"), (AXIOM, "'axiom'"), (AND, "'and'"), (OR, "'or'"), (EXCLAMATION, "'!'"), (UNIT_TEST, "'unit_test'"),
27 (FLOATINGLIT, "floating literal"), (INTLIT, "integer literal"), (CHARLIT, "character literal"), (STRINGLIT, "string literal"),
28 (EQUIVALENCE, "'<=>'"), (IMPLICATION, "'=>'"), (DISJUNCTION, "'||'"), (AMPAMP, "'&&'"),
29 (BITOR, "'|'"), (BITXOR, "'^'"), (AMP, "'&'"), (EQ, "'=='"), (NEQ, "'!='"), (LEQ, "'<='"), (GEQ, "'>='"), (SHIFTLEFT, "'<<'"), (SHIFTRIGHT, "'>>'"),
30 (PLUS, "'+'"), (MINUS, "'-'"), (STAR, "'*'"), (DIV, "'/'"), (REM, "'%'"), (PLUSPLUS, "'++'"), (MINUSMINUS, "'--'"), (CPL, "'~'"), (DOT, "'.'"), (ARROW, "'->'"),
31 (LBRACKET, "'['"), (RBRACKET, "']'"), (LPAREN, "'('"), (RPAREN, "')'"), (LANGLE, "'<'"), (RANGLE, "'>'"), (LBRACE, "'{'"), (RBRACE, "'}'"), (COMMA, "','"), (ASSIGN, "'='"),
32 (COLON, "':'"), (SEMICOLON, "';'"), (HASH, "'#'"),
33 (WS, "white space"), (LINECOMMENT, "line comment"), (BLOCKCOMMENT, "block comment"), (BLOCKCOMMENTLINE, "block comment line"),
34 (KEYWORD, "keyword"), (ID, "identifier"), (NUMBER, "number"), (OTHER, "other"),
35 (MAX, "max")
36 }
37
38 keywords ParserFileTokenLexerKeywords
39 {
40 ("parser", PARSER), ("main", MAIN), ("uselexer", USELEXER), ("ruleinfo", RULEINFO), ("empty", EMPTY), ("any", ANY), ("var", VAR),
41 ("assert", ASSERT), ("elif", ELIF), ("endif", ENDIF), ("bool", BOOL), ("true", TRUE), ("false", FALSE),
42 ("sbyte", SBYTE), ("byte", BYTE), ("short", SHORT), ("ushort", USHORT), ("int", INT), ("uint", UINT), ("long", LONG), ("ulong", ULONG),
43 ("float", FLOAT), ("double", DOUBLE), ("char", CHAR), ("wchar", WCHAR), ("uchar", UCHAR), ("void", VOID), ("enum", ENUM), ("cast", CAST), ("interface", INTERFACE),
44 ("namespace", NAMESPACE), ("using", USING), ("static", STATIC), ("extern", EXTERN), ("as", AS), ("is", IS), ("explicit", EXPLICIT), ("delegate", DELEGATE), ("inline", INLINE), ("cdecl", CDECL), ("nothrow", NOTHROW),
45 ("public", PUBLIC), ("protected", PROTECTED), ("private", PRIVATE), ("internal", INTERNAL), ("virtual", VIRTUAL), ("abstract", ABSTRACT), ("override", OVERRIDE), ("suppress", SUPPRESS),
46 ("operator", OPERATOR), ("class", CLASS), ("return", RETURN), ("if", IF), ("else", ELSE),
47 ("switch", SWITCH), ("case", CASE), ("default", DEFAULT), ("while", WHILE), ("do", DO), ("for", FOR),
48 ("break", BREAK), ("continue", CONTINUE), ("goto", GOTO), ("typedef", TYPEDEF), ("typename", TYPENAME), ("typeid", TYPEID), ("const", CONST), ("constexpr", CONSTEXPR), ("null", NULLLIT), ("this", THIS), ("base", BASE),
49 ("construct", CONSTRUCT), ("destroy", DESTROY), ("new", NEW), ("delete", DELETE), ("sizeof", SIZEOF), ("try", TRY), ("catch", CATCH), ("throw", THROW),
50 ("concept", CONCEPT), ("where", WHERE), ("axiom", AXIOM), ("and", AND), ("or", OR), ("unit_test", UNIT_TEST)
51 }
52
53 expressions
54 {
55 ws = "[\t ]+";
56 newline = "\r\n|\n|\r";
57 linecomment = "//[^\n\r]*{newline}";
58 blockcomment = "/\*([^*\n\r]|\*[^/\n\r])*(\*/|{newline})";
59 blockcommentline = "([^*\n\r]|\*[^/\n\r])*(\*/|{newline})";
60 comment = "{linecomment}|{blockcomment}";
61 separators = "({ws}|{comment})+";
62 id = "{idstart}{idcont}*";
63 decdigits = "[0-9]+";
64 hexdigit = "[0-9a-fA-F]";
65 hexdigits = "{hexdigit}+";
66 hex4 = "{hexdigit}{hexdigit}{hexdigit}{hexdigit}";
67 hex8 = "{hex4}{hex4}";
68 octaldigits = "[0-7]+";
69 fraction = "{decdigits}?\.{decdigits}|{decdigits}\.";
70 sign = "\+|-";
71 exponent = "(e|E){sign}?{decdigits}";
72 integer = "(0{octaldigits}?|[1-9]{decdigits}?|0(x|X){hexdigits})(u|U)?";
73 floating = "({fraction}{exponent}?|{decdigits}{exponent})(f|F)?";
74 escape = "\\((x|X){hexdigits}|(d|D){decdigits}|{octaldigits}|u{hex4}|U{hex8}|(a|b|f|n|r|t|v|.))";
75 character = "(w|u)?'([^\\\r\n']+|{escape})'";
76 string = "((w|u)?@\"[^\"]*\")|(w|u)?\"([^\\\r\n\"]|{escape})*\"";
77 }
78
79 lexer api(SNGCM_LEXER_API) ParserFileTokenLexer
80 {
81 "{ws}" { return WS; }
82 "{newline}" { }
83 "{linecomment}" { return LINECOMMENT; }
84 "{blockcomment}" { return BLOCKCOMMENT; }
85 "{blockcommentline}" $(1) { return BLOCKCOMMENTLINE; }
86 "{id}" { if (GetKeywordToken(token.match) != INVALID_TOKEN) return KEYWORD; else return ID; }
87 "{character}" { return CHARLIT; }
88 "{string}" { return STRINGLIT; }
89 "{floating}" { return NUMBER; }
90 "{integer}" { return NUMBER; }
91 "<=>" { return OTHER; }
92 "=>" { return OTHER; }
93 "\|\|" { return OTHER; }
94 "&&" { return OTHER; }
95 "\|" { return OTHER; }
96 "^" { return OTHER; }
97 "&" { return OTHER; }
98 "==" { return OTHER; }
99 "!=" { return OTHER; }
100 "<=" { return OTHER; }
101 ">=" { return OTHER; }
102 "<" { return OTHER; }
103 ">" { return OTHER; }
104 "<<" { return OTHER; }
105 ">>" { return OTHER; }
106 "\+" { return OTHER; }
107 "-" { return OTHER; }
108 "\*" { return OTHER; }
109 "/" { return OTHER; }
110 "%" { return OTHER; }
111 "\+\+" { return OTHER; }
112 "--" { return OTHER; }
113 "!" { return OTHER; }
114 "~" { return OTHER; }
115 "\." { return OTHER; }
116 "->" { return OTHER; }
117 "\[" { return OTHER; }
118 "\]" { return OTHER; }
119 "\(" { return OTHER; }
120 "\)" { return OTHER; }
121 "\{" { return OTHER; }
122 "\}" { return OTHER; }
123 "," { return OTHER; }
124 "=" { return OTHER; }
125 ":" { return OTHER; }
126 ";" { return OTHER; }
127 "#" { return OTHER; }
128 "::=" { return OTHER; }
129 "\?" { return OTHER; }
130
131 actions
132 {
133 $(1)={ if (!inBlockComment) return INVALID_TOKEN; }
134 }
135
136 variables
137 {
138 bool inBlockComment;
139 }
140 }