feat(flinksql): add some lexer

This commit is contained in:
Erindcl
2020-10-23 17:52:43 +08:00
parent b7df08f012
commit 6082c2b151
11 changed files with 2281 additions and 1690 deletions

View File

@ -299,10 +299,37 @@ ROW: 'ROW';
NULL: 'NULL';
// single character Keywords
// Operators. Comparation
EQUAL: '=';
COMMA: ',';
EQUAL_SYMBOL: '=';
GREATER_SYMBOL: '>';
LESS_SYMBOL: '<';
EXCLAMATION_SYMBOL: '!';
// Operators. Bit
BIT_NOT_OP: '~';
BIT_OR_OP: '|';
BIT_AND_OP: '&';
BIT_XOR_OP: '^';
// Constructors symbols
DOT: '.';
LR_BRACKET: '(';
RR_BRACKET: ')';
COMMA: ',';
SEMICOLON: ';';
AT_SIGN: '@';
ZERO_DECIMAL: '0';
ONE_DECIMAL: '1';
TWO_DECIMAL: '2';
SINGLE_QUOTE_SYMB: '\'';
DOUBLE_QUOTE_SYMB: '"';
REVERSE_QUOTE_SYMB: '`';
COLON_SYMB: ':';
fragment ID_LITERAL: [A-Z_0-9a-z]*?[A-Z_a-z]+?[A-Z_0-9a-z]*;

View File

@ -5,13 +5,21 @@ options { tokenVocab=FlinkSqlLexer; }
program: statement EOF;
statement
: sqlStatement EOF
: sqlStatements EOF
;
sqlStatements
: (sqlStatement SEMICOLON | emptyStatement)*
;
sqlStatement
: ddlStatement | dmlStatement
;
emptyStatement
: SEMICOLON
;
ddlStatement
: createTable | createDatabase | createView | createFunction
| alterTable | alterDatabase | alterFunction
@ -24,13 +32,13 @@ dmlStatement
createTable
: CREATE TABLE tableName
(
columnOptionDefinition (',' columnOptionDefinition)*
)
LR_BRACKET
columnOptionDefinition (COMMA columnOptionDefinition)*
RR_BRACKET
partitionDefinition?
WITH (
withOptionDefinition (',' withOptionDefinition)*
)
WITH LR_BRACKET
withOptionDefinition (COMMA withOptionDefinition)*
RR_BRACKET
;
@ -67,7 +75,7 @@ partitionColumnName
;
withOptionDefinition
: REVERSE_QUOTE_ID EQUAL REVERSE_QUOTE_ID
: REVERSE_QUOTE_ID EQUAL_SYMBOL REVERSE_QUOTE_ID
;
createDatabase