modify grammar, add syntax test

This commit is contained in:
xigua
2020-11-05 20:37:07 +08:00
parent bfe055be71
commit 0d47b7debc
12 changed files with 40947 additions and 83 deletions

View File

@ -17,66 +17,62 @@
grammar SqlBase;
@parser::members {
/**
* When false, INTERSECT is given the greater precedence over the other set
* operations (UNION, EXCEPT and MINUS) as per the SQL standard.
*/
// public boolean legacy_setops_precedence_enbled = false;
legacy_setops_precedence_enbled = false;
/**
* When false, a literal with an exponent would be converted into
* double type rather than decimal type.
*/
// public boolean legacy_exponent_literal_as_decimal_enabled = false;
legacy_exponent_literal_as_decimal_enabled = false;
/**
* When true, the behavior of keywords follows ANSI SQL standard.
*/
// public boolean SQL_standard_keyword_behavior = false;
SQL_standard_keyword_behavior = false;
/**
* When false, INTERSECT is given the greater precedence over the other set
* operations (UNION, EXCEPT and MINUS) as per the SQL standard.
*/
// public boolean legacy_setops_precedence_enbled = false;
/**
* When false, a literal with an exponent would be converted into
* double type rather than decimal type.
*/
// public boolean legacy_exponent_literal_as_decimal_enabled = false;
global.legacy_exponent_literal_as_decimal_enabled = false;
/**
* When true, the behavior of keywords follows ANSI SQL standard.
*/
// public boolean SQL_standard_keyword_behavior = false;
global.legacy_setops_precedence_enbled = false;
global.legacy_exponent_literal_as_decimal_enabled = false;
global.SQL_standard_keyword_behavior = false;
}
//@lexer::members {
// /**
// * Verify whether current token is a valid decimal token (which contains dot).
// * Returns true if the character that follows the token is not a digit or letter or underscore.
// *
// * For example:
// * For char stream "2.3", "2." is not a valid decimal token, because it is followed by digit '3'.
// * For char stream "2.3_", "2.3" is not a valid decimal token, because it is followed by '_'.
// * For char stream "2.3W", "2.3" is not a valid decimal token, because it is followed by 'W'.
// * For char stream "12.0D 34.E2+0.12 " 12.0D is a valid decimal token because it is followed
// * by a space. 34.E2 is a valid decimal token because it is followed by symbol '+'
// * which is not a digit or letter or underscore.
// */
// public boolean isValidDecimal() {
// int nextChar = _input.LA(1);
// if (nextChar >= 'A' && nextChar <= 'Z' || nextChar >= '0' && nextChar <= '9' ||
// nextChar == '_') {
// return false;
// } else {
// return true;
// }
// }
//
// /**
// * This method will be called when we see '/*' and try to match it as a bracketed comment.
// * If the next character is '+', it should be parsed as hint later, and we cannot match
// * it as a bracketed comment.
// *
// * Returns true if the next character is '+'.
// */
// public boolean isHint() {
// int nextChar = _input.LA(1);
// if (nextChar == '+') {
// return true;
// } else {
// return false;
// }
// }
//}
@lexer::members {
var ctx = this
/**
* Verify whether current token is a valid decimal token (which contains dot).
* Returns true if the character that follows the token is not a digit or letter or underscore.
*
* For example:
* For char stream "2.3", "2." is not a valid decimal token, because it is followed by digit '3'.
* For char stream "2.3_", "2.3" is not a valid decimal token, because it is followed by '_'.
* For char stream "2.3W", "2.3" is not a valid decimal token, because it is followed by 'W'.
* For char stream "12.0D 34.E2+0.12 " 12.0D is a valid decimal token because it is followed
* by a space. 34.E2 is a valid decimal token because it is followed by symbol '+'
* which is not a digit or letter or underscore.
*/
global.isValidDecimal = function() {
let nextChar = ctx._input.LA(1);
return !(nextChar >= 'A' && nextChar <= 'Z' || nextChar >= '0' && nextChar <= '9' || nextChar == '_')
}
program: statement EOF;
/**
* This method will be called when we see '/*' and try to match it as a bracketed comment.
* If the next character is '+', it should be parsed as hint later, and we cannot match
* it as a bracketed comment.
*
* Returns true if the next character is '+'.
*/
global.isHint = function() {
let nextChar = ctx._input.LA(1);
return nextChar == '+'
}
}
program
: singleStatement EOF
;
singleStatement
: statement ';'* EOF