blob: 226e0652ff4c72ac053a39aa9c4368fa69be587f [file] [log] [blame]
Joachim Bingeldbbde772014-05-12 15:26:10 +00001grammar CollectionQuery;
2
3@header {package de.ids_mannheim.korap.query.serialize.util;}
4
5/*
6 -- author: jbingel
7 -- date: 14-05-11
8*/
9
10/*
11 * LEXER SECTION
12 */
Joachim Bingel43607ed2014-05-19 12:39:55 +000013LRB : '(';
14RRB : ')';
15LT : '<';
16GT : '>';
17LEQ : '<=';
18GEQ : '>=';
19EQ : '=';
20NE : '!=';
21AND : '&' | 'AND' | 'and' | 'UND' | 'und' ;
22OR : '|' | 'OR' | 'or' | 'ODER' | 'oder' ;
Joachim Bingela3f51f72014-07-22 14:45:31 +000023QMARK : '?';
24SLASH : '/';
Joachim Bingel624854b2014-07-23 13:53:28 +000025DASH : '-';
Joachim Bingeldbbde772014-05-12 15:26:10 +000026WS : ( ' ' | '\t' | '\r' | '\n' )+ -> skip ;
Joachim Bingeldbbde772014-05-12 15:26:10 +000027fragment NO_RE : ~[ \t\/];
28fragment ALPHABET : ~('\t' | ' ' | '/' | '*' | '?' | '+' | '{' | '}' | '[' | ']'
29 | '(' | ')' | '|' | '"' | ',' | ':' | '\'' | '\\' | '!' | '=' | '~' | '&' | '^' | '<' | '>' );
Joachim Bingel624854b2014-07-23 13:53:28 +000030DIGIT : [0-9];
Joachim Bingeldbbde772014-05-12 15:26:10 +000031NUMBER : [0-9]+;
32
33NL : [\r\n] -> skip;
34ws : WS+;
35
36WORD : ALPHABET+;
Joachim Bingel43607ed2014-05-19 12:39:55 +000037
38/*
Joachim Bingela3f51f72014-07-22 14:45:31 +000039 * Regular expressions
Joachim Bingel43607ed2014-05-19 12:39:55 +000040 */
Joachim Bingela3f51f72014-07-22 14:45:31 +000041fragment FOCC : '{' WS* ( [0-9]* WS* ',' WS* [0-9]+ | [0-9]+ WS* ','? ) WS* '}';
Joachim Bingel43607ed2014-05-19 12:39:55 +000042fragment RE_char : ~('*' | '?' | '+' | '{' | '}' | '[' | ']' | '/'
43 | '(' | ')' | '|' | '"' | ':' | '\'' | '\\');
44fragment RE_alter : ((RE_char | ('(' REGEX ')') | RE_chgroup) '|' REGEX )+;
45fragment RE_chgroup : '[' RE_char+ ']';
Joachim Bingela3f51f72014-07-22 14:45:31 +000046fragment RE_quant : (RE_star | RE_plus | RE_occ) QMARK?;
Joachim Bingel43607ed2014-05-19 12:39:55 +000047fragment RE_opt : (RE_char | RE_chgroup | ( '(' REGEX ')')) '?';
48fragment RE_star : (RE_char | RE_chgroup | ( '(' REGEX ')')) '*';
49fragment RE_plus : (RE_char | RE_chgroup | ( '(' REGEX ')')) '+';
50fragment RE_occ : (RE_char | RE_chgroup | ( '(' REGEX ')')) FOCC;
51fragment RE_group : '(' REGEX ')';
Joachim Bingela3f51f72014-07-22 14:45:31 +000052REGEX : SLASH ('.' | RE_char | RE_alter | RE_chgroup | RE_opt | RE_quant | RE_group)* SLASH;
Joachim Bingeldbbde772014-05-12 15:26:10 +000053
54/*
55 * PARSER SECTION
56 */
57
Joachim Bingel43607ed2014-05-19 12:39:55 +000058regex
Joachim Bingel624854b2014-07-23 13:53:28 +000059: REGEX
60;
61
62date
63: DIGIT DIGIT DIGIT DIGIT (DASH DIGIT DIGIT (DASH DIGIT DIGIT)?)?
Joachim Bingel43607ed2014-05-19 12:39:55 +000064;
65
Joachim Bingeldbbde772014-05-12 15:26:10 +000066conj
67: AND | OR;
68
69operator
70: EQ | NE | LT | GT | LEQ | GEQ;
71
72expr
Joachim Bingel43607ed2014-05-19 12:39:55 +000073: (value operator)? field operator value
Joachim Bingel709a15e2014-07-23 13:46:34 +000074//| LRB expr RRB
Joachim Bingeldbbde772014-05-12 15:26:10 +000075;
76
77field
Joachim Bingel624854b2014-07-23 13:53:28 +000078: WORD
Joachim Bingela3f51f72014-07-22 14:45:31 +000079;
Joachim Bingeldbbde772014-05-12 15:26:10 +000080
81value
Joachim Bingela3f51f72014-07-22 14:45:31 +000082: WORD
83| NUMBER
Joachim Bingel624854b2014-07-23 13:53:28 +000084| date
Joachim Bingela3f51f72014-07-22 14:45:31 +000085| '"' (WORD ws*)+'"'
86| regex
87;
88
Joachim Bingela3f51f72014-07-22 14:45:31 +000089
Joachim Bingel624854b2014-07-23 13:53:28 +000090
Joachim Bingela3f51f72014-07-22 14:45:31 +000091relation
92: (expr|exprGroup) conj (expr|exprGroup|relation)
Joachim Bingel709a15e2014-07-23 13:46:34 +000093//| LRB relation RRB
Joachim Bingela3f51f72014-07-22 14:45:31 +000094;
Joachim Bingeldbbde772014-05-12 15:26:10 +000095
96exprGroup
Joachim Bingela3f51f72014-07-22 14:45:31 +000097: LRB (expr | exprGroup | relation) RRB
Joachim Bingeldbbde772014-05-12 15:26:10 +000098;
99
100start
Joachim Bingela3f51f72014-07-22 14:45:31 +0000101: ( expr
Joachim Bingel709a15e2014-07-23 13:46:34 +0000102 | exprGroup
103 | relation )
Joachim Bingeldbbde772014-05-12 15:26:10 +0000104;