|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | +lexer grammar Expression; |
| 8 | + |
| 9 | +// |
| 10 | +// Expression - used by many commands |
| 11 | +// |
| 12 | +COMPLETION : 'completion' -> pushMode(EXPRESSION_MODE); |
| 13 | +DISSECT : 'dissect' -> pushMode(EXPRESSION_MODE); |
| 14 | +EVAL : 'eval' -> pushMode(EXPRESSION_MODE); |
| 15 | +GROK : 'grok' -> pushMode(EXPRESSION_MODE); |
| 16 | +LIMIT : 'limit' -> pushMode(EXPRESSION_MODE); |
| 17 | +ROW : 'row' -> pushMode(EXPRESSION_MODE); |
| 18 | +SORT : 'sort' -> pushMode(EXPRESSION_MODE); |
| 19 | +STATS : 'stats' -> pushMode(EXPRESSION_MODE); |
| 20 | +WHERE : 'where' -> pushMode(EXPRESSION_MODE); |
| 21 | + |
| 22 | +DEV_INLINESTATS : {this.isDevVersion()}? 'inlinestats' -> pushMode(EXPRESSION_MODE); |
| 23 | +DEV_RERANK : {this.isDevVersion()}? 'rerank' -> pushMode(EXPRESSION_MODE); |
| 24 | +DEV_SAMPLE : {this.isDevVersion()}? 'sample' -> pushMode(EXPRESSION_MODE); |
| 25 | + |
| 26 | + |
| 27 | +mode EXPRESSION_MODE; |
| 28 | + |
| 29 | +PIPE : '|' -> popMode; |
| 30 | + |
| 31 | +fragment DIGIT |
| 32 | + : [0-9] |
| 33 | + ; |
| 34 | + |
| 35 | +fragment LETTER |
| 36 | + : [a-z] |
| 37 | + ; |
| 38 | + |
| 39 | +fragment ESCAPE_SEQUENCE |
| 40 | + : '\\' [tnr"\\] |
| 41 | + ; |
| 42 | +
|
| 43 | +fragment UNESCAPED_CHARS |
| 44 | + : ~[\r\n"\\] |
| 45 | + ; |
| 46 | + |
| 47 | +fragment EXPONENT |
| 48 | + : [e] [+-]? DIGIT+ |
| 49 | + ; |
| 50 | + |
| 51 | +fragment ASPERAND |
| 52 | + : '@' |
| 53 | + ; |
| 54 | + |
| 55 | +fragment BACKQUOTE |
| 56 | + : '`' |
| 57 | + ; |
| 58 | + |
| 59 | +fragment BACKQUOTE_BLOCK |
| 60 | + : ~'`' |
| 61 | + | '``' |
| 62 | + ; |
| 63 | + |
| 64 | +fragment UNDERSCORE |
| 65 | + : '_' |
| 66 | + ; |
| 67 | + |
| 68 | +fragment UNQUOTED_ID_BODY |
| 69 | + : (LETTER | DIGIT | UNDERSCORE) |
| 70 | + ; |
| 71 | + |
| 72 | +QUOTED_STRING |
| 73 | + : '"' (ESCAPE_SEQUENCE | UNESCAPED_CHARS)* '"' |
| 74 | + | '"""' (~[\r\n])*? '"""' '"'? '"'? |
| 75 | + ; |
| 76 | + |
| 77 | +INTEGER_LITERAL |
| 78 | + : DIGIT+ |
| 79 | + ; |
| 80 | + |
| 81 | +DECIMAL_LITERAL |
| 82 | + : DIGIT+ DOT DIGIT* |
| 83 | + | DOT DIGIT+ |
| 84 | + | DIGIT+ (DOT DIGIT*)? EXPONENT |
| 85 | + | DOT DIGIT+ EXPONENT |
| 86 | + ; |
| 87 | + |
| 88 | + |
| 89 | +AND : 'and'; |
| 90 | +AS: 'as'; |
| 91 | +ASC : 'asc'; |
| 92 | +ASSIGN : '='; |
| 93 | +BY : 'by'; |
| 94 | +CAST_OP : '::'; |
| 95 | +COLON : ':'; |
| 96 | +COMMA : ','; |
| 97 | +DESC : 'desc'; |
| 98 | +DOT : '.'; |
| 99 | +FALSE : 'false'; |
| 100 | +FIRST : 'first'; |
| 101 | +IN: 'in'; |
| 102 | +IS: 'is'; |
| 103 | +LAST : 'last'; |
| 104 | +LIKE: 'like'; |
| 105 | +NOT : 'not'; |
| 106 | +NULL : 'null'; |
| 107 | +NULLS : 'nulls'; |
| 108 | +ON: 'on'; |
| 109 | +OR : 'or'; |
| 110 | +PARAM: '?'; |
| 111 | +RLIKE: 'rlike'; |
| 112 | +TRUE : 'true'; |
| 113 | +WITH: 'with'; |
| 114 | + |
| 115 | +EQ : '=='; |
| 116 | +CIEQ : '=~'; |
| 117 | +NEQ : '!='; |
| 118 | +LT : '<'; |
| 119 | +LTE : '<='; |
| 120 | +GT : '>'; |
| 121 | +GTE : '>='; |
| 122 | + |
| 123 | +PLUS : '+'; |
| 124 | +MINUS : '-'; |
| 125 | +ASTERISK : '*'; |
| 126 | +SLASH : '/'; |
| 127 | +PERCENT : '%'; |
| 128 | + |
| 129 | +LEFT_BRACES : '{'; |
| 130 | +RIGHT_BRACES : '}'; |
| 131 | + |
| 132 | +DOUBLE_PARAMS: '??'; |
| 133 | + |
| 134 | +NESTED_WHERE : WHERE -> type(WHERE); |
| 135 | + |
| 136 | +NAMED_OR_POSITIONAL_PARAM |
| 137 | + : PARAM (LETTER | UNDERSCORE) UNQUOTED_ID_BODY* |
| 138 | + | PARAM DIGIT+ |
| 139 | + ; |
| 140 | + |
| 141 | +NAMED_OR_POSITIONAL_DOUBLE_PARAMS |
| 142 | + : DOUBLE_PARAMS (LETTER | UNDERSCORE) UNQUOTED_ID_BODY* |
| 143 | + | DOUBLE_PARAMS DIGIT+ |
| 144 | + ; |
| 145 | + |
| 146 | +// Brackets are funny. We can happen upon a CLOSING_BRACKET in two ways - one |
| 147 | +// way is to start in an explain command which then shifts us to expression |
| 148 | +// mode. Thus, the two popModes on CLOSING_BRACKET. The other way could as |
| 149 | +// the start of a multivalued field constant. To line up with the double pop |
| 150 | +// the explain mode needs, we double push when we see that. |
| 151 | +OPENING_BRACKET : '[' -> pushMode(EXPRESSION_MODE), pushMode(EXPRESSION_MODE); |
| 152 | +CLOSING_BRACKET : ']' -> popMode, popMode; |
| 153 | + |
| 154 | +LP : '(' -> pushMode(EXPRESSION_MODE), pushMode(EXPRESSION_MODE); |
| 155 | +RP : ')' -> popMode, popMode; |
| 156 | + |
| 157 | +UNQUOTED_IDENTIFIER |
| 158 | + : LETTER UNQUOTED_ID_BODY* |
| 159 | + // only allow @ at beginning of identifier to keep the option to allow @ as infix operator in the future |
| 160 | + // also, single `_` and `@` characters are not valid identifiers |
| 161 | + | (UNDERSCORE | ASPERAND) UNQUOTED_ID_BODY+ |
| 162 | + ; |
| 163 | + |
| 164 | +fragment QUOTED_ID |
| 165 | + : BACKQUOTE BACKQUOTE_BLOCK+ BACKQUOTE |
| 166 | + ; |
| 167 | + |
| 168 | +QUOTED_IDENTIFIER |
| 169 | + : QUOTED_ID |
| 170 | + ; |
| 171 | + |
| 172 | +EXPR_LINE_COMMENT |
| 173 | + : LINE_COMMENT -> channel(HIDDEN) |
| 174 | + ; |
| 175 | + |
| 176 | +EXPR_MULTILINE_COMMENT |
| 177 | + : MULTILINE_COMMENT -> channel(HIDDEN) |
| 178 | + ; |
| 179 | + |
| 180 | +EXPR_WS |
| 181 | + : WS -> channel(HIDDEN) |
| 182 | + ; |
0 commit comments