blob: 2c6b29bfb6da7c570f76ade3fe67f7a92478f2bc [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 Bingel709a15e2014-07-23 13:46:34 +000068//| LRB expr RRB
Joachim Bingeldbbde772014-05-12 15:26:10 +000069;
70
71field
Joachim Bingela3f51f72014-07-22 14:45:31 +000072: WORD
73;
Joachim Bingeldbbde772014-05-12 15:26:10 +000074
75value
Joachim Bingela3f51f72014-07-22 14:45:31 +000076: WORD
77| NUMBER
78| '"' (WORD ws*)+'"'
79| regex
80;
81
Joachim Bingela3f51f72014-07-22 14:45:31 +000082
83relation
84: (expr|exprGroup) conj (expr|exprGroup|relation)
Joachim Bingel709a15e2014-07-23 13:46:34 +000085//| LRB relation RRB
Joachim Bingela3f51f72014-07-22 14:45:31 +000086;
Joachim Bingeldbbde772014-05-12 15:26:10 +000087
88exprGroup
Joachim Bingela3f51f72014-07-22 14:45:31 +000089: LRB (expr | exprGroup | relation) RRB
Joachim Bingeldbbde772014-05-12 15:26:10 +000090;
91
92start
Joachim Bingela3f51f72014-07-22 14:45:31 +000093: ( expr
Joachim Bingel709a15e2014-07-23 13:46:34 +000094 | exprGroup
95 | relation )
Joachim Bingeldbbde772014-05-12 15:26:10 +000096;