aboutsummaryrefslogtreecommitdiff
path: root/antlr-3.4/runtime/Python/tests/t021hoist.g
blob: 8caa3abf86640b52ab42c1f297816b8e4bd6b073 (plain)
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
grammar t021hoist;
options {
    language=Python;
}

/* With this true, enum is seen as a keyword.  False, it's an identifier */
@parser::init {
self.enableEnum = False
}

stat returns [enumIs]
    : identifier    {enumIs = "ID"}
    | enumAsKeyword {enumIs = "keyword"}
    ;

identifier
    : ID
    | enumAsID
    ;

enumAsKeyword : {self.enableEnum}? 'enum' ;

enumAsID : {not self.enableEnum}? 'enum' ;

ID  :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
    ;

INT :	('0'..'9')+
    ;

WS  :   (   ' '
        |   '\t'
        |   '\r'
        |   '\n'
        )+
        {$channel=HIDDEN}
    ;