source: FCS-QL/trunk/src/main/antlr4/eu/clarin/sru/fcs/qlparser/FCSParser.g4 @ 6865

Last change on this file since 6865 was 6865, checked in by Leif-Jöran, 9 years ago

Simplified AST

File size: 2.4 KB
Line 
1parser grammar FCSParser;
2options { tokenVocab=FCSLexer; }
3/*
4 * Parser for FCS Core FCS-QL version 2.0
5 * 20150501- /ljo
6 */
7query
8    : main_query (WITHIN within_part)? EOF
9    ;
10
11/* for debugging */
12parse
13  :  (t=.   
14          {System.out.printf("text: %-7s  type: %s \n", 
15           $t.text, tokenNames[$t.type]);} 
16     )*
17  ;
18
19
20main_query
21    : query_simple /* #simpleQuery */
22    | query_group /* #queryGroup */
23    | query_sequence /* #querySequence */
24    | query_disjunction /* #queryDisjunction */
25    ;
26
27
28query_disjunction
29    : (query_simple | query_sequence | query_group)
30            (OR (query_simple | query_sequence | query_group))+
31    ;
32
33
34query_sequence
35    : (query_simple | query_group)+
36    ;
37
38
39query_group
40    : L_PAREN (query_disjunction | query_sequence) R_PAREN quantifier?
41    ;
42
43
44query_simple
45    : (query_implicit | query_segment) quantifier?
46    ;
47
48
49quantifier
50    : (Q_ONE_OR_MORE | Q_ZERO_OR_MORE | Q_ZERO_OR_ONE |
51        ( L_CURLY_BRACKET
52            (INTEGER |
53             INTEGER? Q_COMMA INTEGER |
54             INTEGER Q_COMMA INTEGER?) R_CURLY_BRACKET))
55    ;
56
57
58query_implicit
59    : flagged_regexp
60    ;
61
62
63query_segment
64    : L_SQUARE_BRACKET expression? R_SQUARE_BRACKET     /* [ expression? ] */
65    ;
66
67
68within_part
69    : simple_within_part
70    ;
71
72
73simple_within_part
74    : SIMPLE_WITHIN_SCOPE
75    ;
76
77
78expression
79    : expression_basic
80    | expression_not
81    | expression_group
82    | expression_or
83    | expression_and
84    ;
85
86
87expression_or
88    : (expression_basic | expression_group | expression_not | expression_and)
89        (OR (expression_basic | expression_group | expression_not | expression_and))+
90    ;   
91
92
93expression_and
94    : (expression_basic | expression_group | expression_not)
95        (AND (expression_basic | expression_group | expression_not))+
96    ;   
97
98
99
100expression_group
101    : L_PAREN (expression_basic | expression_not | expression_or | expression_and) R_PAREN
102    ;
103
104
105expression_not
106    : NOT (expression_basic | expression_not | expression_or | expression_and)
107    ;
108
109
110expression_basic
111    : attribute (OPERATOR_EQ | OPERATOR_NE) flagged_regexp
112    ;
113
114attribute
115    : (qualifier COLON)? identifier
116    ;
117
118qualifier
119    : (IDENTIFIER | WITHIN | SIMPLE_WITHIN_SCOPE | REGEXP_FLAGS)
120    ;
121
122identifier
123    : (IDENTIFIER | WITHIN | SIMPLE_WITHIN_SCOPE | REGEXP_FLAGS)
124    ;
125
126flagged_regexp
127    : REGEXP (FWD_SLASH REGEXP_FLAGS)?
128    ;
Note: See TracBrowser for help on using the repository browser.