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 |
| 7 | -- date: 14-05-11 |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * LEXER SECTION |
| 12 | */ |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame^] | 13 | LRB : '('; |
| 14 | RRB : ')'; |
| 15 | LT : '<'; |
| 16 | GT : '>'; |
| 17 | LEQ : '<='; |
| 18 | GEQ : '>='; |
| 19 | EQ : '='; |
| 20 | NE : '!='; |
| 21 | AND : '&' | 'AND' | 'and' | 'UND' | 'und' ; |
| 22 | OR : '|' | 'OR' | 'or' | 'ODER' | 'oder' ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 23 | |
| 24 | WS : ( ' ' | '\t' | '\r' | '\n' )+ -> skip ; |
| 25 | fragment FOCC : '{' WS* ( [0-9]* WS* ',' WS* [0-9]+ | [0-9]+ WS* ','? ) WS* '}'; |
| 26 | fragment NO_RE : ~[ \t\/]; |
| 27 | fragment ALPHABET : ~('\t' | ' ' | '/' | '*' | '?' | '+' | '{' | '}' | '[' | ']' |
| 28 | | '(' | ')' | '|' | '"' | ',' | ':' | '\'' | '\\' | '!' | '=' | '~' | '&' | '^' | '<' | '>' ); |
| 29 | NUMBER : [0-9]+; |
| 30 | |
| 31 | NL : [\r\n] -> skip; |
| 32 | ws : WS+; |
| 33 | |
| 34 | WORD : ALPHABET+; |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame^] | 35 | |
| 36 | /* |
| 37 | * Regular expressions (delimited by slashes in Annis) |
| 38 | */ |
| 39 | fragment RE_char : ~('*' | '?' | '+' | '{' | '}' | '[' | ']' | '/' |
| 40 | | '(' | ')' | '|' | '"' | ':' | '\'' | '\\'); |
| 41 | fragment RE_alter : ((RE_char | ('(' REGEX ')') | RE_chgroup) '|' REGEX )+; |
| 42 | fragment RE_chgroup : '[' RE_char+ ']'; |
| 43 | fragment RE_opt : (RE_char | RE_chgroup | ( '(' REGEX ')')) '?'; |
| 44 | fragment RE_star : (RE_char | RE_chgroup | ( '(' REGEX ')')) '*'; |
| 45 | fragment RE_plus : (RE_char | RE_chgroup | ( '(' REGEX ')')) '+'; |
| 46 | fragment RE_occ : (RE_char | RE_chgroup | ( '(' REGEX ')')) FOCC; |
| 47 | fragment RE_group : '(' REGEX ')'; |
| 48 | SLASH : '/'; |
| 49 | REGEX : SLASH ('.' | RE_char | RE_alter | RE_chgroup | RE_opt | RE_star | RE_plus | RE_occ | RE_group)* SLASH; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * PARSER SECTION |
| 53 | */ |
| 54 | |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame^] | 55 | regex |
| 56 | : REGEX |
| 57 | ; |
| 58 | |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 59 | conj |
| 60 | : AND | OR; |
| 61 | |
| 62 | operator |
| 63 | : EQ | NE | LT | GT | LEQ | GEQ; |
| 64 | |
| 65 | expr |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame^] | 66 | : (value operator)? field operator value |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 67 | ; |
| 68 | |
| 69 | field |
| 70 | : WORD; |
| 71 | |
| 72 | value |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame^] | 73 | : WORD | NUMBER | '"' (WORD ws*)+'"' |
| 74 | | regex; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 75 | |
| 76 | andGroup |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame^] | 77 | : (((LRB exprGroup RRB)|expr) AND)+ ((LRB exprGroup RRB)|expr) |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 78 | ; |
| 79 | |
| 80 | orGroup |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame^] | 81 | : (((LRB exprGroup RRB)|expr) OR)+ ((LRB exprGroup RRB)|expr) |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 82 | ; |
| 83 | |
| 84 | exprGroup |
| 85 | : andGroup |
| 86 | | orGroup |
| 87 | ; |
| 88 | |
| 89 | start |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame^] | 90 | : expr EOF |
| 91 | | exprGroup EOF |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 92 | ; |