forked from antlr/antlr4
/
PositionAdjustingLexer.g4
56 lines (44 loc) · 1.08 KB
/
PositionAdjustingLexer.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
lexer grammar PositionAdjustingLexer;
@members {
public boolean testAssertion(int assertionMode, int passingRule) {
int index = _input.index();
int mark = _input.mark();
try {
LexerATNSimulator interp = new LexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
interp.copyState(_interp);
int result = interp.match(_input, assertionMode);
return result == passingRule;
} finally {
_input.seek(index);
_input.release(mark);
}
}
}
ASSIGN : '=' ;
PLUS_ASSIGN : '+=' ;
LCURLY: '{';
// 'tokens' followed by '{'
TOKENS : 'tokens' {testAssertion(MODE_TOKENS_ASSERTION_1, TOKENS_ASSERTION_1_PASS)}?;
// IDENTIFIER followed by '+=' or '='
LABEL
: IDENTIFIER {testAssertion(MODE_LABEL_ASSERTION_1, LABEL_ASSERTION_1_PASS)}?
;
IDENTIFIER
: [a-zA-Z_] [a-zA-Z0-9_]*
;
fragment
IGNORED
: [ \t\r\n]*
;
NEWLINE
: [\r\n]+ -> skip
;
WS
: [ \t]+ -> skip
;
mode MODE_TOKENS_ASSERTION_1;
TOKENS_ASSERTION_1_PASS : IGNORED '{';
TOKENS_ASSERTION_1_FAIL : .;
mode MODE_LABEL_ASSERTION_1;
LABEL_ASSERTION_1_PASS : IGNORED '+'? '=';
LABEL_ASSERTION_1_FAIL : .;