From 0c82e06022e5672be73f9fe7005a2e77c3212731 Mon Sep 17 00:00:00 2001 From: Georgy Frolov Date: Sat, 21 Nov 2020 16:54:49 +0300 Subject: [PATCH 1/3] Created lexer module --- .gitignore | 4 ++-- README.md | 6 +++--- bin/README.md | 0 grammar/MySQLBaseLexer.py | 5 +++++ grammar/__init__.py | 2 ++ test.py | 18 ++++++++++++++++-- 6 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 bin/README.md create mode 100644 grammar/MySQLBaseLexer.py create mode 100644 grammar/__init__.py diff --git a/.gitignore b/.gitignore index 83684a2..47aa65b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -antlr-4.7.2-complete.jar +*.jar MySQLParser.interp MySQLParser.py MySQLParserListener.py MySQLLexer.interp MySQLLexer.py -grammar/__pycache__ \ No newline at end of file +grammar/__pycache__ diff --git a/README.md b/README.md index e39ce8d..054782d 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ Setting up antlr: ``` -wget http://www.antlr.org/download/antlr-4.7.2-complete.jar > bin -export CLASSPATH=${PWD}"/antlr-4.7.2-complete.jar:$CLASSPATH" -alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.7.2-complete.jar:$CLASSPATH" org.antlr.v4.Tool' +wget http://www.antlr.org/download/antlr-4.8-complete.jar -O bin/antlr-4.8-complete.jar +export CLASSPATH=${PWD}"/antlr-4.8-complete.jar:$CLASSPATH" +alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.8-complete.jar:$CLASSPATH" org.antlr.v4.Tool' alias grun='java org.antlr.v4.gui.TestRig' ``` diff --git a/bin/README.md b/bin/README.md new file mode 100644 index 0000000..e69de29 diff --git a/grammar/MySQLBaseLexer.py b/grammar/MySQLBaseLexer.py new file mode 100644 index 0000000..097f76b --- /dev/null +++ b/grammar/MySQLBaseLexer.py @@ -0,0 +1,5 @@ +from antlr4 import Lexer + + +class MySQLBaseLexer(Lexer): + pass diff --git a/grammar/__init__.py b/grammar/__init__.py new file mode 100644 index 0000000..0b63725 --- /dev/null +++ b/grammar/__init__.py @@ -0,0 +1,2 @@ +from .MySQLLexer import MySQLLexer +# from .MySQLParser import MySQLParser diff --git a/test.py b/test.py index 955413e..40b1c23 100644 --- a/test.py +++ b/test.py @@ -1,3 +1,17 @@ import sys -from MySQLLexer import MySQLLexer -from antlr4 import * \ No newline at end of file +import antlr4 + +from grammar import MySQLLexer +from grammar import MySQLParser +from grammar import MySQLLexer + + +LEXER_VALID_STATEMENTS = [ + 'select 1 from foo' +] + +def test_lexer(): + for stmt in LEXER_VALID_STATEMENTS: + for tok in MySQLLexer(antlr4.InputStream(stmt)).getAllTokens(): + print(tok.text) + From 3e5e1a2e303a5b77fb5453530de10f7074434cb1 Mon Sep 17 00:00:00 2001 From: Georgy Frolov Date: Sat, 21 Nov 2020 18:03:04 +0300 Subject: [PATCH 2/3] a more complecated example query --- README.md | 10 ++++- grammar/MySQLBaseLexer.py | 20 ++++++++- grammar/MySQLLexer.g4 | 90 +++++++++++++++++++-------------------- test.py | 27 ++++++++++-- 4 files changed, 93 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 054782d..d08bd76 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ Setting up antlr: ``` wget http://www.antlr.org/download/antlr-4.8-complete.jar -O bin/antlr-4.8-complete.jar -export CLASSPATH=${PWD}"/antlr-4.8-complete.jar:$CLASSPATH" -alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.8-complete.jar:$CLASSPATH" org.antlr.v4.Tool' +export CLASSPATH=${PWD}"/bin/antlr-4.8-complete.jar" +alias antlr4='java -Xmx500M -cp ${PWD}"/bin/antlr-4.8-complete.jar:$CLASSPATH" org.antlr.v4.Tool' alias grun='java org.antlr.v4.gui.TestRig' ``` @@ -14,3 +14,9 @@ Generating the parser: cd grammar antlr4 -Dlanguage=Python3 MySQLLexer.g4 MySQLParser.g4 ``` + +## TODO + +1. Create all methods in MySQLBaseLexer: + * getText + * diff --git a/grammar/MySQLBaseLexer.py b/grammar/MySQLBaseLexer.py index 097f76b..2d34f77 100644 --- a/grammar/MySQLBaseLexer.py +++ b/grammar/MySQLBaseLexer.py @@ -2,4 +2,22 @@ class MySQLBaseLexer(Lexer): - pass + def determineNumericType(self, s: str): + pass + + def setType(self, *a, **kw): + pass + + def getText(self, *a, **kw): + pass + + def emitDot(self, *a, **kw): + pass + + def isSqlModeActive(self, *a, **kw): + pass + + NoBackslashEscapes = True + + + diff --git a/grammar/MySQLLexer.g4 b/grammar/MySQLLexer.g4 index 30ae606..ba0e59c 100644 --- a/grammar/MySQLLexer.g4 +++ b/grammar/MySQLLexer.g4 @@ -60,13 +60,9 @@ tokens { ULONGLONG_NUMBER } -@postinclude { -#include "MySQLBaseLexer.h" -} //------------------------------------------------------------------------------------------------- -@header {} //------------------------------------------------------------------------------------------------- @@ -100,7 +96,7 @@ BITWISE_AND_OPERATOR: '&'; BITWISE_XOR_OPERATOR: '^'; LOGICAL_OR_OPERATOR: - '||' { setType(CONCAT_PIPES_SYMBOL if isSqlModeActive(PipesAsConcat) else LOGICAL_OR_OPERATOR) } + '||' { self.setType(CONCAT_PIPES_SYMBOL if self.isSqlModeActive(PipesAsConcat) else LOGICAL_OR_OPERATOR) } ; BITWISE_OR_OPERATOR: '|'; @@ -162,7 +158,7 @@ fragment HEXDIGIT: [0-9a-fA-F]; HEX_NUMBER: ('0x' HEXDIGIT+) | ('x\'' HEXDIGIT+ '\''); BIN_NUMBER: ('0b' [01]+) | ('b\'' [01]+ '\''); -INT_NUMBER: DIGITS { setType(determineNumericType(getText())); }; +INT_NUMBER: DIGITS { self.setType(self.determineNumericType(self.getText())); }; // Float types must be handled first or the DOT_IDENTIIFER rule will make them to identifiers // (if there is no leading digit before the dot). @@ -173,7 +169,7 @@ FLOAT_NUMBER: (DIGITS? DOT_SYMBOL)? DIGITS [eE] (MINUS_OPERATOR | PLUS_OPERATO // Hence it's defined before all keywords. // Here we make use of the ability in our base lexer to emit multiple tokens with a single rule. DOT_IDENTIFIER: - DOT_SYMBOL LETTER_WHEN_UNQUOTED_NO_DIGIT LETTER_WHEN_UNQUOTED* { emitDot(); } -> type(IDENTIFIER) + DOT_SYMBOL LETTER_WHEN_UNQUOTED_NO_DIGIT LETTER_WHEN_UNQUOTED* { self.emitDot(); } -> type(IDENTIFIER) ; /* @@ -238,7 +234,7 @@ ACCESSIBLE_SYMBOL: A C C E S S I B L E; ACCOUNT_SYMBOL: A C C O U N T {serverVersion >= 50707}?; ACTION_SYMBOL: A C T I O N; // SQL-2003-N ADD_SYMBOL: A D D; // SQL-2003-R -ADDDATE_SYMBOL: A D D D A T E { setType(determineFunction(ADDDATE_SYMBOL)); }; // MYSQL-FUNC +ADDDATE_SYMBOL: A D D D A T E { self.setType(determineFunction(ADDDATE_SYMBOL)); }; // MYSQL-FUNC AFTER_SYMBOL: A F T E R; // SQL-2003-N AGAINST_SYMBOL: A G A I N S T; AGGREGATE_SYMBOL: A G G R E G A T E; @@ -268,10 +264,10 @@ BIGINT_SYMBOL: B I G I N T; // BINARY_SYMBOL: B I N A R Y; // SQL-2003-R BINLOG_SYMBOL: B I N L O G; BIN_NUM_SYMBOL: B I N '_' N U M; -BIT_AND_SYMBOL: B I T '_' A N D { setType(determineFunction(BIT_AND_SYMBOL)); }; // MYSQL-FUNC -BIT_OR_SYMBOL: B I T '_' O R { setType(determineFunction(BIT_OR_SYMBOL)); }; // MYSQL-FUNC +BIT_AND_SYMBOL: B I T '_' A N D { self.setType(determineFunction(BIT_AND_SYMBOL)); }; // MYSQL-FUNC +BIT_OR_SYMBOL: B I T '_' O R { self.setType(determineFunction(BIT_OR_SYMBOL)); }; // MYSQL-FUNC BIT_SYMBOL: B I T; // MYSQL-FUNC -BIT_XOR_SYMBOL: B I T '_' X O R { setType(determineFunction(BIT_XOR_SYMBOL)); }; // MYSQL-FUNC +BIT_XOR_SYMBOL: B I T '_' X O R { self.setType(determineFunction(BIT_XOR_SYMBOL)); }; // MYSQL-FUNC BLOB_SYMBOL: B L O B; // SQL-2003-R BLOCK_SYMBOL: B L O C K; BOOLEAN_SYMBOL: B O O L E A N; // SQL-2003-R @@ -285,7 +281,7 @@ CALL_SYMBOL: C A L L; // CASCADE_SYMBOL: C A S C A D E; // SQL-2003-N CASCADED_SYMBOL: C A S C A D E D; // SQL-2003-R CASE_SYMBOL: C A S E; // SQL-2003-R -CAST_SYMBOL: C A S T { setType(determineFunction(CAST_SYMBOL)); }; // SQL-2003-R +CAST_SYMBOL: C A S T { self.setType(determineFunction(CAST_SYMBOL)); }; // SQL-2003-R CATALOG_NAME_SYMBOL: C A T A L O G '_' N A M E; // SQL-2003-N CHAIN_SYMBOL: C H A I N; // SQL-2003-N CHANGE_SYMBOL: C H A N G E; @@ -328,31 +324,31 @@ CONTEXT_SYMBOL: C O N T E X T; CONTINUE_SYMBOL: C O N T I N U E; // SQL-2003-R CONTRIBUTORS_SYMBOL: C O N T R I B U T O R S {serverVersion < 50700}?; CONVERT_SYMBOL: C O N V E R T; // SQL-2003-N -COUNT_SYMBOL: C O U N T { setType(determineFunction(COUNT_SYMBOL)); }; // SQL-2003-N +COUNT_SYMBOL: C O U N T { self.setType(determineFunction(COUNT_SYMBOL)); }; // SQL-2003-N CPU_SYMBOL: C P U; CREATE_SYMBOL: C R E A T E; // SQL-2003-R CROSS_SYMBOL: C R O S S; // SQL-2003-R CUBE_SYMBOL: C U B E; // SQL-2003-R -CURDATE_SYMBOL: C U R D A T E { setType(determineFunction(CURDATE_SYMBOL)); }; // MYSQL-FUNC +CURDATE_SYMBOL: C U R D A T E { self.setType(determineFunction(CURDATE_SYMBOL)); }; // MYSQL-FUNC CURRENT_SYMBOL: C U R R E N T {serverVersion >= 50604}?; CURRENT_DATE_SYMBOL: - C U R R E N T '_' D A T E { setType(determineFunction(CURDATE_SYMBOL)); } + C U R R E N T '_' D A T E { self.setType(determineFunction(CURDATE_SYMBOL)); } ; // Synonym, MYSQL-FUNC CURRENT_TIME_SYMBOL: - C U R R E N T '_' T I M E { setType(determineFunction(CURTIME_SYMBOL)); } + C U R R E N T '_' T I M E { self.setType(determineFunction(CURTIME_SYMBOL)); } ; // Synonym, MYSQL-FUNC CURRENT_TIMESTAMP_SYMBOL: C U R R E N T '_' T I M E S T A M P -> type(NOW_SYMBOL); // Synonym CURRENT_USER_SYMBOL: C U R R E N T '_' U S E R; // SQL-2003-R CURSOR_SYMBOL: C U R S O R; // SQL-2003-R CURSOR_NAME_SYMBOL: C U R S O R '_' N A M E; // SQL-2003-N -CURTIME_SYMBOL: C U R T I M E { setType(determineFunction(CURTIME_SYMBOL)); }; // MYSQL-FUNC +CURTIME_SYMBOL: C U R T I M E { self.setType(determineFunction(CURTIME_SYMBOL)); }; // MYSQL-FUNC DATABASE_SYMBOL: D A T A B A S E; DATABASES_SYMBOL: D A T A B A S E S; DATAFILE_SYMBOL: D A T A F I L E; DATA_SYMBOL: D A T A; // SQL-2003-N DATETIME_SYMBOL: D A T E T I M E; // MYSQL -DATE_ADD_SYMBOL: D A T E '_' A D D { setType(determineFunction(DATE_ADD_SYMBOL)); }; -DATE_SUB_SYMBOL: D A T E '_' S U B { setType(determineFunction(DATE_SUB_SYMBOL)); }; +DATE_ADD_SYMBOL: D A T E '_' A D D { self.setType(determineFunction(DATE_ADD_SYMBOL)); }; +DATE_SUB_SYMBOL: D A T E '_' S U B { self.setType(determineFunction(DATE_SUB_SYMBOL)); }; DATE_SYMBOL: D A T E; // SQL-2003-R DAYOFMONTH_SYMBOL: D A Y O F M O N T H -> type(DAY_SYMBOL); // Synonym DAY_HOUR_SYMBOL: D A Y '_' H O U R; @@ -419,7 +415,7 @@ EXPLAIN_SYMBOL: E X P L A I N; // EXPORT_SYMBOL: E X P O R T {serverVersion >= 50606}?; EXTENDED_SYMBOL: E X T E N D E D; EXTENT_SIZE_SYMBOL: E X T E N T '_' S I Z E; -EXTRACT_SYMBOL: E X T R A C T { setType(determineFunction(EXTRACT_SYMBOL)); }; // SQL-2003-N +EXTRACT_SYMBOL: E X T R A C T { self.setType(determineFunction(EXTRACT_SYMBOL)); }; // SQL-2003-N FALSE_SYMBOL: F A L S E; // SQL-2003-R FAST_SYMBOL: F A S T; FAULTS_SYMBOL: F A U L T S; @@ -456,7 +452,7 @@ GRANT_SYMBOL: G R A N T; // GRANTS_SYMBOL: G R A N T S; GROUP_SYMBOL: G R O U P; // SQL-2003-R GROUP_CONCAT_SYMBOL: - G R O U P '_' C O N C A T { setType(determineFunction(GROUP_CONCAT_SYMBOL)); } + G R O U P '_' C O N C A T { self.setType(determineFunction(GROUP_CONCAT_SYMBOL)); } ; HANDLER_SYMBOL: H A N D L E R; HASH_SYMBOL: H A S H; @@ -569,7 +565,7 @@ MAX_SIZE_SYMBOL: M A X '_' S I Z E; MAX_STATEMENT_TIME_SYMBOL: M A X '_' S T A T E M E N T '_' T I M E {50704 < serverVersion and serverVersion < 50708}? ; -MAX_SYMBOL: M A X { setType(determineFunction(MAX_SYMBOL)); }; // SQL-2003-N +MAX_SYMBOL: M A X { self.setType(determineFunction(MAX_SYMBOL)); }; // SQL-2003-N MAX_UPDATES_PER_HOUR_SYMBOL: M A X '_' U P D A T E S '_' P E R '_' H O U R; MAX_USER_CONNECTIONS_SYMBOL: M A X '_' U S E R '_' C O N N E C T I O N S; MAXVALUE_SYMBOL: M A X V A L U E; // SQL-2003-N @@ -581,14 +577,14 @@ MEMORY_SYMBOL: M E M O R Y; MERGE_SYMBOL: M E R G E; // SQL-2003-R MESSAGE_TEXT_SYMBOL: M E S S A G E '_' T E X T; // SQL-2003-N MICROSECOND_SYMBOL: M I C R O S E C O N D; // MYSQL-FUNC -MID_SYMBOL: M I D { setType(determineFunction(SUBSTRING_SYMBOL)); }; // Synonym +MID_SYMBOL: M I D { self.setType(determineFunction(SUBSTRING_SYMBOL)); }; // Synonym MIDDLEINT_SYMBOL: M I D D L E I N T -> type(MEDIUMINT_SYMBOL); // Synonym (for Powerbuilder) MIGRATE_SYMBOL: M I G R A T E; MINUTE_MICROSECOND_SYMBOL: M I N U T E '_' M I C R O S E C O N D; MINUTE_SECOND_SYMBOL: M I N U T E '_' S E C O N D; MINUTE_SYMBOL: M I N U T E; // SQL-2003-R MIN_ROWS_SYMBOL: M I N '_' R O W S; -MIN_SYMBOL: M I N { setType(determineFunction(MIN_SYMBOL)); }; // SQL-2003-N +MIN_SYMBOL: M I N { self.setType(determineFunction(MIN_SYMBOL)); }; // SQL-2003-N MODE_SYMBOL: M O D E; MODIFIES_SYMBOL: M O D I F I E S; // SQL-2003-R MODIFY_SYMBOL: M O D I F Y; @@ -615,9 +611,9 @@ NODEGROUP_SYMBOL: N O D E G R O U P; NONE_SYMBOL: N O N E; // SQL-2003-R NONBLOCKING_SYMBOL: N O N B L O C K I N G {50700 < serverVersion and serverVersion < 50706}?; NOT_SYMBOL: - N O T { setType(NOT2_SYMBOL if isSqlModeActive(HighNotPrecedence) else NOT_SYMBOL) } + N O T { self.setType(NOT2_SYMBOL if self.isSqlModeActive(HighNotPrecedence) else NOT_SYMBOL) } ; // SQL-2003-R -NOW_SYMBOL: N O W { setType(determineFunction(NOW_SYMBOL)); }; +NOW_SYMBOL: N O W { self.setType(determineFunction(NOW_SYMBOL)); }; NO_SYMBOL: N O; // SQL-2003-R NO_WAIT_SYMBOL: N O '_' W A I T; NO_WRITE_TO_BINLOG_SYMBOL: N O '_' W R I T E '_' T O '_' B I N L O G; @@ -659,7 +655,7 @@ PLUGIN_SYMBOL: P L U G I N; POINT_SYMBOL: P O I N T; POLYGON_SYMBOL: P O L Y G O N; // MYSQL PORT_SYMBOL: P O R T; -POSITION_SYMBOL: P O S I T I O N { setType(determineFunction(POSITION_SYMBOL)); }; // SQL-2003-N +POSITION_SYMBOL: P O S I T I O N { self.setType(determineFunction(POSITION_SYMBOL)); }; // SQL-2003-N PRECEDES_SYMBOL: P R E C E D E S {serverVersion >= 50700}?; PRECISION_SYMBOL: P R E C I S I O N; // SQL-2003-R PREPARE_SYMBOL: P R E P A R E; // SQL-2003-R @@ -757,7 +753,7 @@ SESSION_SYMBOL: S E S S I O N; // SERVER_SYMBOL: S E R V E R; SERVER_OPTIONS_SYMBOL: S E R V E R '_' O P T I O N S; SESSION_USER_SYMBOL: - S E S S I O N '_' U S E R { setType(determineFunction(USER_SYMBOL)); } + S E S S I O N '_' U S E R { self.setType(determineFunction(USER_SYMBOL)); } ; // Synonym SET_SYMBOL: S E T; // SQL-2003-R SET_VAR_SYMBOL: S E T '_' V A R; @@ -804,30 +800,30 @@ STATS_PERSISTENT_SYMBOL: S T A T S '_' P E R S I S T E N T; STATS_SAMPLE_PAGES_SYMBOL: S T A T S '_' S A M P L E '_' P A G E S; STATUS_SYMBOL: S T A T U S; STDDEV_SAMP_SYMBOL: - S T D D E V '_' S A M P { setType(determineFunction(STDDEV_SAMP_SYMBOL)); } + S T D D E V '_' S A M P { self.setType(determineFunction(STDDEV_SAMP_SYMBOL)); } ; // SQL-2003-N -STDDEV_SYMBOL: S T D D E V { setType(determineFunction(STD_SYMBOL)); }; // Synonym -STDDEV_POP_SYMBOL: S T D D E V '_' P O P { setType(determineFunction(STD_SYMBOL)); }; // Synonym -STD_SYMBOL: S T D { setType(determineFunction(STD_SYMBOL)); }; +STDDEV_SYMBOL: S T D D E V { self.setType(determineFunction(STD_SYMBOL)); }; // Synonym +STDDEV_POP_SYMBOL: S T D D E V '_' P O P { self.setType(determineFunction(STD_SYMBOL)); }; // Synonym +STD_SYMBOL: S T D { self.setType(determineFunction(STD_SYMBOL)); }; STOP_SYMBOL: S T O P; STORAGE_SYMBOL: S T O R A G E; STORED_SYMBOL: S T O R E D {serverVersion >= 50707}?; STRAIGHT_JOIN_SYMBOL: S T R A I G H T '_' J O I N; STRING_SYMBOL: S T R I N G; SUBCLASS_ORIGIN_SYMBOL: S U B C L A S S '_' O R I G I N; // SQL-2003-N -SUBDATE_SYMBOL: S U B D A T E { setType(determineFunction(SUBDATE_SYMBOL)); }; +SUBDATE_SYMBOL: S U B D A T E { self.setType(determineFunction(SUBDATE_SYMBOL)); }; SUBJECT_SYMBOL: S U B J E C T; SUBPARTITIONS_SYMBOL: S U B P A R T I T I O N S; SUBPARTITION_SYMBOL: S U B P A R T I T I O N; -SUBSTR_SYMBOL: S U B S T R { setType(determineFunction(SUBSTRING_SYMBOL)); }; // Synonym -SUBSTRING_SYMBOL: S U B S T R I N G { setType(determineFunction(SUBSTRING_SYMBOL)); }; // SQL-2003-N -SUM_SYMBOL: S U M { setType(determineFunction(SUM_SYMBOL)); }; // SQL-2003-N +SUBSTR_SYMBOL: S U B S T R { self.setType(determineFunction(SUBSTRING_SYMBOL)); }; // Synonym +SUBSTRING_SYMBOL: S U B S T R I N G { self.setType(determineFunction(SUBSTRING_SYMBOL)); }; // SQL-2003-N +SUM_SYMBOL: S U M { self.setType(determineFunction(SUM_SYMBOL)); }; // SQL-2003-N SUPER_SYMBOL: S U P E R; SUSPEND_SYMBOL: S U S P E N D; SWAPS_SYMBOL: S W A P S; SWITCHES_SYMBOL: S W I T C H E S; -SYSDATE_SYMBOL: S Y S D A T E { setType(determineFunction(SYSDATE_SYMBOL)); }; -SYSTEM_USER_SYMBOL: S Y S T E M '_' U S E R { setType(determineFunction(USER_SYMBOL)); }; +SYSDATE_SYMBOL: S Y S D A T E { self.setType(determineFunction(SYSDATE_SYMBOL)); }; +SYSTEM_USER_SYMBOL: S Y S T E M '_' U S E R { self.setType(determineFunction(USER_SYMBOL)); }; TABLES_SYMBOL: T A B L E S; TABLESPACE_SYMBOL: T A B L E S P A C E; TABLE_REF_PRIORITY_SYMBOL: T A B L E '_' R E F '_' P R I O R I T Y {serverVersion < 80000}?; @@ -852,7 +848,7 @@ TRAILING_SYMBOL: T R A I L I N G; // TRANSACTION_SYMBOL: T R A N S A C T I O N; TRIGGERS_SYMBOL: T R I G G E R S; TRIGGER_SYMBOL: T R I G G E R; // SQL-2003-R -TRIM_SYMBOL: T R I M { setType(determineFunction(TRIM_SYMBOL)); }; // SQL-2003-N +TRIM_SYMBOL: T R I M { self.setType(determineFunction(TRIM_SYMBOL)); }; // SQL-2003-N TRUE_SYMBOL: T R U E; // SQL-2003-R TRUNCATE_SYMBOL: T R U N C A T E; TYPES_SYMBOL: T Y P E S; @@ -891,10 +887,10 @@ VARBINARY_SYMBOL: V A R B I N A R Y; // VARCHAR_SYMBOL: V A R C H A R; // SQL-2003-R VARCHARACTER_SYMBOL: V A R C H A R A C T E R -> type(VARCHAR_SYMBOL); // Synonym VARIABLES_SYMBOL: V A R I A B L E S; -VARIANCE_SYMBOL: V A R I A N C E { setType(determineFunction(VARIANCE_SYMBOL)); }; +VARIANCE_SYMBOL: V A R I A N C E { self.setType(determineFunction(VARIANCE_SYMBOL)); }; VARYING_SYMBOL: V A R Y I N G; // SQL-2003-R -VAR_POP_SYMBOL: V A R '_' P O P { setType(determineFunction(VARIANCE_SYMBOL)); }; // Synonym -VAR_SAMP_SYMBOL: V A R '_' S A M P { setType(determineFunction(VAR_SAMP_SYMBOL)); }; +VAR_POP_SYMBOL: V A R '_' P O P { self.setType(determineFunction(VARIANCE_SYMBOL)); }; // Synonym +VAR_SAMP_SYMBOL: V A R '_' S A M P { self.setType(determineFunction(VAR_SAMP_SYMBOL)); }; VIEW_SYMBOL: V I E W; // SQL-2003-N VIRTUAL_SYMBOL: V I R T U A L {serverVersion >= 50707}?; WAIT_SYMBOL: W A I T; @@ -1069,7 +1065,7 @@ INVALID_INPUT: // The underscore charset token is used to defined the repertoire of a string, though it conflicts // with normal identifiers, which also can start with an underscore. -UNDERSCORE_CHARSET: UNDERLINE_SYMBOL [a-z0-9]+ { setType(checkCharset(getText())); }; +UNDERSCORE_CHARSET: UNDERLINE_SYMBOL [a-z0-9]+ { self.setType(checkCharset(self.getText())); }; // Identifiers might start with a digit, even though it is discouraged, and may not consist entirely of digits only. // All keywords above are automatically excluded. @@ -1090,17 +1086,17 @@ fragment SINGLE_QUOTE: '\''; fragment DOUBLE_QUOTE: '"'; // TODO check syntax -BACK_TICK_QUOTED_ID: BACK_TICK (({not isSqlModeActive(NoBackslashEscapes)}? '\\')? .)*? BACK_TICK; +BACK_TICK_QUOTED_ID: BACK_TICK (({not self.isSqlModeActive(self.NoBackslashEscapes)}? '\\')? .)*? BACK_TICK; // TODO check syntax DOUBLE_QUOTED_TEXT: ( - DOUBLE_QUOTE (({not isSqlModeActive(NoBackslashEscapes)}? '\\' .)? .)*? DOUBLE_QUOTE + DOUBLE_QUOTE (({not self.isSqlModeActive(self.NoBackslashEscapes)}? '\\' .)? .)*? DOUBLE_QUOTE )+ ; // TODO check syntax SINGLE_QUOTED_TEXT: ( - SINGLE_QUOTE (({not isSqlModeActive(NoBackslashEscapes)}? '\\')? .)*? SINGLE_QUOTE + SINGLE_QUOTE (({not self.isSqlModeActive(self.NoBackslashEscapes)}? '\\')? .)*? SINGLE_QUOTE )+ ; @@ -1110,7 +1106,7 @@ SINGLE_QUOTED_TEXT: ( // /*!12345 ... */ - Same as the previous one except code is only used when the given number is lower // than the current server version (specifying so the minimum server version the code can run with). VERSION_COMMENT_START: ('/*!' DIGITS) ( - {checkVersion(getText())}? // Will set inVersionComment if the number matches. + {checkVersion(self.getText())}? // Will set inVersionComment if the number matches. | .*? '*/' ) -> channel(HIDDEN) ; diff --git a/test.py b/test.py index 40b1c23..8bda92a 100644 --- a/test.py +++ b/test.py @@ -2,16 +2,35 @@ import antlr4 from grammar import MySQLLexer -from grammar import MySQLParser +#from grammar import MySQLParser from grammar import MySQLLexer LEXER_VALID_STATEMENTS = [ - 'select 1 from foo' + 'select 1 from foo', + + ('\n' + 'select p.id,\n' + ' p.name,\n' + ' c.desc ContactDesc,\n' + ' a.desc AddressDesc\n' + 'from profile p\n' + 'inner join contact c\n' + ' on p.id = c.profileid\n' + 'inner join address a\n' + ' on p.id = a.profileid\n' + 'where p.name = \'bla\'\n' + ' and c.ord = 1\n' + ' and a.ord = 1\n'), ] + def test_lexer(): for stmt in LEXER_VALID_STATEMENTS: - for tok in MySQLLexer(antlr4.InputStream(stmt)).getAllTokens(): - print(tok.text) + print(f"\n============\nStatement: {stmt}\n") + for tok in MySQLLexer(antlr4.InputStream(stmt)).getAllTokens(): + print(f'{tok.text}\t: {MySQLLexer.symbolicNames[tok.type]}') + +if __name__ == '__main__': + test_lexer() From 3a88fd7c369b763eb0ccc1f3657127251824ffda Mon Sep 17 00:00:00 2001 From: Georgy Frolov Date: Sun, 22 Nov 2020 16:24:58 +0300 Subject: [PATCH 3/3] lexer fixes --- grammar/MySQLBaseLexer.py | 45 ++++- grammar/MySQLLexer.g4 | 384 +++++++++++++++++++------------------- test.py | 36 ---- 3 files changed, 235 insertions(+), 230 deletions(-) delete mode 100644 test.py diff --git a/grammar/MySQLBaseLexer.py b/grammar/MySQLBaseLexer.py index 2d34f77..14db72a 100644 --- a/grammar/MySQLBaseLexer.py +++ b/grammar/MySQLBaseLexer.py @@ -2,22 +2,63 @@ class MySQLBaseLexer(Lexer): + def __init__(self, server_version, *a, **kw): + self.server_version = server_version + super().__init__(*a, **kw) + self.pending_tokens = [] + def determineNumericType(self, s: str): pass + # LENGTH_LONG = 10 + # LENGTH_LONGLONG = 19 + # LENGTH_SIGNED_LONGLONG = 19 + # LENGTH_UNSIGNED_LONGLONG = 20 + # + # value = int(s) + # s_normalized = str(value) if value >= 0 else str(value)[1:] + # + # length = len(s_normalized) + # if length < LENGTH_LONG: + # return self.INT_NUMBER + # + # if value < 0 + def setType(self, *a, **kw): pass def getText(self, *a, **kw): + print('getText') pass def emitDot(self, *a, **kw): - pass + t = self._factory.create(self._tokenFactorySourcePair, self.DOT_SYMBOL, self._text, self._channel, + self._tokenStartCharIndex, + self._tokenStartCharIndex, self._tokenStartLine, self._tokenStartColumn) + self.pending_tokens.append(t) + self._tokenStartCharIndex += 1 def isSqlModeActive(self, *a, **kw): pass - NoBackslashEscapes = True + def nextToken(self): + if self.pending_tokens: + return self.pending_tokens.pop() + next_token = super().nextToken() + if self.pending_tokens: + pending_token = self.pending_tokens.pop() + self.pending_tokens.append(next_token) + return pending_token + return next_token + def checkVersion(self, s: str): + pass + + def determineFunction(self, token: int): + return + + NoBackslashEscapes = True + inVersionComment = True + PipesAsConcat = True diff --git a/grammar/MySQLLexer.g4 b/grammar/MySQLLexer.g4 index ba0e59c..c4aeb35 100644 --- a/grammar/MySQLLexer.g4 +++ b/grammar/MySQLLexer.g4 @@ -96,7 +96,7 @@ BITWISE_AND_OPERATOR: '&'; BITWISE_XOR_OPERATOR: '^'; LOGICAL_OR_OPERATOR: - '||' { self.setType(CONCAT_PIPES_SYMBOL if self.isSqlModeActive(PipesAsConcat) else LOGICAL_OR_OPERATOR) } + '||' { self.setType(self.CONCAT_PIPES_SYMBOL if self.isSqlModeActive(self.PipesAsConcat) else self.LOGICAL_OR_OPERATOR) } ; BITWISE_OR_OPERATOR: '|'; @@ -110,8 +110,8 @@ OPEN_CURLY_SYMBOL: '{'; CLOSE_CURLY_SYMBOL: '}'; UNDERLINE_SYMBOL: '_'; -JSON_SEPARATOR_SYMBOL: '->' {serverVersion >= 50708}?; // MYSQL -JSON_UNQUOTED_SEPARATOR_SYMBOL: '->>' {serverVersion >= 50713}?; // MYSQL +JSON_SEPARATOR_SYMBOL: '->' {self.server_version >= 50708}?; // MYSQL +JSON_UNQUOTED_SEPARATOR_SYMBOL: '->>' {self.server_version >= 50713}?; // MYSQL // The MySQL server parser uses custom code in its lexer to allow base alphanum chars (and ._$) as variable name. // For this it handles user variables in 2 different ways and we have to model this to match that behavior. @@ -158,7 +158,7 @@ fragment HEXDIGIT: [0-9a-fA-F]; HEX_NUMBER: ('0x' HEXDIGIT+) | ('x\'' HEXDIGIT+ '\''); BIN_NUMBER: ('0b' [01]+) | ('b\'' [01]+ '\''); -INT_NUMBER: DIGITS { self.setType(self.determineNumericType(self.getText())); }; +INT_NUMBER: DIGITS { self.setType(self.determineNumericType(self.getText())) }; // Float types must be handled first or the DOT_IDENTIIFER rule will make them to identifiers // (if there is no leading digit before the dot). @@ -169,7 +169,7 @@ FLOAT_NUMBER: (DIGITS? DOT_SYMBOL)? DIGITS [eE] (MINUS_OPERATOR | PLUS_OPERATO // Hence it's defined before all keywords. // Here we make use of the ability in our base lexer to emit multiple tokens with a single rule. DOT_IDENTIFIER: - DOT_SYMBOL LETTER_WHEN_UNQUOTED_NO_DIGIT LETTER_WHEN_UNQUOTED* { self.emitDot(); } -> type(IDENTIFIER) + DOT_SYMBOL LETTER_WHEN_UNQUOTED_NO_DIGIT LETTER_WHEN_UNQUOTED* { self.emitDot() } -> type(IDENTIFIER) ; /* @@ -231,18 +231,18 @@ DOT_IDENTIFIER: //ABORT_SYMBOL: 'ABORT'; // INTERNAL (used in lex) ACCESSIBLE_SYMBOL: A C C E S S I B L E; -ACCOUNT_SYMBOL: A C C O U N T {serverVersion >= 50707}?; +ACCOUNT_SYMBOL: A C C O U N T {self.server_version >= 50707}?; ACTION_SYMBOL: A C T I O N; // SQL-2003-N ADD_SYMBOL: A D D; // SQL-2003-R -ADDDATE_SYMBOL: A D D D A T E { self.setType(determineFunction(ADDDATE_SYMBOL)); }; // MYSQL-FUNC +ADDDATE_SYMBOL: A D D D A T E { self.setType(self.determineFunction(self.ADDDATE_SYMBOL)) }; // MYSQL-FUNC AFTER_SYMBOL: A F T E R; // SQL-2003-N AGAINST_SYMBOL: A G A I N S T; AGGREGATE_SYMBOL: A G G R E G A T E; ALGORITHM_SYMBOL: A L G O R I T H M; ALL_SYMBOL: A L L; // SQL-2003-R ALTER_SYMBOL: A L T E R; // SQL-2003-R -ALWAYS_SYMBOL: A L W A Y S {serverVersion >= 50707}?; -ANALYSE_SYMBOL: A N A L Y S E {serverVersion < 80000}?; +ALWAYS_SYMBOL: A L W A Y S {self.server_version >= 50707}?; +ANALYSE_SYMBOL: A N A L Y S E {self.server_version < 80000}?; ANALYZE_SYMBOL: A N A L Y Z E; AND_SYMBOL: A N D; // SQL-2003-R ANY_SYMBOL: A N Y; // SQL-2003-R @@ -251,7 +251,7 @@ ASC_SYMBOL: A S C; // ASCII_SYMBOL: A S C I I; // MYSQL-FUNC ASENSITIVE_SYMBOL: A S E N S I T I V E; // FUTURE-USE AT_SYMBOL: A T; -AUTHORS_SYMBOL: A U T H O R S {serverVersion < 50700}?; +AUTHORS_SYMBOL: A U T H O R S {self.server_version < 50700}?; AUTOEXTEND_SIZE_SYMBOL: A U T O E X T E N D '_' S I Z E; AUTO_INCREMENT_SYMBOL: A U T O '_' I N C R E M E N T; AVG_ROW_LENGTH_SYMBOL: A V G '_' R O W '_' L E N G T H; @@ -264,10 +264,10 @@ BIGINT_SYMBOL: B I G I N T; // BINARY_SYMBOL: B I N A R Y; // SQL-2003-R BINLOG_SYMBOL: B I N L O G; BIN_NUM_SYMBOL: B I N '_' N U M; -BIT_AND_SYMBOL: B I T '_' A N D { self.setType(determineFunction(BIT_AND_SYMBOL)); }; // MYSQL-FUNC -BIT_OR_SYMBOL: B I T '_' O R { self.setType(determineFunction(BIT_OR_SYMBOL)); }; // MYSQL-FUNC +BIT_AND_SYMBOL: B I T '_' A N D { self.setType(self.determineFunction(self.BIT_AND_SYMBOL)) }; // MYSQL-FUNC +BIT_OR_SYMBOL: B I T '_' O R { self.setType(self.determineFunction(self.BIT_OR_SYMBOL)) }; // MYSQL-FUNC BIT_SYMBOL: B I T; // MYSQL-FUNC -BIT_XOR_SYMBOL: B I T '_' X O R { self.setType(determineFunction(BIT_XOR_SYMBOL)); }; // MYSQL-FUNC +BIT_XOR_SYMBOL: B I T '_' X O R { self.setType(self.determineFunction(self.BIT_XOR_SYMBOL)) }; // MYSQL-FUNC BLOB_SYMBOL: B L O B; // SQL-2003-R BLOCK_SYMBOL: B L O C K; BOOLEAN_SYMBOL: B O O L E A N; // SQL-2003-R @@ -281,12 +281,12 @@ CALL_SYMBOL: C A L L; // CASCADE_SYMBOL: C A S C A D E; // SQL-2003-N CASCADED_SYMBOL: C A S C A D E D; // SQL-2003-R CASE_SYMBOL: C A S E; // SQL-2003-R -CAST_SYMBOL: C A S T { self.setType(determineFunction(CAST_SYMBOL)); }; // SQL-2003-R +CAST_SYMBOL: C A S T { self.setType(self.determineFunction(self.CAST_SYMBOL)) }; // SQL-2003-R CATALOG_NAME_SYMBOL: C A T A L O G '_' N A M E; // SQL-2003-N CHAIN_SYMBOL: C H A I N; // SQL-2003-N CHANGE_SYMBOL: C H A N G E; CHANGED_SYMBOL: C H A N G E D; -CHANNEL_SYMBOL: C H A N N E L {serverVersion >= 50706}?; +CHANNEL_SYMBOL: C H A N N E L {self.server_version >= 50706}?; CHARSET_SYMBOL: C H A R S E T; CHARACTER_SYMBOL: C H A R A C T E R -> type(CHAR_SYMBOL); // Synonym CHAR_SYMBOL: C H A R; // SQL-2003-R @@ -310,7 +310,7 @@ COMMIT_SYMBOL: C O M M I T; // COMPACT_SYMBOL: C O M P A C T; COMPLETION_SYMBOL: C O M P L E T I O N; COMPRESSED_SYMBOL: C O M P R E S S E D; -COMPRESSION_SYMBOL: C O M P R E S S I O N {serverVersion >= 50707}?; +COMPRESSION_SYMBOL: C O M P R E S S I O N {self.server_version >= 50707}?; CONCURRENT_SYMBOL: C O N C U R R E N T; CONDITION_SYMBOL: C O N D I T I O N; // SQL-2003-R, SQL-2008-R CONNECTION_SYMBOL: C O N N E C T I O N; @@ -322,33 +322,33 @@ CONSTRAINT_SCHEMA_SYMBOL: C O N S T R A I N T '_' S C H E M A; // CONTAINS_SYMBOL: C O N T A I N S; // SQL-2003-N CONTEXT_SYMBOL: C O N T E X T; CONTINUE_SYMBOL: C O N T I N U E; // SQL-2003-R -CONTRIBUTORS_SYMBOL: C O N T R I B U T O R S {serverVersion < 50700}?; +CONTRIBUTORS_SYMBOL: C O N T R I B U T O R S {self.server_version < 50700}?; CONVERT_SYMBOL: C O N V E R T; // SQL-2003-N -COUNT_SYMBOL: C O U N T { self.setType(determineFunction(COUNT_SYMBOL)); }; // SQL-2003-N +COUNT_SYMBOL: C O U N T { self.setType(self.determineFunction(self.COUNT_SYMBOL)) }; // SQL-2003-N CPU_SYMBOL: C P U; CREATE_SYMBOL: C R E A T E; // SQL-2003-R CROSS_SYMBOL: C R O S S; // SQL-2003-R CUBE_SYMBOL: C U B E; // SQL-2003-R -CURDATE_SYMBOL: C U R D A T E { self.setType(determineFunction(CURDATE_SYMBOL)); }; // MYSQL-FUNC -CURRENT_SYMBOL: C U R R E N T {serverVersion >= 50604}?; +CURDATE_SYMBOL: C U R D A T E { self.setType(self.determineFunction(self.CURDATE_SYMBOL)) }; // MYSQL-FUNC +CURRENT_SYMBOL: C U R R E N T {self.server_version >= 50604}?; CURRENT_DATE_SYMBOL: - C U R R E N T '_' D A T E { self.setType(determineFunction(CURDATE_SYMBOL)); } + C U R R E N T '_' D A T E { self.setType(self.determineFunction(self.CURDATE_SYMBOL)) } ; // Synonym, MYSQL-FUNC CURRENT_TIME_SYMBOL: - C U R R E N T '_' T I M E { self.setType(determineFunction(CURTIME_SYMBOL)); } + C U R R E N T '_' T I M E { self.setType(self.determineFunction(self.CURTIME_SYMBOL)) } ; // Synonym, MYSQL-FUNC CURRENT_TIMESTAMP_SYMBOL: C U R R E N T '_' T I M E S T A M P -> type(NOW_SYMBOL); // Synonym CURRENT_USER_SYMBOL: C U R R E N T '_' U S E R; // SQL-2003-R CURSOR_SYMBOL: C U R S O R; // SQL-2003-R CURSOR_NAME_SYMBOL: C U R S O R '_' N A M E; // SQL-2003-N -CURTIME_SYMBOL: C U R T I M E { self.setType(determineFunction(CURTIME_SYMBOL)); }; // MYSQL-FUNC +CURTIME_SYMBOL: C U R T I M E { self.setType(self.determineFunction(self.CURTIME_SYMBOL)) }; // MYSQL-FUNC DATABASE_SYMBOL: D A T A B A S E; DATABASES_SYMBOL: D A T A B A S E S; DATAFILE_SYMBOL: D A T A F I L E; DATA_SYMBOL: D A T A; // SQL-2003-N DATETIME_SYMBOL: D A T E T I M E; // MYSQL -DATE_ADD_SYMBOL: D A T E '_' A D D { self.setType(determineFunction(DATE_ADD_SYMBOL)); }; -DATE_SUB_SYMBOL: D A T E '_' S U B { self.setType(determineFunction(DATE_SUB_SYMBOL)); }; +DATE_ADD_SYMBOL: D A T E '_' A D D { self.setType(self.determineFunction(self.DATE_ADD_SYMBOL)) }; +DATE_SUB_SYMBOL: D A T E '_' S U B { self.setType(self.determineFunction(self.DATE_SUB_SYMBOL)) }; DATE_SYMBOL: D A T E; // SQL-2003-R DAYOFMONTH_SYMBOL: D A Y O F M O N T H -> type(DAY_SYMBOL); // Synonym DAY_HOUR_SYMBOL: D A Y '_' H O U R; @@ -362,14 +362,14 @@ DECIMAL_NUM_SYMBOL: D E C I M A L '_' N U M; DECIMAL_SYMBOL: D E C I M A L; // SQL-2003-R DECLARE_SYMBOL: D E C L A R E; // SQL-2003-R DEFAULT_SYMBOL: D E F A U L T; // SQL-2003-R -DEFAULT_AUTH_SYMBOL: D E F A U L T '_' A U T H {serverVersion >= 50604}?; // Internal +DEFAULT_AUTH_SYMBOL: D E F A U L T '_' A U T H {self.server_version >= 50604}?; // Internal DEFINER_SYMBOL: D E F I N E R; DELAYED_SYMBOL: D E L A Y E D; DELAY_KEY_WRITE_SYMBOL: D E L A Y '_' K E Y '_' W R I T E; DELETE_SYMBOL: D E L E T E; // SQL-2003-R DESC_SYMBOL: D E S C; // SQL-2003-N DESCRIBE_SYMBOL: D E S C R I B E; // SQL-2003-R -DES_KEY_FILE_SYMBOL: D E S '_' K E Y '_' F I L E {serverVersion < 80000}?; +DES_KEY_FILE_SYMBOL: D E S '_' K E Y '_' F I L E {self.server_version < 80000}?; DETERMINISTIC_SYMBOL: D E T E R M I N I S T I C; // SQL-2003-R DIAGNOSTICS_SYMBOL: D I A G N O S T I C S; DIRECTORY_SYMBOL: D I R E C T O R Y; @@ -391,7 +391,7 @@ ELSE_SYMBOL: E L S E; // ELSEIF_SYMBOL: E L S E I F; ENABLE_SYMBOL: E N A B L E; ENCLOSED_SYMBOL: E N C L O S E D; -ENCRYPTION_SYMBOL: E N C R Y P T I O N {serverVersion >= 50711}?; +ENCRYPTION_SYMBOL: E N C R Y P T I O N {self.server_version >= 50711}?; END_SYMBOL: E N D; // SQL-2003-R ENDS_SYMBOL: E N D S; END_OF_INPUT_SYMBOL: E N D '_' O F '_' I N P U T; // INTERNAL @@ -410,27 +410,27 @@ EXECUTE_SYMBOL: E X E C U T E; // EXISTS_SYMBOL: E X I S T S; // SQL-2003-R EXIT_SYMBOL: E X I T; EXPANSION_SYMBOL: E X P A N S I O N; -EXPIRE_SYMBOL: E X P I R E {serverVersion >= 50606}?; +EXPIRE_SYMBOL: E X P I R E {self.server_version >= 50606}?; EXPLAIN_SYMBOL: E X P L A I N; // SQL-2003-R -EXPORT_SYMBOL: E X P O R T {serverVersion >= 50606}?; +EXPORT_SYMBOL: E X P O R T {self.server_version >= 50606}?; EXTENDED_SYMBOL: E X T E N D E D; EXTENT_SIZE_SYMBOL: E X T E N T '_' S I Z E; -EXTRACT_SYMBOL: E X T R A C T { self.setType(determineFunction(EXTRACT_SYMBOL)); }; // SQL-2003-N +EXTRACT_SYMBOL: E X T R A C T { self.setType(self.determineFunction(self.EXTRACT_SYMBOL)) }; // SQL-2003-N FALSE_SYMBOL: F A L S E; // SQL-2003-R FAST_SYMBOL: F A S T; FAULTS_SYMBOL: F A U L T S; FETCH_SYMBOL: F E T C H; // SQL-2003-R FIELDS_SYMBOL: F I E L D S -> type(COLUMNS_SYMBOL); // Synonym FILE_SYMBOL: F I L E; -FILE_BLOCK_SIZE_SYMBOL: F I L E '_' B L O C K '_' S I Z E {serverVersion >= 50707}?; -FILTER_SYMBOL: F I L T E R {serverVersion >= 50700}?; +FILE_BLOCK_SIZE_SYMBOL: F I L E '_' B L O C K '_' S I Z E {self.server_version >= 50707}?; +FILTER_SYMBOL: F I L T E R {self.server_version >= 50700}?; FIRST_SYMBOL: F I R S T; // SQL-2003-N FIXED_SYMBOL: F I X E D; FLOAT4_SYMBOL: F L O A T '4' -> type(FLOAT_SYMBOL); // Synonym FLOAT8_SYMBOL: F L O A T '8' -> type(DOUBLE_SYMBOL); // Synonym FLOAT_SYMBOL: F L O A T; // SQL-2003-R FLUSH_SYMBOL: F L U S H; -FOLLOWS_SYMBOL: F O L L O W S {serverVersion >= 50700}?; +FOLLOWS_SYMBOL: F O L L O W S {self.server_version >= 50700}?; FORCE_SYMBOL: F O R C E; FOREIGN_SYMBOL: F O R E I G N; // SQL-2003-R FOR_SYMBOL: F O R; // SQL-2003-R @@ -440,10 +440,10 @@ FROM_SYMBOL: F R O M; FULL_SYMBOL: F U L L; // SQL-2003-R FULLTEXT_SYMBOL: F U L L T E X T; FUNCTION_SYMBOL: F U N C T I O N; // SQL-2003-R -GET_SYMBOL: G E T {serverVersion >= 50604}?; +GET_SYMBOL: G E T {self.server_version >= 50604}?; GENERAL_SYMBOL: G E N E R A L; -GENERATED_SYMBOL: G E N E R A T E D {serverVersion >= 50707}?; -GROUP_REPLICATION_SYMBOL: G R O U P '_' R E P L I C A T I O N {serverVersion >= 50707}?; +GENERATED_SYMBOL: G E N E R A T E D {self.server_version >= 50707}?; +GROUP_REPLICATION_SYMBOL: G R O U P '_' R E P L I C A T I O N {self.server_version >= 50707}?; GEOMETRYCOLLECTION_SYMBOL: G E O M E T R Y C O L L E C T I O N; // MYSQL GEOMETRY_SYMBOL: G E O M E T R Y; GET_FORMAT_SYMBOL: G E T '_' F O R M A T; // MYSQL-FUNC @@ -452,7 +452,7 @@ GRANT_SYMBOL: G R A N T; // GRANTS_SYMBOL: G R A N T S; GROUP_SYMBOL: G R O U P; // SQL-2003-R GROUP_CONCAT_SYMBOL: - G R O U P '_' C O N C A T { self.setType(determineFunction(GROUP_CONCAT_SYMBOL)); } + G R O U P '_' C O N C A T { self.setType(self.determineFunction(self.GROUP_CONCAT_SYMBOL)) } ; HANDLER_SYMBOL: H A N D L E R; HASH_SYMBOL: H A S H; @@ -479,7 +479,7 @@ INOUT_SYMBOL: I N O U T; // INSENSITIVE_SYMBOL: I N S E N S I T I V E; // SQL-2003-R INSERT_SYMBOL: I N S E R T; // SQL-2003-R INSERT_METHOD_SYMBOL: I N S E R T '_' M E T H O D; -INSTANCE_SYMBOL: I N S T A N C E {serverVersion >= 50713}?; +INSTANCE_SYMBOL: I N S T A N C E {self.server_version >= 50713}?; INSTALL_SYMBOL: I N S T A L L; INTEGER_SYMBOL: I N T E G E R -> type(INT_SYMBOL); // Synonym INTERVAL_SYMBOL: I N T E R V A L; // SQL-2003-R @@ -497,7 +497,7 @@ ISOLATION_SYMBOL: I S O L A T I O N; // ISSUER_SYMBOL: I S S U E R; ITERATE_SYMBOL: I T E R A T E; JOIN_SYMBOL: J O I N; // SQL-2003-R -JSON_SYMBOL: J S O N {serverVersion >= 50708}?; // MYSQL +JSON_SYMBOL: J S O N {self.server_version >= 50708}?; // MYSQL KEYS_SYMBOL: K E Y S; KEY_BLOCK_SIZE_SYMBOL: K E Y '_' B L O C K '_' S I Z E; KEY_SYMBOL: K E Y; // SQL-2003-N @@ -531,8 +531,8 @@ LONG_NUM_SYMBOL: L O N G '_' N U M; LONG_SYMBOL: L O N G; LOOP_SYMBOL: L O O P; LOW_PRIORITY_SYMBOL: L O W '_' P R I O R I T Y; -MASTER_AUTO_POSITION_SYMBOL: M A S T E R '_' A U T O '_' P O S I T I O N {serverVersion >= 50605}?; -MASTER_BIND_SYMBOL: M A S T E R '_' B I N D {serverVersion >= 50602}?; +MASTER_AUTO_POSITION_SYMBOL: M A S T E R '_' A U T O '_' P O S I T I O N {self.server_version >= 50605}?; +MASTER_BIND_SYMBOL: M A S T E R '_' B I N D {self.server_version >= 50602}?; MASTER_CONNECT_RETRY_SYMBOL: M A S T E R '_' C O N N E C T '_' R E T R Y; MASTER_DELAY_SYMBOL: M A S T E R '_' D E L A Y; MASTER_HOST_SYMBOL: M A S T E R '_' H O S T; @@ -540,21 +540,21 @@ MASTER_LOG_FILE_SYMBOL: M A S T E R '_' L O G '_' F I L E; MASTER_LOG_POS_SYMBOL: M A S T E R '_' L O G '_' P O S; MASTER_PASSWORD_SYMBOL: M A S T E R '_' P A S S W O R D; MASTER_PORT_SYMBOL: M A S T E R '_' P O R T; -MASTER_RETRY_COUNT_SYMBOL: M A S T E R '_' R E T R Y '_' C O U N T {serverVersion >= 50601}?; +MASTER_RETRY_COUNT_SYMBOL: M A S T E R '_' R E T R Y '_' C O U N T {self.server_version >= 50601}?; MASTER_SERVER_ID_SYMBOL: M A S T E R '_' S E R V E R '_' I D; MASTER_SSL_CAPATH_SYMBOL: M A S T E R '_' S S L '_' C A P A T H; MASTER_SSL_CA_SYMBOL: M A S T E R '_' S S L '_' C A; MASTER_SSL_CERT_SYMBOL: M A S T E R '_' S S L '_' C E R T; MASTER_SSL_CIPHER_SYMBOL: M A S T E R '_' S S L '_' C I P H E R; -MASTER_SSL_CRL_SYMBOL: M A S T E R '_' S S L '_' C R L {serverVersion >= 50603}?; -MASTER_SSL_CRLPATH_SYMBOL: M A S T E R '_' S S L '_' C R L P A T H {serverVersion >= 50603}?; +MASTER_SSL_CRL_SYMBOL: M A S T E R '_' S S L '_' C R L {self.server_version >= 50603}?; +MASTER_SSL_CRLPATH_SYMBOL: M A S T E R '_' S S L '_' C R L P A T H {self.server_version >= 50603}?; MASTER_SSL_KEY_SYMBOL: M A S T E R '_' S S L '_' K E Y; MASTER_SSL_SYMBOL: M A S T E R '_' S S L; MASTER_SSL_VERIFY_SERVER_CERT_SYMBOL: M A S T E R '_' S S L '_' V E R I F Y '_' S E R V E R '_' C E R T? ; MASTER_SYMBOL: M A S T E R; -MASTER_TLS_VERSION_SYMBOL: M A S T E R '_' T L S '_' V E R S I O N {serverVersion >= 50713}?; +MASTER_TLS_VERSION_SYMBOL: M A S T E R '_' T L S '_' V E R S I O N {self.server_version >= 50713}?; MASTER_USER_SYMBOL: M A S T E R '_' U S E R; MASTER_HEARTBEAT_PERIOD_SYMBOL: M A S T E R '_' H E A R T B E A T '_' P E R I O D?; MATCH_SYMBOL: M A T C H; // SQL-2003-R @@ -563,9 +563,9 @@ MAX_QUERIES_PER_HOUR_SYMBOL: M A X '_' Q U E R I E S '_' P E R '_' H O U R; MAX_ROWS_SYMBOL: M A X '_' R O W S; MAX_SIZE_SYMBOL: M A X '_' S I Z E; MAX_STATEMENT_TIME_SYMBOL: - M A X '_' S T A T E M E N T '_' T I M E {50704 < serverVersion and serverVersion < 50708}? + M A X '_' S T A T E M E N T '_' T I M E {50704 < self.server_version and self.server_version < 50708}? ; -MAX_SYMBOL: M A X { self.setType(determineFunction(MAX_SYMBOL)); }; // SQL-2003-N +MAX_SYMBOL: M A X { self.setType(self.determineFunction(self.MAX_SYMBOL)) }; // SQL-2003-N MAX_UPDATES_PER_HOUR_SYMBOL: M A X '_' U P D A T E S '_' P E R '_' H O U R; MAX_USER_CONNECTIONS_SYMBOL: M A X '_' U S E R '_' C O N N E C T I O N S; MAXVALUE_SYMBOL: M A X V A L U E; // SQL-2003-N @@ -577,14 +577,14 @@ MEMORY_SYMBOL: M E M O R Y; MERGE_SYMBOL: M E R G E; // SQL-2003-R MESSAGE_TEXT_SYMBOL: M E S S A G E '_' T E X T; // SQL-2003-N MICROSECOND_SYMBOL: M I C R O S E C O N D; // MYSQL-FUNC -MID_SYMBOL: M I D { self.setType(determineFunction(SUBSTRING_SYMBOL)); }; // Synonym +MID_SYMBOL: M I D { self.setType(self.determineFunction(self.SUBSTRING_SYMBOL)) }; // Synonym MIDDLEINT_SYMBOL: M I D D L E I N T -> type(MEDIUMINT_SYMBOL); // Synonym (for Powerbuilder) MIGRATE_SYMBOL: M I G R A T E; MINUTE_MICROSECOND_SYMBOL: M I N U T E '_' M I C R O S E C O N D; MINUTE_SECOND_SYMBOL: M I N U T E '_' S E C O N D; MINUTE_SYMBOL: M I N U T E; // SQL-2003-R MIN_ROWS_SYMBOL: M I N '_' R O W S; -MIN_SYMBOL: M I N { self.setType(determineFunction(MIN_SYMBOL)); }; // SQL-2003-N +MIN_SYMBOL: M I N { self.setType(self.determineFunction(self.MIN_SYMBOL)) }; // SQL-2003-N MODE_SYMBOL: M O D E; MODIFIES_SYMBOL: M O D I F I E S; // SQL-2003-R MODIFY_SYMBOL: M O D I F Y; @@ -604,33 +604,33 @@ NCHAR_SYMBOL: N C H A R; // NDB_SYMBOL: N D B -> type(NDBCLUSTER_SYMBOL); //Synonym NDBCLUSTER_SYMBOL: N D B C L U S T E R; NEG_SYMBOL: N E G; -NEVER_SYMBOL: N E V E R {serverVersion >= 50704}?; +NEVER_SYMBOL: N E V E R {self.server_version >= 50704}?; NEW_SYMBOL: N E W; // SQL-2003-R NEXT_SYMBOL: N E X T; // SQL-2003-N NODEGROUP_SYMBOL: N O D E G R O U P; NONE_SYMBOL: N O N E; // SQL-2003-R -NONBLOCKING_SYMBOL: N O N B L O C K I N G {50700 < serverVersion and serverVersion < 50706}?; +NONBLOCKING_SYMBOL: N O N B L O C K I N G {50700 < self.server_version and self.server_version < 50706}?; NOT_SYMBOL: - N O T { self.setType(NOT2_SYMBOL if self.isSqlModeActive(HighNotPrecedence) else NOT_SYMBOL) } + N O T { self.setType(self.NOT2_SYMBOL if self.isSqlModeActive(self.HighNotPrecedence) else self.NOT_SYMBOL) } ; // SQL-2003-R -NOW_SYMBOL: N O W { self.setType(determineFunction(NOW_SYMBOL)); }; +NOW_SYMBOL: N O W { self.setType(self.determineFunction(self.NOW_SYMBOL)) }; NO_SYMBOL: N O; // SQL-2003-R NO_WAIT_SYMBOL: N O '_' W A I T; NO_WRITE_TO_BINLOG_SYMBOL: N O '_' W R I T E '_' T O '_' B I N L O G; NULL_SYMBOL: N U L L; // SQL-2003-R -NUMBER_SYMBOL: N U M B E R {serverVersion >= 50606}?; +NUMBER_SYMBOL: N U M B E R {self.server_version >= 50606}?; NUMERIC_SYMBOL: N U M E R I C; // SQL-2003-R NVARCHAR_SYMBOL: N V A R C H A R; OFFLINE_SYMBOL: O F F L I N E; OFFSET_SYMBOL: O F F S E T; -OLD_PASSWORD_SYMBOL: O L D '_' P A S S W O R D {serverVersion < 50706}?; +OLD_PASSWORD_SYMBOL: O L D '_' P A S S W O R D {self.server_version < 50706}?; ON_SYMBOL: O N; // SQL-2003-R ONE_SYMBOL: O N E; ONLINE_SYMBOL: O N L I N E; -ONLY_SYMBOL: O N L Y {serverVersion >= 50605}?; +ONLY_SYMBOL: O N L Y {self.server_version >= 50605}?; OPEN_SYMBOL: O P E N; // SQL-2003-R OPTIMIZE_SYMBOL: O P T I M I Z E; -OPTIMIZER_COSTS_SYMBOL: O P T I M I Z E R '_' C O S T S {serverVersion >= 50706}?; +OPTIMIZER_COSTS_SYMBOL: O P T I M I Z E R '_' C O S T S {self.server_version >= 50706}?; OPTIONS_SYMBOL: O P T I O N S; OPTION_SYMBOL: O P T I O N; // SQL-2003-N OPTIONALLY_SYMBOL: O P T I O N A L L Y; @@ -650,13 +650,13 @@ PARTITION_SYMBOL: P A R T I T I O N; // PASSWORD_SYMBOL: P A S S W O R D; PHASE_SYMBOL: P H A S E; PLUGINS_SYMBOL: P L U G I N S; -PLUGIN_DIR_SYMBOL: P L U G I N '_' D I R {serverVersion >= 50604}?; // Internal +PLUGIN_DIR_SYMBOL: P L U G I N '_' D I R {self.server_version >= 50604}?; // Internal PLUGIN_SYMBOL: P L U G I N; POINT_SYMBOL: P O I N T; POLYGON_SYMBOL: P O L Y G O N; // MYSQL PORT_SYMBOL: P O R T; -POSITION_SYMBOL: P O S I T I O N { self.setType(determineFunction(POSITION_SYMBOL)); }; // SQL-2003-N -PRECEDES_SYMBOL: P R E C E D E S {serverVersion >= 50700}?; +POSITION_SYMBOL: P O S I T I O N { self.setType(self.determineFunction(self.POSITION_SYMBOL)) }; // SQL-2003-N +PRECEDES_SYMBOL: P R E C E D E S {self.server_version >= 50700}?; PRECISION_SYMBOL: P R E C I S I O N; // SQL-2003-R PREPARE_SYMBOL: P R E P A R E; // SQL-2003-R PRESERVE_SYMBOL: P R E S E R V E; @@ -681,7 +681,7 @@ READ_WRITE_SYMBOL: R E A D '_' W R I T E; REAL_SYMBOL: R E A L; // SQL-2003-R REBUILD_SYMBOL: R E B U I L D; RECOVER_SYMBOL: R E C O V E R; -REDOFILE_SYMBOL: R E D O F I L E {serverVersion < 80000}?; +REDOFILE_SYMBOL: R E D O F I L E {self.server_version < 80000}?; REDO_BUFFER_SIZE_SYMBOL: R E D O '_' B U F F E R '_' S I Z E; REDUNDANT_SYMBOL: R E D U N D A N T; REFERENCES_SYMBOL: R E F E R E N C E S; // SQL-2003-R @@ -701,19 +701,19 @@ REPEATABLE_SYMBOL: R E P E A T A B L E; // REPEAT_SYMBOL: R E P E A T; // MYSQL-FUNC REPLACE_SYMBOL: R E P L A C E; // MYSQL-FUNC REPLICATION_SYMBOL: R E P L I C A T I O N; -REPLICATE_DO_DB_SYMBOL: R E P L I C A T E '_' D O '_' D B {serverVersion >= 50700}?; -REPLICATE_IGNORE_DB_SYMBOL: R E P L I C A T E '_' I G N O R E '_' D B {serverVersion >= 50700}?; -REPLICATE_DO_TABLE_SYMBOL: R E P L I C A T E '_' D O '_' T A B L E {serverVersion >= 50700}?; +REPLICATE_DO_DB_SYMBOL: R E P L I C A T E '_' D O '_' D B {self.server_version >= 50700}?; +REPLICATE_IGNORE_DB_SYMBOL: R E P L I C A T E '_' I G N O R E '_' D B {self.server_version >= 50700}?; +REPLICATE_DO_TABLE_SYMBOL: R E P L I C A T E '_' D O '_' T A B L E {self.server_version >= 50700}?; REPLICATE_IGNORE_TABLE_SYMBOL: - R E P L I C A T E '_' I G N O R E '_' T A B L E {serverVersion >= 50700}? + R E P L I C A T E '_' I G N O R E '_' T A B L E {self.server_version >= 50700}? ; REPLICATE_WILD_DO_TABLE_SYMBOL: - R E P L I C A T E '_' W I L D '_' D O '_' T A B L E {serverVersion >= 50700}? + R E P L I C A T E '_' W I L D '_' D O '_' T A B L E {self.server_version >= 50700}? ; REPLICATE_WILD_IGNORE_TABLE_SYMBOL: - R E P L I C A T E '_' W I L D '_' I G N O R E '_' T A B L E {serverVersion >= 50700}? + R E P L I C A T E '_' W I L D '_' I G N O R E '_' T A B L E {self.server_version >= 50700}? ; -REPLICATE_REWRITE_DB_SYMBOL: R E P L I C A T E '_' R E W R I T E '_' D B {serverVersion >= 50700}?; +REPLICATE_REWRITE_DB_SYMBOL: R E P L I C A T E '_' R E W R I T E '_' D B {self.server_version >= 50700}?; REQUIRE_SYMBOL: R E Q U I R E; RESET_SYMBOL: R E S E T; RESIGNAL_SYMBOL: R E S I G N A L; // SQL-2003-R @@ -729,7 +729,7 @@ RIGHT_SYMBOL: R I G H T; // RLIKE_SYMBOL: R L I K E -> type(REGEXP_SYMBOL); // Synonym (like in mSQL2) ROLLBACK_SYMBOL: R O L L B A C K; // SQL-2003-R ROLLUP_SYMBOL: R O L L U P; // SQL-2003-R -ROTATE_SYMBOL: R O T A T E {serverVersion >= 50713}?; +ROTATE_SYMBOL: R O T A T E {self.server_version >= 50713}?; ROUTINE_SYMBOL: R O U T I N E; // SQL-2003-N ROWS_SYMBOL: R O W S; // SQL-2003-R ROW_COUNT_SYMBOL: R O W '_' C O U N T; @@ -753,7 +753,7 @@ SESSION_SYMBOL: S E S S I O N; // SERVER_SYMBOL: S E R V E R; SERVER_OPTIONS_SYMBOL: S E R V E R '_' O P T I O N S; SESSION_USER_SYMBOL: - S E S S I O N '_' U S E R { self.setType(determineFunction(USER_SYMBOL)); } + S E S S I O N '_' U S E R { self.setType(self.determineFunction(USER_SYMBOL)) } ; // Synonym SET_SYMBOL: S E T; // SQL-2003-R SET_VAR_SYMBOL: S E T '_' V A R; @@ -779,19 +779,19 @@ SQLSTATE_SYMBOL: S Q L S T A T E; // SQLWARNING_SYMBOL: S Q L W A R N I N G; // SQL-2003-R SQL_AFTER_GTIDS_SYMBOL: S Q L '_' A F T E R '_' G T I D S; // MYSQL SQL_AFTER_MTS_GAPS_SYMBOL: - S Q L '_' A F T E R '_' M T S '_' G A P S {serverVersion >= 50606}? + S Q L '_' A F T E R '_' M T S '_' G A P S {self.server_version >= 50606}? ; // MYSQL SQL_BEFORE_GTIDS_SYMBOL: S Q L '_' B E F O R E '_' G T I D S; // MYSQL SQL_BIG_RESULT_SYMBOL: S Q L '_' B I G '_' R E S U L T; SQL_BUFFER_RESULT_SYMBOL: S Q L '_' B U F F E R '_' R E S U L T; -SQL_CACHE_SYMBOL: S Q L '_' C A C H E {serverVersion < 80000}?; +SQL_CACHE_SYMBOL: S Q L '_' C A C H E {self.server_version < 80000}?; SQL_CALC_FOUND_ROWS_SYMBOL: S Q L '_' C A L C '_' F O U N D '_' R O W S; SQL_NO_CACHE_SYMBOL: S Q L '_' N O '_' C A C H E; SQL_SMALL_RESULT_SYMBOL: S Q L '_' S M A L L '_' R E S U L T; SQL_SYMBOL: S Q L; // SQL-2003-R SQL_THREAD_SYMBOL: S Q L '_' T H R E A D; SSL_SYMBOL: S S L; -STACKED_SYMBOL: S T A C K E D {serverVersion >= 50700}?; +STACKED_SYMBOL: S T A C K E D {self.server_version >= 50700}?; STARTING_SYMBOL: S T A R T I N G; STARTS_SYMBOL: S T A R T S; START_SYMBOL: S T A R T; // SQL-2003-R @@ -800,33 +800,33 @@ STATS_PERSISTENT_SYMBOL: S T A T S '_' P E R S I S T E N T; STATS_SAMPLE_PAGES_SYMBOL: S T A T S '_' S A M P L E '_' P A G E S; STATUS_SYMBOL: S T A T U S; STDDEV_SAMP_SYMBOL: - S T D D E V '_' S A M P { self.setType(determineFunction(STDDEV_SAMP_SYMBOL)); } + S T D D E V '_' S A M P { self.setType(self.determineFunction(self.STDDEV_SAMP_SYMBOL)) } ; // SQL-2003-N -STDDEV_SYMBOL: S T D D E V { self.setType(determineFunction(STD_SYMBOL)); }; // Synonym -STDDEV_POP_SYMBOL: S T D D E V '_' P O P { self.setType(determineFunction(STD_SYMBOL)); }; // Synonym -STD_SYMBOL: S T D { self.setType(determineFunction(STD_SYMBOL)); }; +STDDEV_SYMBOL: S T D D E V { self.setType(self.determineFunction(self.STD_SYMBOL)) }; // Synonym +STDDEV_POP_SYMBOL: S T D D E V '_' P O P { self.setType(self.determineFunction(self.STD_SYMBOL)) }; // Synonym +STD_SYMBOL: S T D { self.setType(self.determineFunction(self.STD_SYMBOL)) }; STOP_SYMBOL: S T O P; STORAGE_SYMBOL: S T O R A G E; -STORED_SYMBOL: S T O R E D {serverVersion >= 50707}?; +STORED_SYMBOL: S T O R E D {self.server_version >= 50707}?; STRAIGHT_JOIN_SYMBOL: S T R A I G H T '_' J O I N; STRING_SYMBOL: S T R I N G; SUBCLASS_ORIGIN_SYMBOL: S U B C L A S S '_' O R I G I N; // SQL-2003-N -SUBDATE_SYMBOL: S U B D A T E { self.setType(determineFunction(SUBDATE_SYMBOL)); }; +SUBDATE_SYMBOL: S U B D A T E { self.setType(self.determineFunction(self.SUBDATE_SYMBOL)) }; SUBJECT_SYMBOL: S U B J E C T; SUBPARTITIONS_SYMBOL: S U B P A R T I T I O N S; SUBPARTITION_SYMBOL: S U B P A R T I T I O N; -SUBSTR_SYMBOL: S U B S T R { self.setType(determineFunction(SUBSTRING_SYMBOL)); }; // Synonym -SUBSTRING_SYMBOL: S U B S T R I N G { self.setType(determineFunction(SUBSTRING_SYMBOL)); }; // SQL-2003-N -SUM_SYMBOL: S U M { self.setType(determineFunction(SUM_SYMBOL)); }; // SQL-2003-N +SUBSTR_SYMBOL: S U B S T R { self.setType(self.determineFunction(self.SUBSTRING_SYMBOL)) }; // Synonym +SUBSTRING_SYMBOL: S U B S T R I N G { self.setType(self.determineFunction(self.SUBSTRING_SYMBOL)) }; // SQL-2003-N +SUM_SYMBOL: S U M { self.setType(self.determineFunction(self.SUM_SYMBOL)) }; // SQL-2003-N SUPER_SYMBOL: S U P E R; SUSPEND_SYMBOL: S U S P E N D; SWAPS_SYMBOL: S W A P S; SWITCHES_SYMBOL: S W I T C H E S; -SYSDATE_SYMBOL: S Y S D A T E { self.setType(determineFunction(SYSDATE_SYMBOL)); }; -SYSTEM_USER_SYMBOL: S Y S T E M '_' U S E R { self.setType(determineFunction(USER_SYMBOL)); }; +SYSDATE_SYMBOL: S Y S D A T E { self.setType(self.determineFunction(self.SYSDATE_SYMBOL)) }; +SYSTEM_USER_SYMBOL: S Y S T E M '_' U S E R { self.setType(self.determineFunction(self.USER_SYMBOL)) }; TABLES_SYMBOL: T A B L E S; TABLESPACE_SYMBOL: T A B L E S P A C E; -TABLE_REF_PRIORITY_SYMBOL: T A B L E '_' R E F '_' P R I O R I T Y {serverVersion < 80000}?; +TABLE_REF_PRIORITY_SYMBOL: T A B L E '_' R E F '_' P R I O R I T Y {self.server_version < 80000}?; TABLE_SYMBOL: T A B L E; // SQL-2003-R TABLE_CHECKSUM_SYMBOL: T A B L E '_' C H E C K S U M; TABLE_NAME_SYMBOL: T A B L E '_' N A M E; // SQL-2003-N @@ -848,7 +848,7 @@ TRAILING_SYMBOL: T R A I L I N G; // TRANSACTION_SYMBOL: T R A N S A C T I O N; TRIGGERS_SYMBOL: T R I G G E R S; TRIGGER_SYMBOL: T R I G G E R; // SQL-2003-R -TRIM_SYMBOL: T R I M { self.setType(determineFunction(TRIM_SYMBOL)); }; // SQL-2003-N +TRIM_SYMBOL: T R I M { self.setType(self.determineFunction(self.TRIM_SYMBOL)) }; // SQL-2003-N TRUE_SYMBOL: T R U E; // SQL-2003-R TRUNCATE_SYMBOL: T R U N C A T E; TYPES_SYMBOL: T Y P E S; @@ -880,19 +880,19 @@ USING_SYMBOL: U S I N G; // UTC_DATE_SYMBOL: U T C '_' D A T E; UTC_TIMESTAMP_SYMBOL: U T C '_' T I M E S T A M P; UTC_TIME_SYMBOL: U T C '_' T I M E; -VALIDATION_SYMBOL: V A L I D A T I O N {serverVersion >= 50706}?; +VALIDATION_SYMBOL: V A L I D A T I O N {self.server_version >= 50706}?; VALUES_SYMBOL: V A L U E S; // SQL-2003-R VALUE_SYMBOL: V A L U E; // SQL-2003-R VARBINARY_SYMBOL: V A R B I N A R Y; // SQL-2008-R VARCHAR_SYMBOL: V A R C H A R; // SQL-2003-R VARCHARACTER_SYMBOL: V A R C H A R A C T E R -> type(VARCHAR_SYMBOL); // Synonym VARIABLES_SYMBOL: V A R I A B L E S; -VARIANCE_SYMBOL: V A R I A N C E { self.setType(determineFunction(VARIANCE_SYMBOL)); }; +VARIANCE_SYMBOL: V A R I A N C E { self.setType(self.determineFunction(self.VARIANCE_SYMBOL)) }; VARYING_SYMBOL: V A R Y I N G; // SQL-2003-R -VAR_POP_SYMBOL: V A R '_' P O P { self.setType(determineFunction(VARIANCE_SYMBOL)); }; // Synonym -VAR_SAMP_SYMBOL: V A R '_' S A M P { self.setType(determineFunction(VAR_SAMP_SYMBOL)); }; +VAR_POP_SYMBOL: V A R '_' P O P { self.setType(self.determineFunction(self.VARIANCE_SYMBOL)) }; // Synonym +VAR_SAMP_SYMBOL: V A R '_' S A M P { self.setType(self.determineFunction(self.VAR_SAMP_SYMBOL)) }; VIEW_SYMBOL: V I E W; // SQL-2003-N -VIRTUAL_SYMBOL: V I R T U A L {serverVersion >= 50707}?; +VIRTUAL_SYMBOL: V I R T U A L {self.server_version >= 50707}?; WAIT_SYMBOL: W A I T; WARNINGS_SYMBOL: W A R N I N G S; WEEK_SYMBOL: W E E K; @@ -907,7 +907,7 @@ WRAPPER_SYMBOL: W R A P P E R; WRITE_SYMBOL: W R I T E; // SQL-2003-N X509_SYMBOL: X '509'; XA_SYMBOL: X A; -XID_SYMBOL: X I D {serverVersion >= 50704}?; +XID_SYMBOL: X I D {self.server_version >= 50704}?; XML_SYMBOL: X M L; XOR_SYMBOL: X O R; YEAR_MONTH_SYMBOL: Y E A R '_' M O N T H; @@ -917,130 +917,130 @@ ZEROFILL_SYMBOL: Z E R O F I L L; // /* Tokens from MySQL 8.0 */ -PERSIST_SYMBOL: P E R S I S T {serverVersion >= 80000}?; -ROLE_SYMBOL: R O L E {serverVersion >= 80000}?; // SQL-1999-R -ADMIN_SYMBOL: A D M I N {serverVersion >= 80000}?; // SQL-1999-R -INVISIBLE_SYMBOL: I N V I S I B L E {serverVersion >= 80000}?; -VISIBLE_SYMBOL: V I S I B L E {serverVersion >= 80000}?; -EXCEPT_SYMBOL: E X C E P T {serverVersion >= 80000}?; // SQL-1999-R -COMPONENT_SYMBOL: C O M P O N E N T {serverVersion >= 80000}?; // MYSQL -RECURSIVE_SYMBOL: R E C U R S I V E {serverVersion >= 80000}?; // SQL-1999-R -JSON_OBJECTAGG_SYMBOL: J S O N '_' O B J E C T A G G {serverVersion >= 80000}?; // SQL-2015-R -JSON_ARRAYAGG_SYMBOL: J S O N '_' A R R A Y A G G {serverVersion >= 80000}?; // SQL-2015-R -OF_SYMBOL: O F {serverVersion >= 80000}?; // SQL-1999-R -SKIP_SYMBOL: S K I P {serverVersion >= 80000}?; // MYSQL -LOCKED_SYMBOL: L O C K E D {serverVersion >= 80000}?; // MYSQL -NOWAIT_SYMBOL: N O W A I T {serverVersion >= 80000}?; // MYSQL -GROUPING_SYMBOL: G R O U P I N G {serverVersion >= 80000}?; // SQL-2011-R -PERSIST_ONLY_SYMBOL: P E R S I S T '_' O N L Y {serverVersion >= 80000}?; // MYSQL -HISTOGRAM_SYMBOL: H I S T O G R A M {serverVersion >= 80000}?; // MYSQL -BUCKETS_SYMBOL: B U C K E T S {serverVersion >= 80000}?; // MYSQL -REMOTE_SYMBOL: R E M O T E {serverVersion >= 80003 and serverVersion < 80014}?; // MYSQL -CLONE_SYMBOL: C L O N E {serverVersion >= 80000}?; // MYSQL -CUME_DIST_SYMBOL: C U M E '_' D I S T {serverVersion >= 80000}?; // SQL-2003-R -DENSE_RANK_SYMBOL: D E N S E '_' R A N K {serverVersion >= 80000}?; // SQL-2003-R -EXCLUDE_SYMBOL: E X C L U D E {serverVersion >= 80000}?; // SQL-2003-N -FIRST_VALUE_SYMBOL: F I R S T '_' V A L U E {serverVersion >= 80000}?; // SQL-2011-R -FOLLOWING_SYMBOL: F O L L O W I N G {serverVersion >= 80000}?; // SQL-2003-N -GROUPS_SYMBOL: G R O U P S {serverVersion >= 80000}?; // SQL-2011-R -LAG_SYMBOL: L A G {serverVersion >= 80000}?; // SQL-2011-R -LAST_VALUE_SYMBOL: L A S T '_' V A L U E {serverVersion >= 80000}?; // SQL-2011-R -LEAD_SYMBOL: L E A D {serverVersion >= 80000}?; // SQL-2011-R -NTH_VALUE_SYMBOL: N T H '_' V A L U E {serverVersion >= 80000}?; // SQL-2011-R -NTILE_SYMBOL: N T I L E {serverVersion >= 80000}?; // SQL-2011-R -NULLS_SYMBOL: N U L L S {serverVersion >= 80000}?; // SQL-2003-N -OTHERS_SYMBOL: O T H E R S {serverVersion >= 80000}?; // SQL-2003-N -OVER_SYMBOL: O V E R {serverVersion >= 80000}?; // SQL-2003-R -PERCENT_RANK_SYMBOL: P E R C E N T '_' R A N K {serverVersion >= 80000}?; // SQL-2003-R -PRECEDING_SYMBOL: P R E C E D I N G {serverVersion >= 80000}?; // SQL-2003-N -RANK_SYMBOL: R A N K {serverVersion >= 80000}?; // SQL-2003-R -RESPECT_SYMBOL: R E S P E C T {serverVersion >= 80000}?; // SQL_2011-N -ROW_NUMBER_SYMBOL: R O W '_' N U M B E R {serverVersion >= 80000}?; // SQL-2003-R -TIES_SYMBOL: T I E S {serverVersion >= 80000}?; // SQL-2003-N -UNBOUNDED_SYMBOL: U N B O U N D E D {serverVersion >= 80000}?; // SQL-2003-N -WINDOW_SYMBOL: W I N D O W {serverVersion >= 80000}?; // SQL-2003-R -EMPTY_SYMBOL: E M P T Y {serverVersion >= 80000}?; // SQL-2016-R -JSON_TABLE_SYMBOL: J S O N '_' T A B L E {serverVersion >= 80000}?; // SQL-2016-R -NESTED_SYMBOL: N E S T E D {serverVersion >= 80000}?; // SQL-2016-N -ORDINALITY_SYMBOL: O R D I N A L I T Y {serverVersion >= 80000}?; // SQL-2003-N -PATH_SYMBOL: P A T H {serverVersion >= 80000}?; // SQL-2003-N -HISTORY_SYMBOL: H I S T O R Y {serverVersion >= 80000}?; // MYSQL -REUSE_SYMBOL: R E U S E {serverVersion >= 80000}?; // MYSQL -SRID_SYMBOL: S R I D {serverVersion >= 80000}?; // MYSQL -THREAD_PRIORITY_SYMBOL: T H R E A D '_' P R I O R I T Y {serverVersion >= 80000}?; // MYSQL -RESOURCE_SYMBOL: R E S O U R C E {serverVersion >= 80000}?; // MYSQL -SYSTEM_SYMBOL: S Y S T E M {serverVersion >= 80000}?; // SQL-2003-R -VCPU_SYMBOL: V C P U {serverVersion >= 80000}?; // MYSQL +PERSIST_SYMBOL: P E R S I S T {self.server_version >= 80000}?; +ROLE_SYMBOL: R O L E {self.server_version >= 80000}?; // SQL-1999-R +ADMIN_SYMBOL: A D M I N {self.server_version >= 80000}?; // SQL-1999-R +INVISIBLE_SYMBOL: I N V I S I B L E {self.server_version >= 80000}?; +VISIBLE_SYMBOL: V I S I B L E {self.server_version >= 80000}?; +EXCEPT_SYMBOL: E X C E P T {self.server_version >= 80000}?; // SQL-1999-R +COMPONENT_SYMBOL: C O M P O N E N T {self.server_version >= 80000}?; // MYSQL +RECURSIVE_SYMBOL: R E C U R S I V E {self.server_version >= 80000}?; // SQL-1999-R +JSON_OBJECTAGG_SYMBOL: J S O N '_' O B J E C T A G G {self.server_version >= 80000}?; // SQL-2015-R +JSON_ARRAYAGG_SYMBOL: J S O N '_' A R R A Y A G G {self.server_version >= 80000}?; // SQL-2015-R +OF_SYMBOL: O F {self.server_version >= 80000}?; // SQL-1999-R +SKIP_SYMBOL: S K I P {self.server_version >= 80000}?; // MYSQL +LOCKED_SYMBOL: L O C K E D {self.server_version >= 80000}?; // MYSQL +NOWAIT_SYMBOL: N O W A I T {self.server_version >= 80000}?; // MYSQL +GROUPING_SYMBOL: G R O U P I N G {self.server_version >= 80000}?; // SQL-2011-R +PERSIST_ONLY_SYMBOL: P E R S I S T '_' O N L Y {self.server_version >= 80000}?; // MYSQL +HISTOGRAM_SYMBOL: H I S T O G R A M {self.server_version >= 80000}?; // MYSQL +BUCKETS_SYMBOL: B U C K E T S {self.server_version >= 80000}?; // MYSQL +REMOTE_SYMBOL: R E M O T E {self.server_version >= 80003 and self.server_version < 80014}?; // MYSQL +CLONE_SYMBOL: C L O N E {self.server_version >= 80000}?; // MYSQL +CUME_DIST_SYMBOL: C U M E '_' D I S T {self.server_version >= 80000}?; // SQL-2003-R +DENSE_RANK_SYMBOL: D E N S E '_' R A N K {self.server_version >= 80000}?; // SQL-2003-R +EXCLUDE_SYMBOL: E X C L U D E {self.server_version >= 80000}?; // SQL-2003-N +FIRST_VALUE_SYMBOL: F I R S T '_' V A L U E {self.server_version >= 80000}?; // SQL-2011-R +FOLLOWING_SYMBOL: F O L L O W I N G {self.server_version >= 80000}?; // SQL-2003-N +GROUPS_SYMBOL: G R O U P S {self.server_version >= 80000}?; // SQL-2011-R +LAG_SYMBOL: L A G {self.server_version >= 80000}?; // SQL-2011-R +LAST_VALUE_SYMBOL: L A S T '_' V A L U E {self.server_version >= 80000}?; // SQL-2011-R +LEAD_SYMBOL: L E A D {self.server_version >= 80000}?; // SQL-2011-R +NTH_VALUE_SYMBOL: N T H '_' V A L U E {self.server_version >= 80000}?; // SQL-2011-R +NTILE_SYMBOL: N T I L E {self.server_version >= 80000}?; // SQL-2011-R +NULLS_SYMBOL: N U L L S {self.server_version >= 80000}?; // SQL-2003-N +OTHERS_SYMBOL: O T H E R S {self.server_version >= 80000}?; // SQL-2003-N +OVER_SYMBOL: O V E R {self.server_version >= 80000}?; // SQL-2003-R +PERCENT_RANK_SYMBOL: P E R C E N T '_' R A N K {self.server_version >= 80000}?; // SQL-2003-R +PRECEDING_SYMBOL: P R E C E D I N G {self.server_version >= 80000}?; // SQL-2003-N +RANK_SYMBOL: R A N K {self.server_version >= 80000}?; // SQL-2003-R +RESPECT_SYMBOL: R E S P E C T {self.server_version >= 80000}?; // SQL_2011-N +ROW_NUMBER_SYMBOL: R O W '_' N U M B E R {self.server_version >= 80000}?; // SQL-2003-R +TIES_SYMBOL: T I E S {self.server_version >= 80000}?; // SQL-2003-N +UNBOUNDED_SYMBOL: U N B O U N D E D {self.server_version >= 80000}?; // SQL-2003-N +WINDOW_SYMBOL: W I N D O W {self.server_version >= 80000}?; // SQL-2003-R +EMPTY_SYMBOL: E M P T Y {self.server_version >= 80000}?; // SQL-2016-R +JSON_TABLE_SYMBOL: J S O N '_' T A B L E {self.server_version >= 80000}?; // SQL-2016-R +NESTED_SYMBOL: N E S T E D {self.server_version >= 80000}?; // SQL-2016-N +ORDINALITY_SYMBOL: O R D I N A L I T Y {self.server_version >= 80000}?; // SQL-2003-N +PATH_SYMBOL: P A T H {self.server_version >= 80000}?; // SQL-2003-N +HISTORY_SYMBOL: H I S T O R Y {self.server_version >= 80000}?; // MYSQL +REUSE_SYMBOL: R E U S E {self.server_version >= 80000}?; // MYSQL +SRID_SYMBOL: S R I D {self.server_version >= 80000}?; // MYSQL +THREAD_PRIORITY_SYMBOL: T H R E A D '_' P R I O R I T Y {self.server_version >= 80000}?; // MYSQL +RESOURCE_SYMBOL: R E S O U R C E {self.server_version >= 80000}?; // MYSQL +SYSTEM_SYMBOL: S Y S T E M {self.server_version >= 80000}?; // SQL-2003-R +VCPU_SYMBOL: V C P U {self.server_version >= 80000}?; // MYSQL MASTER_PUBLIC_KEY_PATH_SYMBOL: - M A S T E R '_' P U B L I C '_' K E Y '_' P A T H {serverVersion >= 80000}? + M A S T E R '_' P U B L I C '_' K E Y '_' P A T H {self.server_version >= 80000}? ; // MYSQL GET_MASTER_PUBLIC_KEY_SYMBOL: - G E T '_' M A S T E R '_' P U B L I C '_' K E Y '_' S Y M {serverVersion >= 80000}? + G E T '_' M A S T E R '_' P U B L I C '_' K E Y '_' S Y M {self.server_version >= 80000}? ; // MYSQL -RESTART_SYMBOL: R E S T A R T {serverVersion >= 80011}?; // SQL-2003-N -DEFINITION_SYMBOL: D E F I N I T I O N {serverVersion >= 80011}?; // MYSQL -DESCRIPTION_SYMBOL: D E S C R I P T I O N {serverVersion >= 80011}?; // MYSQL -ORGANIZATION_SYMBOL: O R G A N I Z A T I O N {serverVersion >= 80011}?; // MYSQL -REFERENCE_SYMBOL: R E F E R E N C E {serverVersion >= 80011}?; // MYSQL - -OPTIONAL_SYMBOL: O P T I O N A L {serverVersion >= 80013}?; // MYSQL -SECONDARY_SYMBOL: S E C O N D A R Y {serverVersion >= 80013}?; // MYSQL -SECONDARY_ENGINE_SYMBOL: S E C O N D A R Y '_' E N G I N E {serverVersion >= 80013}?; // MYSQL -SECONDARY_LOAD_SYMBOL: S E C O N D A R Y '_' L O A D {serverVersion >= 80013}?; // MYSQL -SECONDARY_UNLOAD_SYMBOL: S E C O N D A R Y '_' U N L O A D {serverVersion >= 80013}?; // MYSQL - -ACTIVE_SYMBOL: A C T I V E {serverVersion >= 80014}?; // MYSQL -INACTIVE_SYMBOL: I N A C T I V E {serverVersion >= 80014}?; // MYSQL -LATERAL_SYMBOL: L A T E R A L {serverVersion >= 80014}?; // SQL-2003-R -RETAIN_SYMBOL: R E T A I N {serverVersion >= 80014}?; // MYSQL -OLD_SYMBOL: O L D {serverVersion >= 80014}?; // SQL-2003-R - -NETWORK_NAMESPACE_SYMBOL: N E T W O R K '_' N A M E S P A C E {serverVersion >= 80017}?; // MYSQL -ENFORCED_SYMBOL: E N F O R C E D {serverVersion >= 80017}?; // SQL-2003-N -ARRAY_SYMBOL: A R R A Y {serverVersion >= 80017}?; // SQL-2003-R -OJ_SYMBOL: O J {serverVersion >= 80017}?; // ODBC -MEMBER_SYMBOL: M E M B E R {serverVersion >= 80017}?; // SQL-2003-R - -RANDOM_SYMBOL: R A N D O M {serverVersion >= 80018}?; // MYSQL +RESTART_SYMBOL: R E S T A R T {self.server_version >= 80011}?; // SQL-2003-N +DEFINITION_SYMBOL: D E F I N I T I O N {self.server_version >= 80011}?; // MYSQL +DESCRIPTION_SYMBOL: D E S C R I P T I O N {self.server_version >= 80011}?; // MYSQL +ORGANIZATION_SYMBOL: O R G A N I Z A T I O N {self.server_version >= 80011}?; // MYSQL +REFERENCE_SYMBOL: R E F E R E N C E {self.server_version >= 80011}?; // MYSQL + +OPTIONAL_SYMBOL: O P T I O N A L {self.server_version >= 80013}?; // MYSQL +SECONDARY_SYMBOL: S E C O N D A R Y {self.server_version >= 80013}?; // MYSQL +SECONDARY_ENGINE_SYMBOL: S E C O N D A R Y '_' E N G I N E {self.server_version >= 80013}?; // MYSQL +SECONDARY_LOAD_SYMBOL: S E C O N D A R Y '_' L O A D {self.server_version >= 80013}?; // MYSQL +SECONDARY_UNLOAD_SYMBOL: S E C O N D A R Y '_' U N L O A D {self.server_version >= 80013}?; // MYSQL + +ACTIVE_SYMBOL: A C T I V E {self.server_version >= 80014}?; // MYSQL +INACTIVE_SYMBOL: I N A C T I V E {self.server_version >= 80014}?; // MYSQL +LATERAL_SYMBOL: L A T E R A L {self.server_version >= 80014}?; // SQL-2003-R +RETAIN_SYMBOL: R E T A I N {self.server_version >= 80014}?; // MYSQL +OLD_SYMBOL: O L D {self.server_version >= 80014}?; // SQL-2003-R + +NETWORK_NAMESPACE_SYMBOL: N E T W O R K '_' N A M E S P A C E {self.server_version >= 80017}?; // MYSQL +ENFORCED_SYMBOL: E N F O R C E D {self.server_version >= 80017}?; // SQL-2003-N +ARRAY_SYMBOL: A R R A Y {self.server_version >= 80017}?; // SQL-2003-R +OJ_SYMBOL: O J {self.server_version >= 80017}?; // ODBC +MEMBER_SYMBOL: M E M B E R {self.server_version >= 80017}?; // SQL-2003-R + +RANDOM_SYMBOL: R A N D O M {self.server_version >= 80018}?; // MYSQL MASTER_COMPRESSION_ALGORITHM_SYMBOL: - M A S T E R '_' C O M P R E S S I O N '_' A L G O R I T H M {serverVersion >= 80018}? + M A S T E R '_' C O M P R E S S I O N '_' A L G O R I T H M {self.server_version >= 80018}? ; // MYSQL MASTER_ZSTD_COMPRESSION_LEVEL_SYMBOL: - M A S T E R '_' Z S T D '_' C O M P R E S S I O N '_' L E V E L {serverVersion >= 80018}? + M A S T E R '_' Z S T D '_' C O M P R E S S I O N '_' L E V E L {self.server_version >= 80018}? ; // MYSQL PRIVILEGE_CHECKS_USER_SYMBOL: - P R I V I L E G E '_' C H E C K S '_' U S E R {serverVersion >= 80018}? + P R I V I L E G E '_' C H E C K S '_' U S E R {self.server_version >= 80018}? ; // MYSQL MASTER_TLS_CIPHERSUITES_SYMBOL: - M A S T E R '_' T L S '_' C I P H E R S U I T E S {serverVersion >= 80018}? + M A S T E R '_' T L S '_' C I P H E R S U I T E S {self.server_version >= 80018}? ; // MYSQL REQUIRE_ROW_FORMAT_SYMBOL: - R E Q U I R E '_' R O W '_' F O R M A T {serverVersion >= 80019}? + R E Q U I R E '_' R O W '_' F O R M A T {self.server_version >= 80019}? ; // MYSQL PASSWORD_LOCK_TIME_SYMBOL: - P A S S W O R D '_' L O C K '_' T I M E {serverVersion >= 80019}? + P A S S W O R D '_' L O C K '_' T I M E {self.server_version >= 80019}? ; // MYSQL FAILED_LOGIN_ATTEMPTS_SYMBOL: - F A I L E D '_' L O G I N '_' A T T E M P T S {serverVersion >= 80019}? + F A I L E D '_' L O G I N '_' A T T E M P T S {self.server_version >= 80019}? ; // MYSQL REQUIRE_TABLE_PRIMARY_KEY_CHECK_SYMBOL: - R E Q U I R E '_' T A B L E '_' P R I M A R Y '_' K E Y '_' C H E C K {serverVersion >= 80019}? + R E Q U I R E '_' T A B L E '_' P R I M A R Y '_' K E Y '_' C H E C K {self.server_version >= 80019}? ; // MYSQL -STREAM_SYMBOL: S T R E A M {serverVersion >= 80019}?; // MYSQL -OFF_SYMBOL: O F F {serverVersion >= 80019}?; // SQL-1999-R +STREAM_SYMBOL: S T R E A M {self.server_version >= 80019}?; // MYSQL +OFF_SYMBOL: O F F {self.server_version >= 80019}?; // SQL-1999-R // $antlr-format groupedAlignments on, alignTrailers off, alignLexerCommands on // Additional tokens which are mapped to existing tokens. -INT1_SYMBOL: I N T '1' -> type(TINYINT_SYMBOL); // Synonym -INT2_SYMBOL: I N T '2' -> type(SMALLINT_SYMBOL); // Synonym +INT1_SYMBOL: I N T '1' -> type(TINYINT_SYMBOL); // Synonym +INT2_SYMBOL: I N T '2' -> type(SMALLINT_SYMBOL); // Synonym INT3_SYMBOL: I N T '3' -> type(MEDIUMINT_SYMBOL); // Synonym INT4_SYMBOL: I N T '4' -> type(INT_SYMBOL); // Synonym INT8_SYMBOL: I N T '8' -> type(BIGINT_SYMBOL); // Synonym -SQL_TSI_SECOND_SYMBOL: S Q L '_' T S I '_' S E C O N D -> type(SECOND_SYMBOL); // Synonym -SQL_TSI_MINUTE_SYMBOL: S Q L '_' T S I '_' M I N U T E -> type(MINUTE_SYMBOL); // Synonym +SQL_TSI_SECOND_SYMBOL: S Q L '_' T S I '_' S E C O N D -> type(SECOND_SYMBOL); // Synonym +SQL_TSI_MINUTE_SYMBOL: S Q L '_' T S I '_' M I N U T E -> type(MINUTE_SYMBOL); // Synonym SQL_TSI_HOUR_SYMBOL: S Q L '_' T S I '_' H O U R -> type(HOUR_SYMBOL); // Synonym SQL_TSI_DAY_SYMBOL: S Q L '_' T S I '_' D A Y -> type(DAY_SYMBOL); // Synonym SQL_TSI_WEEK_SYMBOL: S Q L '_' T S I '_' W E E K -> type(WEEK_SYMBOL); // Synonym @@ -1065,7 +1065,7 @@ INVALID_INPUT: // The underscore charset token is used to defined the repertoire of a string, though it conflicts // with normal identifiers, which also can start with an underscore. -UNDERSCORE_CHARSET: UNDERLINE_SYMBOL [a-z0-9]+ { self.setType(checkCharset(self.getText())); }; +UNDERSCORE_CHARSET: UNDERLINE_SYMBOL [a-z0-9]+ { self.setType(self.checkCharset(self.getText())) }; // Identifiers might start with a digit, even though it is discouraged, and may not consist entirely of digits only. // All keywords above are automatically excluded. @@ -1106,15 +1106,15 @@ SINGLE_QUOTED_TEXT: ( // /*!12345 ... */ - Same as the previous one except code is only used when the given number is lower // than the current server version (specifying so the minimum server version the code can run with). VERSION_COMMENT_START: ('/*!' DIGITS) ( - {checkVersion(self.getText())}? // Will set inVersionComment if the number matches. + {self.checkVersion(self.getText())}? // Will set inVersionComment if the number matches. | .*? '*/' ) -> channel(HIDDEN) ; // inVersionComment is a variable in the base lexer. // TODO: use a lexer mode instead of a member variable. -MYSQL_COMMENT_START: '/*!' { inVersionComment = true; } -> channel(HIDDEN); -VERSION_COMMENT_END: '*/' {inVersionComment}? { inVersionComment = false; } -> channel(HIDDEN); +MYSQL_COMMENT_START: '/*!' { self.inVersionComment = True; } -> channel(HIDDEN); +VERSION_COMMENT_END: '*/' {self.inVersionComment}? { self.inVersionComment = False; } -> channel(HIDDEN); BLOCK_COMMENT: ( '/**/' | '/*' ~[!] .*? '*/') -> channel(HIDDEN); POUND_COMMENT: '#' ~([\n\r])* -> channel(HIDDEN); diff --git a/test.py b/test.py deleted file mode 100644 index 8bda92a..0000000 --- a/test.py +++ /dev/null @@ -1,36 +0,0 @@ -import sys -import antlr4 - -from grammar import MySQLLexer -#from grammar import MySQLParser -from grammar import MySQLLexer - - -LEXER_VALID_STATEMENTS = [ - 'select 1 from foo', - - ('\n' - 'select p.id,\n' - ' p.name,\n' - ' c.desc ContactDesc,\n' - ' a.desc AddressDesc\n' - 'from profile p\n' - 'inner join contact c\n' - ' on p.id = c.profileid\n' - 'inner join address a\n' - ' on p.id = a.profileid\n' - 'where p.name = \'bla\'\n' - ' and c.ord = 1\n' - ' and a.ord = 1\n'), -] - - -def test_lexer(): - for stmt in LEXER_VALID_STATEMENTS: - print(f"\n============\nStatement: {stmt}\n") - for tok in MySQLLexer(antlr4.InputStream(stmt)).getAllTokens(): - print(f'{tok.text}\t: {MySQLLexer.symbolicNames[tok.type]}') - - -if __name__ == '__main__': - test_lexer()