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