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