Skip to content

Commit

Permalink
Support uppercase commands and functions
Browse files Browse the repository at this point in the history
stratoula committed Apr 25, 2023
1 parent 2ddbd2d commit 456b4b0
Showing 7 changed files with 652 additions and 553 deletions.
82 changes: 56 additions & 26 deletions packages/kbn-monaco/src/esql/antlr/esql_lexer.g4
Original file line number Diff line number Diff line change
@@ -7,19 +7,21 @@

lexer grammar esql_lexer;

DISSECT : 'dissect' -> pushMode(EXPRESSION);
GROK : 'grok' -> pushMode(EXPRESSION);
EVAL : 'eval' -> pushMode(EXPRESSION);
EXPLAIN : 'explain' -> pushMode(EXPRESSION);
FROM : 'from' -> pushMode(SOURCE_IDENTIFIERS);
ROW : 'row' -> pushMode(EXPRESSION);
STATS : 'stats' -> pushMode(EXPRESSION);
WHERE : 'where' -> pushMode(EXPRESSION);
SORT : 'sort' -> pushMode(EXPRESSION);
LIMIT : 'limit' -> pushMode(EXPRESSION);
PROJECT : 'project' -> pushMode(EXPRESSION);
DROP : 'drop' -> pushMode(EXPRESSION);
RENAME : 'rename' -> pushMode(EXPRESSION);
options { caseInsensitive = true; }

DISSECT : D I S S E C T -> pushMode(EXPRESSION);
GROK : G R O K -> pushMode(EXPRESSION);
EVAL : E V A L -> pushMode(EXPRESSION);
EXPLAIN : E X P L A I N -> pushMode(EXPRESSION);
FROM : F R O M -> pushMode(SOURCE_IDENTIFIERS);
ROW : R O W -> pushMode(EXPRESSION);
STATS : S T A T S -> pushMode(EXPRESSION);
WHERE : W H E R E -> pushMode(EXPRESSION);
SORT : S O R T -> pushMode(EXPRESSION);
LIMIT : L I M I T -> pushMode(EXPRESSION);
PROJECT : P R O J E C T -> pushMode(EXPRESSION);
DROP : D R O P -> pushMode(EXPRESSION);
RENAME : R E N A M E -> pushMode(EXPRESSION);

LINE_COMMENT
: '//' ~[\r\n]* '\r'? '\n'? -> channel(HIDDEN)
@@ -97,6 +99,7 @@ RLIKE: 'rlike';
NULL : 'null';
OR : 'or';
RP : ')';
UNDERSCORE: '_';

BOOLEAN_VALUE
: 'true'
@@ -130,22 +133,22 @@ NULLS_ORDERING_DIRECTION
;

MATH_FUNCTION
: 'round'
| 'abs'
| 'substring'
| 'concat'
| 'starts_with'
| 'date_format'
| 'date_trunc'
: R O U N D
| A B S
| S U B S T R I N G
| C O N C A T
| S T A R T S UNDERSCORE W I T H
| D A T E UNDERSCORE F O R M A T
| D A T E UNDERSCORE T R U N C
;

UNARY_FUNCTION
: 'avg'
| 'min'
| 'max'
| 'sum'
| 'count'
| 'count_distinct'
: A V G
| M I N
| M A X
| S U M
| C O U N T
| C O U N T UNDERSCORE D I S T I N C T
;

WHERE_FUNCTIONS
@@ -205,3 +208,30 @@ SRC_MULTILINE_COMMENT
SRC_WS
: WS -> channel(HIDDEN)
;

fragment A : [aA]; // match either an 'a' or 'A'
fragment B : [bB];
fragment C : [cC];
fragment D : [dD];
fragment E : [eE];
fragment F : [fF];
fragment G : [gG];
fragment H : [hH];
fragment I : [iI];
fragment J : [jJ];
fragment K : [kK];
fragment L : [lL];
fragment M : [mM];
fragment N : [nN];
fragment O : [oO];
fragment P : [pP];
fragment Q : [qQ];
fragment R : [rR];
fragment S : [sS];
fragment T : [tT];
fragment U : [uU];
fragment V : [vV];
fragment W : [wW];
fragment X : [xX];
fragment Y : [yY];
fragment Z : [zZ];
57 changes: 43 additions & 14 deletions packages/kbn-monaco/src/esql/antlr/esql_lexer.interp

Large diffs are not rendered by default.

73 changes: 31 additions & 42 deletions packages/kbn-monaco/src/esql/antlr/esql_lexer.tokens
Original file line number Diff line number Diff line change
@@ -33,42 +33,30 @@ RLIKE=32
NULL=33
OR=34
RP=35
BOOLEAN_VALUE=36
COMPARISON_OPERATOR=37
PLUS=38
MINUS=39
ASTERISK=40
SLASH=41
PERCENT=42
ORDERING=43
NULLS_ORDERING=44
NULLS_ORDERING_DIRECTION=45
MATH_FUNCTION=46
UNARY_FUNCTION=47
WHERE_FUNCTIONS=48
UNQUOTED_IDENTIFIER=49
QUOTED_IDENTIFIER=50
EXPR_LINE_COMMENT=51
EXPR_MULTILINE_COMMENT=52
EXPR_WS=53
SRC_UNQUOTED_IDENTIFIER=54
SRC_QUOTED_IDENTIFIER=55
SRC_LINE_COMMENT=56
SRC_MULTILINE_COMMENT=57
SRC_WS=58
'dissect'=1
'grok'=2
'eval'=3
'explain'=4
'from'=5
'row'=6
'stats'=7
'where'=8
'sort'=9
'limit'=10
'project'=11
'drop'=12
'rename'=13
UNDERSCORE=36
BOOLEAN_VALUE=37
COMPARISON_OPERATOR=38
PLUS=39
MINUS=40
ASTERISK=41
SLASH=42
PERCENT=43
ORDERING=44
NULLS_ORDERING=45
NULLS_ORDERING_DIRECTION=46
MATH_FUNCTION=47
UNARY_FUNCTION=48
WHERE_FUNCTIONS=49
UNQUOTED_IDENTIFIER=50
QUOTED_IDENTIFIER=51
EXPR_LINE_COMMENT=52
EXPR_MULTILINE_COMMENT=53
EXPR_WS=54
SRC_UNQUOTED_IDENTIFIER=55
SRC_QUOTED_IDENTIFIER=56
SRC_LINE_COMMENT=57
SRC_MULTILINE_COMMENT=58
SRC_WS=59
'by'=21
'and'=23
'.'=26
@@ -81,9 +69,10 @@ SRC_WS=58
'null'=33
'or'=34
')'=35
'+'=38
'-'=39
'*'=40
'/'=41
'%'=42
'nulls'=44
'_'=36
'+'=39
'-'=40
'*'=41
'/'=42
'%'=43
'nulls'=45
Loading

0 comments on commit 456b4b0

Please sign in to comment.