-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctx2lParser.g4
More file actions
41 lines (32 loc) · 1.03 KB
/
ctx2lParser.g4
File metadata and controls
41 lines (32 loc) · 1.03 KB
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
parser grammar ctx2lParser;
options {
tokenVocab = ctx2lLexer;
contextSuperClass = RuleContextWithAltNum;
}
@parser::header {
from RuleContextWithAltNum import RuleContextWithAltNum
}
import ANTLRv4Parser;
program: (ruleDef | tokenDef)+ EOF;
ruleDef: RULE_REF COLON OR? ruleAlts;
tokenDef: TOKEN_REF (DIRECT tokenCommands)? COLON OR? tokenAlts;
tokenCommands: lexerCommand (COMMA lexerCommand)*;
ruleSub: LPAREN OR? ruleAlts RPAREN;
tokenSub: LPAREN OR? tokenAlts RPAREN;
ruleAlts: ruleAlt (OR ruleAlt)*;
tokenAlts: tokenAlt (OR tokenAlt)*;
ruleAlt: ruleAtom+ (RARROW expr)?;
tokenAlt: tokenAtom+;
ruleAtom: label? ruleTerm ebnfSuffix?;
ruleTerm: ruleSub | ruleRef | ruleLiteral;
ruleRef: RULE_REF | TOKEN_REF;
ruleLiteral: STRING_LITERAL;
expr: DOLLAR? identifier call?;
call: LPAREN args? RPAREN;
args: expr (COMMA expr)* COMMA?;
tokenAtom: label? tokenTerm ebnfSuffix?;
tokenTerm: tokenSub | tokenRef | tokenLiteral;
tokenRef: TOKEN_REF;
tokenLiteral: STRING_LITERAL | LEXER_CHAR_SET;
label: identifier assign;
assign: ASSIGN | PLUS_ASSIGN;