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