blob: 7aad659b72617cf1dcebe428e599c6d890a70a29 [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 Bingeldbbde772014-05-12 15:26:10 +000025WS : ( ' ' | '\t' | '\r' | '\n' )+ -> skip ;
Joachim Bingeldbbde772014-05-12 15:26:10 +000026fragment NO_RE : ~[ \t\/];
27fragment ALPHABET : ~('\t' | ' ' | '/' | '*' | '?' | '+' | '{' | '}' | '[' | ']'
28 | '(' | ')' | '|' | '"' | ',' | ':' | '\'' | '\\' | '!' | '=' | '~' | '&' | '^' | '<' | '>' );
29NUMBER : [0-9]+;
30
31NL : [\r\n] -> skip;
32ws : WS+;
33
34WORD : ALPHABET+;
Joachim Bingel43607ed2014-05-19 12:39:55 +000035
36/*
Joachim Bingela3f51f72014-07-22 14:45:31 +000037 * Regular expressions
Joachim Bingel43607ed2014-05-19 12:39:55 +000038 */
Joachim Bingela3f51f72014-07-22 14:45:31 +000039fragment FOCC : '{' WS* ( [0-9]* WS* ',' WS* [0-9]+ | [0-9]+ WS* ','? ) WS* '}';
Joachim Bingel43607ed2014-05-19 12:39:55 +000040fragment RE_char : ~('*' | '?' | '+' | '{' | '}' | '[' | ']' | '/'
41 | '(' | ')' | '|' | '"' | ':' | '\'' | '\\');
42fragment RE_alter : ((RE_char | ('(' REGEX ')') | RE_chgroup) '|' REGEX )+;
43fragment RE_chgroup : '[' RE_char+ ']';
Joachim Bingela3f51f72014-07-22 14:45:31 +000044fragment RE_quant : (RE_star | RE_plus | RE_occ) QMARK?;
Joachim Bingel43607ed2014-05-19 12:39:55 +000045fragment RE_opt : (RE_char | RE_chgroup | ( '(' REGEX ')')) '?';
46fragment RE_star : (RE_char | RE_chgroup | ( '(' REGEX ')')) '*';
47fragment RE_plus : (RE_char | RE_chgroup | ( '(' REGEX ')')) '+';
48fragment RE_occ : (RE_char | RE_chgroup | ( '(' REGEX ')')) FOCC;
49fragment RE_group : '(' REGEX ')';
Joachim Bingela3f51f72014-07-22 14:45:31 +000050REGEX : SLASH ('.' | RE_char | RE_alter | RE_chgroup | RE_opt | RE_quant | RE_group)* SLASH;
Joachim Bingeldbbde772014-05-12 15:26:10 +000051
52/*
53 * PARSER SECTION
54 */
55
Joachim Bingel43607ed2014-05-19 12:39:55 +000056regex
57: REGEX
58;
59
Joachim Bingeldbbde772014-05-12 15:26:10 +000060conj
61: AND | OR;
62
63operator
64: EQ | NE | LT | GT | LEQ | GEQ;
65
66expr
Joachim Bingel43607ed2014-05-19 12:39:55 +000067: (value operator)? field operator value
Joachim Bingeldbbde772014-05-12 15:26:10 +000068;
69
70field
Joachim Bingela3f51f72014-07-22 14:45:31 +000071: WORD
72;
Joachim Bingeldbbde772014-05-12 15:26:10 +000073
74value
Joachim Bingela3f51f72014-07-22 14:45:31 +000075: WORD
76| NUMBER
77| '"' (WORD ws*)+'"'
78| regex
79;
80
81/*
Joachim Bingeldbbde772014-05-12 15:26:10 +000082andGroup
Joachim Bingel43607ed2014-05-19 12:39:55 +000083: (((LRB exprGroup RRB)|expr) AND)+ ((LRB exprGroup RRB)|expr)
Joachim Bingeldbbde772014-05-12 15:26:10 +000084;
85
86orGroup
Joachim Bingel43607ed2014-05-19 12:39:55 +000087: (((LRB exprGroup RRB)|expr) OR)+ ((LRB exprGroup RRB)|expr)
Joachim Bingeldbbde772014-05-12 15:26:10 +000088;
Joachim Bingela3f51f72014-07-22 14:45:31 +000089*/
90
91relation
92: (expr|exprGroup) conj (expr|exprGroup|relation)
93;
Joachim Bingeldbbde772014-05-12 15:26:10 +000094
95exprGroup
Joachim Bingela3f51f72014-07-22 14:45:31 +000096: LRB (expr | exprGroup | relation) RRB
Joachim Bingeldbbde772014-05-12 15:26:10 +000097;
98
99start
Joachim Bingela3f51f72014-07-22 14:45:31 +0000100: ( expr
101 | exprGroup EOF
102 | relation EOF )
Joachim Bingeldbbde772014-05-12 15:26:10 +0000103;