Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
costin committed Aug 17, 2024
1 parent 9b00883 commit 6ce1255
Show file tree
Hide file tree
Showing 17 changed files with 2,041 additions and 1,696 deletions.
39 changes: 32 additions & 7 deletions x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.g4
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
lexer grammar EsqlBaseLexer;

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

@header {
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
}

options {
superClass=LexerConfig;
caseInsensitive=true;
}

DISSECT : 'dissect' -> pushMode(EXPRESSION_MODE);
DROP : 'drop' -> pushMode(PROJECT_MODE);
ENRICH : 'enrich' -> pushMode(ENRICH_MODE);
EVAL : 'eval' -> pushMode(EXPRESSION_MODE);
EXPLAIN : 'explain' -> pushMode(EXPLAIN_MODE);
FROM : 'from' -> pushMode(FROM_MODE);
GROK : 'grok' -> pushMode(EXPRESSION_MODE);
INLINESTATS : 'inlinestats' -> pushMode(EXPRESSION_MODE);
KEEP : 'keep' -> pushMode(PROJECT_MODE);
LIMIT : 'limit' -> pushMode(EXPRESSION_MODE);
LOOKUP : 'lookup' -> pushMode(LOOKUP_MODE);
META : 'meta' -> pushMode(META_MODE);
METRICS : 'metrics' -> pushMode(METRICS_MODE);
MV_EXPAND : 'mv_expand' -> pushMode(MVEXPAND_MODE);
RENAME : 'rename' -> pushMode(RENAME_MODE);
ROW : 'row' -> pushMode(EXPRESSION_MODE);
SHOW : 'show' -> pushMode(SHOW_MODE);
SORT : 'sort' -> pushMode(EXPRESSION_MODE);
STATS : 'stats' -> pushMode(EXPRESSION_MODE);
WHERE : 'where' -> pushMode(EXPRESSION_MODE);
MATCH : 'match' -> pushMode(EXPRESSION_MODE);
UNKNOWN_CMD : ~[ \r\n\t[\]/]+ -> pushMode(EXPRESSION_MODE);
//
// in development
//
INLINESTATS : {devVersion()}? 'inlinestats' -> pushMode(EXPRESSION_MODE);
LOOKUP : {devVersion()}? 'lookup' -> pushMode(LOOKUP_MODE);
MATCH : {devVersion()}? 'match' -> pushMode(EXPRESSION_MODE);
METRICS : {devVersion()}? 'metrics' -> pushMode(METRICS_MODE);

UNKNOWN_CMD : ~[ \r\n\t[\]/]+ -> pushMode(EXPRESSION_MODE) ;

LINE_COMMENT
: '//' ~[\r\n]* '\r'? '\n'? -> channel(HIDDEN)
Expand Down Expand Up @@ -68,7 +93,7 @@ fragment DIGIT
;
fragment LETTER
: [A-Za-z]
: [a-z]
;
fragment ESCAPE_SEQUENCE
Expand All @@ -80,7 +105,7 @@ fragment UNESCAPED_CHARS
;
fragment EXPONENT
: [Ee] [+-]? DIGIT+
: [e] [+-]? DIGIT+
;
fragment ASPERAND
Expand Down
52 changes: 25 additions & 27 deletions x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.tokens

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 30 additions & 14 deletions x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@

parser grammar EsqlBaseParser;

options {tokenVocab=EsqlBaseLexer;}
@header {
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
}

options {
superClass=ParserConfig;
tokenVocab=EsqlBaseLexer;
}

singleStatement
: query EOF
Expand All @@ -22,28 +34,30 @@ query
sourceCommand
: explainCommand
| fromCommand
| metaCommand
| rowCommand
| metricsCommand
| showCommand
| metaCommand
// in development
| {devVersion()}? metricsCommand
;

processingCommand
: evalCommand
| inlinestatsCommand
| limitCommand
| lookupCommand
| whereCommand
| keepCommand
| sortCommand
| limitCommand
| statsCommand
| whereCommand
| sortCommand
| dropCommand
| renameCommand
| dissectCommand
| grokCommand
| enrichCommand
| mvExpandCommand
| matchCommand
// in development
| {devVersion()}? inlinestatsCommand
| {devVersion()}? lookupCommand
| {devVersion()}? matchCommand
;

whereCommand
Expand Down Expand Up @@ -154,11 +168,6 @@ statsCommand
: STATS stats=fields? (BY grouping=fields)?
;

inlinestatsCommand
: INLINESTATS stats=fields (BY grouping=fields)?
;


qualifiedName
: identifier (DOT identifier)*
;
Expand Down Expand Up @@ -295,10 +304,17 @@ enrichWithClause
: (newName=qualifiedNamePattern ASSIGN)? enrichField=qualifiedNamePattern
;

//
// In development
//
lookupCommand
: LOOKUP tableName=indexPattern ON matchFields=qualifiedNamePatterns
;

inlinestatsCommand
: INLINESTATS stats=fields (BY grouping=fields)?
;

matchCommand
: MATCH matchQuery
;
Expand Down
52 changes: 25 additions & 27 deletions x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.tokens

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Loading

0 comments on commit 6ce1255

Please sign in to comment.