-
Notifications
You must be signed in to change notification settings - Fork 0
/
LuaLexer.g4
123 lines (96 loc) · 2.83 KB
/
LuaLexer.g4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// $antlr-format alignTrailingComments true, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments false, useTab false
// $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine
// $antlr-format alignColons trailing, singleLineOverrulesHangingColon true, alignLexerCommands true, alignLabels true, alignTrailers true
lexer grammar LuaLexer;
options {
superClass = LuaLexerBase;
}
// Insert here @header for C++ lexer.
SEMI : ';';
EQ : '=';
BREAK : 'break';
GOTO : 'goto';
DO : 'do';
END : 'end';
WHILE : 'while';
REPEAT : 'repeat';
UNTIL : 'until';
IF : 'if';
THEN : 'then';
ELSEIF : 'elseif';
ELSE : 'else';
FOR : 'for';
COMMA : ',';
IN : 'in';
FUNCTION : 'function';
LOCAL : 'local';
LT : '<';
GT : '>';
RETURN : 'return';
CONTINUE : 'continue';
CC : '::';
NIL : 'nil';
FALSE : 'false';
TRUE : 'true';
DOT : '.';
SQUIG : '~';
MINUS : '-';
POUND : '#';
OP : '(';
CP : ')';
NOT : 'not';
LL : '<<';
GG : '>>';
AMP : '&';
SS : '//';
PER : '%';
COL : ':';
LE : '<=';
GE : '>=';
AND : 'and';
OR : 'or';
PLUS : '+';
STAR : '*';
OCU : '{';
CCU : '}';
OB : '[';
CB : ']';
EE : '==';
DD : '..';
PIPE : '|';
CARET : '^';
SLASH : '/';
DDD : '...';
SQEQ : '~=';
NAME: [a-zA-Z_][a-zA-Z_0-9]*;
NORMALSTRING: '"' ( EscapeSequence | ~('\\' | '"'))* '"';
CHARSTRING: '\'' ( EscapeSequence | ~('\'' | '\\'))* '\'';
LONGSTRING: '[' NESTED_STR ']';
fragment NESTED_STR: '=' NESTED_STR '=' | '[' .*? ']';
INT: Digit+;
HEX: '0' [xX] HexDigit+;
FLOAT: Digit+ '.' Digit* ExponentPart? | '.' Digit+ ExponentPart? | Digit+ ExponentPart;
HEX_FLOAT:
'0' [xX] HexDigit+ '.' HexDigit* HexExponentPart?
| '0' [xX] '.' HexDigit+ HexExponentPart?
| '0' [xX] HexDigit+ HexExponentPart
;
fragment ExponentPart: [eE] [+-]? Digit+;
fragment HexExponentPart: [pP] [+-]? Digit+;
fragment EscapeSequence:
'\\' [abfnrtvz"'|$#\\] // World of Warcraft Lua additionally escapes |$#
| '\\' '\r'? '\n'
| DecimalEscape
| HexEscape
| UtfEscape
;
fragment DecimalEscape: '\\' Digit | '\\' Digit Digit | '\\' [0-2] Digit Digit;
fragment HexEscape: '\\' 'x' HexDigit HexDigit;
fragment UtfEscape: '\\' 'u{' HexDigit+ '}';
fragment Digit: [0-9];
fragment HexDigit: [0-9a-fA-F];
fragment SingleLineInputCharacter: ~[\r\n\u0085\u2028\u2029];
COMMENT: '--' { this.HandleComment(); } -> channel(HIDDEN);
WS: [ \t\u000C\r]+ -> channel(HIDDEN);
NL: [\n] -> channel(2);
SHEBANG: '#' { this.IsLine1Col0() }? '!'? SingleLineInputCharacter* -> channel(HIDDEN);