Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 1 | grammar CollectionQuery; |
2 | |||||
3 | @header {package de.ids_mannheim.korap.query.serialize.util;} | ||||
4 | |||||
5 | /* | ||||
6 | -- author: jbingel | ||||
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 7 | -- date: 2014-05-11 |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 8 | */ |
9 | |||||
10 | /* | ||||
11 | * LEXER SECTION | ||||
12 | */ | ||||
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 13 | /* |
14 | Regular expression | ||||
15 | /x allows submatches like /^.*?RE.*?$/ | ||||
16 | /X forces full matches | ||||
17 | /i means case insensitivity | ||||
18 | /I forces case sensitivity | ||||
19 | */ | ||||
20 | FLAG_xi : '/' ( ('x'|'X') ('i'|'I')? ); | ||||
21 | FLAG_ix : '/' ( ('i'|'I') ('x'|'X')? ); | ||||
22 | |||||
23 | |||||
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 24 | LRB : '('; |
25 | RRB : ')'; | ||||
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 26 | LB : '['; |
27 | RB : ']'; | ||||
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 28 | LT : '<'; |
29 | GT : '>'; | ||||
30 | LEQ : '<='; | ||||
31 | GEQ : '>='; | ||||
32 | EQ : '='; | ||||
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 33 | AND : '&' | 'AND' | 'and' | 'UND' | 'und' ; |
34 | OR : '|' | 'OR' | 'or' | 'ODER' | 'oder' ; | ||||
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 35 | NEG : '!'; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 36 | QMARK : '?'; |
37 | SLASH : '/'; | ||||
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 38 | COLON : ':'; |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 39 | DASH : '-'; |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 40 | TILDE : '~'; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 41 | WS : ( ' ' | '\t' | '\r' | '\n' )+ -> skip ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 42 | fragment NO_RE : ~[ \t\/]; |
43 | fragment ALPHABET : ~('\t' | ' ' | '/' | '*' | '?' | '+' | '{' | '}' | '[' | ']' | ||||
44 | | '(' | ')' | '|' | '"' | ',' | ':' | '\'' | '\\' | '!' | '=' | '~' | '&' | '^' | '<' | '>' ); | ||||
Joachim Bingel | 4bf1ec5 | 2014-10-08 08:18:03 +0000 | [diff] [blame^] | 45 | fragment ALPHA : [a-zA-Z]; |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 46 | DIGIT : [0-9]; |
Joachim Bingel | 4bf1ec5 | 2014-10-08 08:18:03 +0000 | [diff] [blame^] | 47 | |
48 | DATE | ||||
49 | : DIGIT DIGIT DIGIT DIGIT (DASH DIGIT DIGIT (DASH DIGIT DIGIT)?)? | ||||
50 | ; | ||||
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 51 | |
52 | NL : [\r\n] -> skip; | ||||
53 | ws : WS+; | ||||
54 | |||||
Joachim Bingel | 4bf1ec5 | 2014-10-08 08:18:03 +0000 | [diff] [blame^] | 55 | WORD : ALPHABET* ALPHA ALPHABET*; // needs to have at least one alphabetical letter |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 56 | |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 57 | /* |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 58 | * Regular expressions |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 59 | */ |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 60 | fragment FOCC : '{' WS* ( [0-9]* WS* ',' WS* [0-9]+ | [0-9]+ WS* ','? ) WS* '}'; |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 61 | fragment RE_char : ~('*' | '?' | '+' | '{' | '}' | '[' | ']' | '/' |
62 | | '(' | ')' | '|' | '"' | ':' | '\'' | '\\'); | ||||
63 | fragment RE_alter : ((RE_char | ('(' REGEX ')') | RE_chgroup) '|' REGEX )+; | ||||
64 | fragment RE_chgroup : '[' RE_char+ ']'; | ||||
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 65 | fragment RE_quant : (RE_star | RE_plus | RE_occ) QMARK?; |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 66 | fragment RE_opt : (RE_char | RE_chgroup | ( '(' REGEX ')')) '?'; |
67 | fragment RE_star : (RE_char | RE_chgroup | ( '(' REGEX ')')) '*'; | ||||
68 | fragment RE_plus : (RE_char | RE_chgroup | ( '(' REGEX ')')) '+'; | ||||
69 | fragment RE_occ : (RE_char | RE_chgroup | ( '(' REGEX ')')) FOCC; | ||||
70 | fragment RE_group : '(' REGEX ')'; | ||||
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 71 | REGEX : SLASH ('.' | RE_char | RE_alter | RE_chgroup | RE_opt | RE_quant | RE_group)* SLASH; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 72 | |
73 | /* | ||||
74 | * PARSER SECTION | ||||
75 | */ | ||||
76 | |||||
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 77 | regex |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 78 | : REGEX |
79 | ; | ||||
80 | |||||
81 | date | ||||
Joachim Bingel | 4bf1ec5 | 2014-10-08 08:18:03 +0000 | [diff] [blame^] | 82 | : DATE |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 83 | ; |
84 | |||||
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 85 | operator |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 86 | : (NEG? EQ) | LT | GT | LEQ | GEQ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 87 | |
88 | expr | ||||
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 89 | : meta |
90 | | token | ||||
91 | ; | ||||
92 | |||||
93 | meta | ||||
94 | : (value operator)? field operator value | ||||
95 | ; | ||||
96 | |||||
97 | token | ||||
98 | : LB (term|termGroup) RB | ||||
99 | ; | ||||
100 | |||||
101 | term | ||||
102 | : NEG* (foundry SLASH)? layer termOp key (COLON value)? flag? | ||||
103 | ; | ||||
104 | |||||
105 | termOp | ||||
106 | : (NEG? EQ? EQ | NEG? TILDE? TILDE) | ||||
107 | ; | ||||
108 | |||||
109 | termGroup | ||||
110 | : (term | LRB termGroup RRB) booleanOp (term | LRB termGroup RRB | termGroup) | ||||
111 | ; | ||||
112 | |||||
113 | key | ||||
114 | : WORD | ||||
115 | | regex | ||||
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 116 | ; |
117 | |||||
118 | foundry | ||||
119 | : WORD | ||||
120 | ; | ||||
121 | |||||
122 | layer | ||||
123 | : WORD | ||||
124 | ; | ||||
125 | |||||
126 | booleanOp | ||||
127 | : AND | ||||
128 | | OR | ||||
129 | ; | ||||
130 | |||||
131 | flag | ||||
132 | : FLAG_xi | ||||
133 | | FLAG_ix | ||||
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 134 | ; |
135 | |||||
136 | field | ||||
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 137 | : WORD |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 138 | ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 139 | |
140 | value | ||||
Joachim Bingel | 4bf1ec5 | 2014-10-08 08:18:03 +0000 | [diff] [blame^] | 141 | : WORD |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 142 | | '"' (WORD ws*)+'"' |
Joachim Bingel | 4bf1ec5 | 2014-10-08 08:18:03 +0000 | [diff] [blame^] | 143 | | date |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 144 | | regex |
145 | ; | ||||
146 | |||||
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 147 | relation |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 148 | : (expr|exprGroup) booleanOp (expr|exprGroup|relation) |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 149 | ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 150 | |
151 | exprGroup | ||||
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 152 | : LRB (expr | exprGroup | relation) RRB |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 153 | ; |
154 | |||||
155 | start | ||||
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 156 | : expr EOF |
157 | | exprGroup EOF | ||||
158 | | relation EOF | ||||
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 159 | ; |