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 |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 7 | -- date: 2014-05-11 |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * LEXER SECTION |
| 12 | */ |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 13 | /* |
| 14 | Regular expression |
| 15 | /x allows submatches like /^.*?RE.*?$/ |
| 16 | /X forces full matches |
| 17 | /i means case insensitivity |
| 18 | /I forces case sensitivity |
| 19 | */ |
| 20 | FLAG_xi : '/' ( ('x'|'X') ('i'|'I')? ); |
| 21 | FLAG_ix : '/' ( ('i'|'I') ('x'|'X')? ); |
| 22 | |
| 23 | |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 24 | LRB : '('; |
| 25 | RRB : ')'; |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 26 | LB : '['; |
| 27 | RB : ']'; |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 28 | LT : '<'; |
| 29 | GT : '>'; |
| 30 | LEQ : '<='; |
| 31 | GEQ : '>='; |
| 32 | EQ : '='; |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 33 | AND : '&' | 'AND' | 'and' | 'UND' | 'und' ; |
| 34 | OR : '|' | 'OR' | 'or' | 'ODER' | 'oder' ; |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 35 | NEG : '!'; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 36 | QMARK : '?'; |
| 37 | SLASH : '/'; |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 38 | COLON : ':'; |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 39 | DASH : '-'; |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 40 | TILDE : '~'; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 41 | WS : ( ' ' | '\t' | '\r' | '\n' )+ -> skip ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 42 | fragment NO_RE : ~[ \t\/]; |
| 43 | fragment ALPHABET : ~('\t' | ' ' | '/' | '*' | '?' | '+' | '{' | '}' | '[' | ']' |
| 44 | | '(' | ')' | '|' | '"' | ',' | ':' | '\'' | '\\' | '!' | '=' | '~' | '&' | '^' | '<' | '>' ); |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 45 | DIGIT : [0-9]; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 46 | NUMBER : [0-9]+; |
| 47 | |
| 48 | NL : [\r\n] -> skip; |
| 49 | ws : WS+; |
| 50 | |
| 51 | WORD : ALPHABET+; |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 52 | |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 53 | |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 54 | /* |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 55 | * Regular expressions |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 56 | */ |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 57 | 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] | 58 | fragment RE_char : ~('*' | '?' | '+' | '{' | '}' | '[' | ']' | '/' |
| 59 | | '(' | ')' | '|' | '"' | ':' | '\'' | '\\'); |
| 60 | fragment RE_alter : ((RE_char | ('(' REGEX ')') | RE_chgroup) '|' REGEX )+; |
| 61 | fragment RE_chgroup : '[' RE_char+ ']'; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 62 | fragment RE_quant : (RE_star | RE_plus | RE_occ) QMARK?; |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 63 | fragment RE_opt : (RE_char | RE_chgroup | ( '(' REGEX ')')) '?'; |
| 64 | fragment RE_star : (RE_char | RE_chgroup | ( '(' REGEX ')')) '*'; |
| 65 | fragment RE_plus : (RE_char | RE_chgroup | ( '(' REGEX ')')) '+'; |
| 66 | fragment RE_occ : (RE_char | RE_chgroup | ( '(' REGEX ')')) FOCC; |
| 67 | fragment RE_group : '(' REGEX ')'; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 68 | 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] | 69 | |
| 70 | /* |
| 71 | * PARSER SECTION |
| 72 | */ |
| 73 | |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 74 | regex |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 75 | : REGEX |
| 76 | ; |
| 77 | |
| 78 | date |
| 79 | : DIGIT DIGIT DIGIT DIGIT (DASH DIGIT DIGIT (DASH DIGIT DIGIT)?)? |
Joachim Bingel | 43607ed | 2014-05-19 12:39:55 +0000 | [diff] [blame] | 80 | ; |
| 81 | |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 82 | operator |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 83 | : (NEG? EQ) | LT | GT | LEQ | GEQ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 84 | |
| 85 | expr |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 86 | : meta |
| 87 | | token |
| 88 | ; |
| 89 | |
| 90 | meta |
| 91 | : (value operator)? field operator value |
| 92 | ; |
| 93 | |
| 94 | token |
| 95 | : LB (term|termGroup) RB |
| 96 | ; |
| 97 | |
| 98 | term |
| 99 | : NEG* (foundry SLASH)? layer termOp key (COLON value)? flag? |
| 100 | ; |
| 101 | |
| 102 | termOp |
| 103 | : (NEG? EQ? EQ | NEG? TILDE? TILDE) |
| 104 | ; |
| 105 | |
| 106 | termGroup |
| 107 | : (term | LRB termGroup RRB) booleanOp (term | LRB termGroup RRB | termGroup) |
| 108 | ; |
| 109 | |
| 110 | key |
| 111 | : WORD |
| 112 | | regex |
| 113 | | NUMBER |
| 114 | ; |
| 115 | |
| 116 | foundry |
| 117 | : WORD |
| 118 | ; |
| 119 | |
| 120 | layer |
| 121 | : WORD |
| 122 | ; |
| 123 | |
| 124 | booleanOp |
| 125 | : AND |
| 126 | | OR |
| 127 | ; |
| 128 | |
| 129 | flag |
| 130 | : FLAG_xi |
| 131 | | FLAG_ix |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 132 | ; |
| 133 | |
| 134 | field |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 135 | : WORD |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 136 | ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 137 | |
| 138 | value |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 139 | : WORD |
| 140 | | NUMBER |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 141 | | date |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 142 | | '"' (WORD ws*)+'"' |
| 143 | | regex |
| 144 | ; |
| 145 | |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 146 | relation |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 147 | : (expr|exprGroup) booleanOp (expr|exprGroup|relation) |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 148 | ; |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 149 | |
| 150 | exprGroup |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 151 | : LRB (expr | exprGroup | relation) RRB |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 152 | ; |
| 153 | |
| 154 | start |
Joachim Bingel | 787836a | 2014-08-07 14:50:18 +0000 | [diff] [blame] | 155 | : expr EOF |
| 156 | | exprGroup EOF |
| 157 | | relation EOF |
Joachim Bingel | dbbde77 | 2014-05-12 15:26:10 +0000 | [diff] [blame] | 158 | ; |