blob: 0bd7fe57a2f8c490656281c8088611d69c6f1533 [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 Bingeldbbde772014-05-12 15:26:10 +000023
24WS : ( ' ' | '\t' | '\r' | '\n' )+ -> skip ;
25fragment FOCC : '{' WS* ( [0-9]* WS* ',' WS* [0-9]+ | [0-9]+ WS* ','? ) WS* '}';
26fragment 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/*
37 * Regular expressions (delimited by slashes in Annis)
38 */
39fragment RE_char : ~('*' | '?' | '+' | '{' | '}' | '[' | ']' | '/'
40 | '(' | ')' | '|' | '"' | ':' | '\'' | '\\');
41fragment RE_alter : ((RE_char | ('(' REGEX ')') | RE_chgroup) '|' REGEX )+;
42fragment RE_chgroup : '[' RE_char+ ']';
43fragment RE_opt : (RE_char | RE_chgroup | ( '(' REGEX ')')) '?';
44fragment RE_star : (RE_char | RE_chgroup | ( '(' REGEX ')')) '*';
45fragment RE_plus : (RE_char | RE_chgroup | ( '(' REGEX ')')) '+';
46fragment RE_occ : (RE_char | RE_chgroup | ( '(' REGEX ')')) FOCC;
47fragment RE_group : '(' REGEX ')';
48SLASH : '/';
49REGEX : SLASH ('.' | RE_char | RE_alter | RE_chgroup | RE_opt | RE_star | RE_plus | RE_occ | RE_group)* SLASH;
Joachim Bingeldbbde772014-05-12 15:26:10 +000050
51/*
52 * PARSER SECTION
53 */
54
Joachim Bingel43607ed2014-05-19 12:39:55 +000055regex
56: REGEX
57;
58
Joachim Bingeldbbde772014-05-12 15:26:10 +000059conj
60: AND | OR;
61
62operator
63: EQ | NE | LT | GT | LEQ | GEQ;
64
65expr
Joachim Bingel43607ed2014-05-19 12:39:55 +000066: (value operator)? field operator value
Joachim Bingeldbbde772014-05-12 15:26:10 +000067;
68
69field
70: WORD;
71
72value
Joachim Bingel43607ed2014-05-19 12:39:55 +000073: WORD | NUMBER | '"' (WORD ws*)+'"'
74| regex;
Joachim Bingeldbbde772014-05-12 15:26:10 +000075
76andGroup
Joachim Bingel43607ed2014-05-19 12:39:55 +000077: (((LRB exprGroup RRB)|expr) AND)+ ((LRB exprGroup RRB)|expr)
Joachim Bingeldbbde772014-05-12 15:26:10 +000078;
79
80orGroup
Joachim Bingel43607ed2014-05-19 12:39:55 +000081: (((LRB exprGroup RRB)|expr) OR)+ ((LRB exprGroup RRB)|expr)
Joachim Bingeldbbde772014-05-12 15:26:10 +000082;
83
84exprGroup
85: andGroup
86| orGroup
87;
88
89start
Joachim Bingel3e0f0062014-05-19 14:00:25 +000090: expr
Joachim Bingel43607ed2014-05-19 12:39:55 +000091| exprGroup EOF
Joachim Bingeldbbde772014-05-12 15:26:10 +000092;