| 110 | == Discussion == |
| 111 | Peter Beinema, MPI, proposes some minor changes to the grammar: |
| 112 | * main query [2] / simple query [3]: above definition generate structural ambiguity. Not a problem for ANTLR (which selects the right-recursive solution), but some other parser generators generate all solutions - which are exponential wrt the number of main queries. I propose to use the alternative rules given below. |
| 113 | * above rule [2] can generate infinite array of quantifiers: "word" +*{23}(,17}? would be legal. |
| 114 | * rule 5: option marker '?' makes "[]" a valid query. Propose to remove question mark. |
| 115 | * expression [11] / basic expression [12]: structural ambiguity. See proposed alternative below. |
| 116 | {{{ |
| 117 | // rules presented in antlr format |
| 118 | //--- [2v2] no left recursion or ambiguity, 1 (optional) quantifier |
| 119 | main_query : |
| 120 | simple_query |
| 121 | | simple_query '|' main_query // 'or' |
| 122 | | simple_query main_query // sequence |
| 123 | | simple_query quantifier // quantification |
| 124 | ; |
| 125 | |
| 126 | //--- [3v2] |
| 127 | simple_query : |
| 128 | '(' main_query ')' |
| 129 | | implicit_query |
| 130 | | segment_query |
| 131 | ; |
| 132 | |
| 133 | //--- [5v2] 'expression no longer optional |
| 134 | segment_query : |
| 135 | '[' expression ']' |
| 136 | ; |
| 137 | |
| 138 | //--- [11v2] |
| 139 | expression : |
| 140 | basic_expression |
| 141 | | basic_expression '|' expression // or |
| 142 | | basic_expression '&' expression // and |
| 143 | ; |
| 144 | |
| 145 | //--- [12v2] |
| 146 | basic_expression : |
| 147 | '(' expression ')' // grouping |
| 148 | | '!' expression // not |
| 149 | | attribute operator flagged_regexp |
| 150 | ; |
| 151 | |
| 152 | }}} |
| 153 | |