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 | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 23 | QMARK : '?'; |
| 24 | SLASH : '/'; |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame^] | 25 | DASH : '-'; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 26 | WS : ( ' ' | '\t' | '\r' | '\n' )+ -> skip ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 27 | fragment NO_RE : ~[ \t\/]; |
| 28 | fragment ALPHABET : ~('\t' | ' ' | '/' | '*' | '?' | '+' | '{' | '}' | '[' | ']' |
| 29 | | '(' | ')' | '|' | '"' | ',' | ':' | '\'' | '\\' | '!' | '=' | '~' | '&' | '^' | '<' | '>' ); |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame^] | 30 | DIGIT : [0-9]; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 31 | NUMBER : [0-9]+; |
| 32 | |
| 33 | NL : [\r\n] -> skip; |
| 34 | ws : WS+; |
| 35 | |
| 36 | WORD : ALPHABET+; |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 37 | |
| 38 | /* |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 39 | * Regular expressions |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 40 | */ |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 41 | fragment FOCC : '{' WS* ( [0-9]* WS* ',' WS* [0-9]+ | [0-9]+ WS* ','? ) WS* '}'; |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 42 | fragment RE_char : ~('*' | '?' | '+' | '{' | '}' | '[' | ']' | '/' |
| 43 | | '(' | ')' | '|' | '"' | ':' | '\'' | '\\'); |
| 44 | fragment RE_alter : ((RE_char | ('(' REGEX ')') | RE_chgroup) '|' REGEX )+; |
| 45 | fragment RE_chgroup : '[' RE_char+ ']'; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 46 | fragment RE_quant : (RE_star | RE_plus | RE_occ) QMARK?; |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 47 | fragment RE_opt : (RE_char | RE_chgroup | ( '(' REGEX ')')) '?'; |
| 48 | fragment RE_star : (RE_char | RE_chgroup | ( '(' REGEX ')')) '*'; |
| 49 | fragment RE_plus : (RE_char | RE_chgroup | ( '(' REGEX ')')) '+'; |
| 50 | fragment RE_occ : (RE_char | RE_chgroup | ( '(' REGEX ')')) FOCC; |
| 51 | fragment RE_group : '(' REGEX ')'; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 52 | REGEX : SLASH ('.' | RE_char | RE_alter | RE_chgroup | RE_opt | RE_quant | RE_group)* SLASH; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * PARSER SECTION |
| 56 | */ |
| 57 | |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 58 | regex |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame^] | 59 | : REGEX |
| 60 | ; |
| 61 | |
| 62 | date |
| 63 | : DIGIT DIGIT DIGIT DIGIT (DASH DIGIT DIGIT (DASH DIGIT DIGIT)?)? |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 64 | ; |
| 65 | |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 66 | conj |
| 67 | : AND | OR; |
| 68 | |
| 69 | operator |
| 70 | : EQ | NE | LT | GT | LEQ | GEQ; |
| 71 | |
| 72 | expr |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 73 | : (value operator)? field operator value |
Joachim Bingel | 709a15e | 2014-07-23 13:46:34 +0000 | [diff] [blame] | 74 | //| LRB expr RRB |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 75 | ; |
| 76 | |
| 77 | field |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame^] | 78 | : WORD |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 79 | ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 80 | |
| 81 | value |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 82 | : WORD |
| 83 | | NUMBER |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame^] | 84 | | date |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 85 | | '"' (WORD ws*)+'"' |
| 86 | | regex |
| 87 | ; |
| 88 | |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 89 | |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame^] | 90 | |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 91 | relation |
| 92 | : (expr|exprGroup) conj (expr|exprGroup|relation) |
Joachim Bingel | 709a15e | 2014-07-23 13:46:34 +0000 | [diff] [blame] | 93 | //| LRB relation RRB |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 94 | ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 95 | |
| 96 | exprGroup |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 97 | : LRB (expr | exprGroup | relation) RRB |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 98 | ; |
| 99 | |
| 100 | start |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 101 | : ( expr |
Joachim Bingel | 709a15e | 2014-07-23 13:46:34 +0000 | [diff] [blame] | 102 | | exprGroup |
| 103 | | relation ) |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 104 | ; |