lexer grammar FlinkSqlLexer;

channels { MYSQLCOMMENT }

// SKIP

SPACE:                               [ \t\r\n]+    -> channel(HIDDEN);
SPEC_MYSQL_COMMENT:                  '/*!' .+? '*/' -> channel(MYSQLCOMMENT);
COMMENT_INPUT:                       '/*' .*? '*/' -> channel(HIDDEN);
LINE_COMMENT:                        (
                                       ('-- ' | '#') ~[\r\n]* ('\r'? '\n' | EOF)
                                       | '--' ('\r'? '\n' | EOF)
                                     ) -> channel(HIDDEN);


// Common Keywords

SELECT:                       'SELECT';
FROM:                         'FROM';
ADD:                          'ADD';
AS:                           'AS';
ALL:                          'ALL';
ANY:                          'ANY';
DISTINCT:                     'DISTINCT';
WHERE:                        'WHERE';
GROUP:                        'GROUP';
BY:                           'BY';
GROUPING:                     'GROUPING';
SETS:                         'SETS';
CUBE:                         'CUBE';
ROLLUP:                       'ROLLUP';
ORDER:                        'ORDER';
HAVING:                       'HAVING';
LIMIT:                        'LIMIT';
AT:                           'AT';
OR:                           'OR';
AND:                          'AND';
IN:                           'IN';
NOT:                          'NOT';
NO:                           'NO';
EXISTS:                       'EXISTS';
BETWEEN:                      'BETWEEN';
LIKE:                         'LIKE';
RLIKE:                        'RLIKE';
IS:                           'IS';
TRUE:                         'TRUE';
FALSE:                        'FALSE';
NULLS:                        'NULLS';
ASC:                          'ASC';
DESC:                         'DESC';
FOR:                          'FOR';
INTERVAL:                     'INTERVAL';
CASE:                         'CASE';
WHEN:                         'WHEN';
THEN:                         'THEN';
ELSE:                         'ELSE';
END:                          'END';
JOIN:                         'JOIN';
CROSS:                        'CROSS';
OUTER:                        'OUTER';
INNER:                        'INNER';
LEFT:                         'LEFT';
SEMI:                         'SEMI';
RIGHT:                        'RIGHT';
FULL:                         'FULL';
NATURAL:                      'NATURAL';
ON:                           'ON';
PIVOT:                        'PIVOT';
LATERAL:                      'LATERAL';
WINDOW:                       'WINDOW';
OVER:                         'OVER';
PARTITION:                    'PARTITION';
RANGE:                        'RANGE';
ROWS:                         'ROWS';
UNBOUNDED:                    'UNBOUNDED';
PRECEDING:                    'PRECEDING';
FOLLOWING:                    'FOLLOWING';
CURRENT:                      'CURRENT';
FIRST:                        'FIRST';
AFTER:                        'AFTER';
LAST:                         'LAST';
WITH:                         'WITH';
VALUES:                       'VALUES';
CREATE:                       'CREATE';
TABLE:                        'TABLE';
DIRECTORY:                    'DIRECTORY';
VIEW:                         'VIEW';
REPLACE:                      'REPLACE';
INSERT:                       'INSERT';
DELETE:                       'DELETE';
INTO:                         'INTO';
DESCRIBE:                     'DESCRIBE';
EXPLAIN:                      'EXPLAIN';
FORMAT:                       'FORMAT';
LOGICAL:                      'LOGICAL';
CODEGEN:                      'CODEGEN';
COST:                         'COST';
CAST:                         'CAST';
SHOW:                         'SHOW';
TABLES:                       'TABLES';
COLUMNS:                      'COLUMNS';
COLUMN:                       'COLUMN';
USE:                          'USE';
PARTITIONS:                   'PARTITIONS';
FUNCTIONS:                    'FUNCTIONS';
DROP:                         'DROP';
UNION:                        'UNION';
EXCEPT:                       'EXCEPT';
SETMINUS:                     'SETMINUS';
INTERSECT:                    'INTERSECT';
TO:                           'TO';
TABLESAMPLE:                  'TABLESAMPLE';
STRATIFY:                     'STRATIFY';
ALTER:                        'ALTER';
RENAME:                       'RENAME';
STRUCT:                       'STRUCT';
COMMENT:                      'COMMENT';
SET:                          'SET';
RESET:                        'RESET';
DATA:                         'DATA';
START:                        'START';
TRANSACTION:                  'TRANSACTION';
COMMIT:                       'COMMIT';
ROLLBACK:                     'ROLLBACK';
MACRO:                        'MACRO';
IGNORE:                       'IGNORE';
BOTH:                         'BOTH';
LEADING:                      'LEADING';
TRAILING:                     'TRAILING';
IF:                           'IF';
POSITION:                     'POSITION';
EXTRACT:                      'EXTRACT';
EQ:                           'EQ';
NSEQ:                         'NSEQ';
NEQ:                          'NEQ';
NEQJ:                         'NEQJ';
LT:                           'LT';
LTE:                          'LTE';
GT:                           'GT';
GTE:                          'GTE';
PLUS:                         'PLUS';
MINUS:                        'MINUS';
ASTERISK:                     'ASTERISK';
SLASH:                        'SLASH';
PERCENT:                      'PERCENT';
DIV:                          'DIV';
TILDE:                        'TILDE';
AMPERSAND:                    'AMPERSAND';
PIPE:                         'PIPE';
CONCAT_PIPE:                  'CONCAT_PIPE';
HAT:                          'HAT';
PERCENTLIT:                   'PERCENTLIT';
BUCKET:                       'BUCKET';
OUT:                          'OUT';
OF:                           'OF';
SORT:                         'SORT';
CLUSTER:                      'CLUSTER';
DISTRIBUTE:                   'DISTRIBUTE';
OVERWRITE:                    'OVERWRITE';
TRANSFORM:                    'TRANSFORM';
REDUCE:                       'REDUCE';
USING:                        'USING';
SERDE:                        'SERDE';
SERDEPROPERTIES:              'SERDEPROPERTIES';
RECORDREADER:                 'RECORDREADER';
RECORDWRITER:                 'RECORDWRITER';
DELIMITED:                    'DELIMITED';
FIELDS:                       'FIELDS';
TERMINATED:                   'TERMINATED';
COLLECTION:                   'COLLECTION';
ITEMS:                        'ITEMS';
KEYS:                         'KEYS';
ESCAPED:                      'ESCAPED';
LINES:                        'LINES';
SEPARATED:                    'SEPARATED';
FUNCTION:                     'FUNCTION';
EXTENDED:                     'EXTENDED';
REFRESH:                      'REFRESH';
CLEAR:                        'CLEAR';
CACHE:                        'CACHE';
UNCACHE:                      'UNCACHE';
LAZY:                         'LAZY';
FORMATTED:                    'FORMATTED';
GLOBAL:                       'GLOBAL';
TEMPORARY:                    'TEMPORARY';
OPTIONS:                      'OPTIONS';
UNSET:                        'UNSET';
TBLPROPERTIES:                'TBLPROPERTIES';
DBPROPERTIES:                 'DBPROPERTIES';
BUCKETS:                      'BUCKETS';
SKEWED:                       'SKEWED';
STORED:                       'STORED';
DIRECTORIES:                  'DIRECTORIES';
LOCATION:                     'LOCATION';
EXCHANGE:                     'EXCHANGE';
ARCHIVE:                      'ARCHIVE';
UNARCHIVE:                    'UNARCHIVE';
FILEFORMAT:                   'FILEFORMAT';
TOUCH:                        'TOUCH';
COMPACT:                      'COMPACT';
CONCATENATE:                  'CONCATENATE';
CHANGE:                       'CHANGE';
CASCADE:                      'CASCADE';
RESTRICT:                     'RESTRICT';
CLUSTERED:                    'CLUSTERED';
SORTED:                       'SORTED';
PURGE:                        'PURGE';
INPUTFORMAT:                  'INPUTFORMAT';
OUTPUTFORMAT:                 'OUTPUTFORMAT';
DATABASE:                     'DATABASE';
DATABASES:                    'DATABASES';
DFS:                          'DFS';
TRUNCATE:                     'TRUNCATE';
ANALYZE:                      'ANALYZE';
COMPUTE:                      'COMPUTE';
LIST:                         'LIST';
STATISTICS:                   'STATISTICS';
PARTITIONED:                  'PARTITIONED';
EXTERNAL:                     'EXTERNAL';
DEFINED:                      'DEFINED';
REVOKE:                       'REVOKE';
GRANT:                        'GRANT';
LOCK:                         'LOCK';
UNLOCK:                       'UNLOCK';
MSCK:                         'MSCK';
REPAIR:                       'REPAIR';
RECOVER:                      'RECOVER';
EXPORT:                       'EXPORT';
IMPORT:                       'IMPORT';
LOAD:                         'LOAD';
ROLE:                         'ROLE';
ROLES:                        'ROLES';
COMPACTIONS:                  'COMPACTIONS';
PRINCIPALS:                   'PRINCIPALS';
TRANSACTIONS:                 'TRANSACTIONS';
INDEX:                        'INDEX';
INDEXES:                      'INDEXES';
LOCKS:                        'LOCKS';
OPTION:                       'OPTION';
ANTI:                         'ANTI';
LOCAL:                        'LOCAL';
INPATH:                       'INPATH';
WATERMARK:                    'WATERMARK';
UNNEST:                       'UNNEST';
MATCH_RECOGNIZE:              'MATCH_RECOGNIZE';
MEASURES:                     'MEASURES';
ONE:                          'ONE';
PER:                          'PER';
MATCH:                        'MATCH';
SKIP1:                        'SKIP1';
NEXT:                         'NEXT';
PAST:                         'PAST';
PATTERN:                      'PATTERN';
WITHIN:                       'WITHIN';
DEFINE:                       'DEFINE';
BIGINT_LITERAL:               'BIGINT_LITERAL';
SMALLINT_LITERAL:             'SMALLINT_LITERAL';
TINYINT_LITERAL:              'TINYINT_LITERAL';
INTEGER_VALUE:                'INTEGER_VALUE';
DECIMAL_VALUE:                'DECIMAL_VALUE';
DOUBLE_LITERAL:               'DOUBLE_LITERAL';
BIGDECIMAL_LITERAL:           'BIGDECIMAL_LITERAL';
IDENTIFIER:                   'IDENTIFIER';
BACKQUOTED_IDENTIFIER:        'BACKQUOTED_IDENTIFIER';
SIMPLE_COMMENT:               'SIMPLE_COMMENT';
BRACKETED_EMPTY_COMMENT:      'BRACKETED_EMPTY_COMMENT';
BRACKETED_COMMENT:            'BRACKETED_COMMENT';
WS:                           'WS';
UNRECOGNIZED:                 'UNRECOGNIZED';
REVERSE_QUOTE_ID:             '"' ~'"'+ '"';
DOT_ID:                       '.' ID_LITERAL;
ID:                           ID_LITERAL;


// DATA TYPE Keywords

STRING:                       'STRING';
ARRAY:                        'ARRAY';
MAP:                          'MAP';
CHAR:                         'CHAR';
VARCHAR:                      'VARCHAR';
BINARY:                       'BINARY';
VARBINARY:                    'VARBINARY';
BYTES:                        'BYTES';
DECIMAL:                      'DECIMAL';
TINYINT:                      'TINYINT';
SMALLINT:                     'SMALLINT';
INT:                          'INT';
BIGINT:                       'BIGINT';
FLOAT:                        'FLOAT';
DOUBLE:                       'DOUBLE';
DATE:                         'DATE';
TIME:                         'TIME';
TIMESTAMP:                    'TIMESTAMP';
MULTISET:                     'MULTISET';
BOOLEAN:                      'BOOLEAN';
RAW:                          'RAW';
ROW:                          'ROW';
NULL:                         'NULL';


// single character Keywords

EQUAL:                        '=';
COMMA:                        ',';


fragment ID_LITERAL:                 [A-Z_0-9a-z]*?[A-Z_a-z]+?[A-Z_0-9a-z]*;
