Unverified Commit dbf83e8d authored by 张亮's avatar 张亮 Committed by GitHub
Browse files

Merge pull request #2254 from tristaZero/dev

Review literals parsing g4 file 
parents 4f9632aa 35c25ed7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -78,11 +78,11 @@ public final class ExpressionExtractor implements OptionalSQLSegmentExtractor {
        if (bitExprNode.isPresent() && 1 != bitExprNode.get().getChildCount()) {
            return result;
        }
        Optional<ParserRuleContext> numberNode = ExtractorUtils.findFirstChildNode(expressionNode, RuleName.NUMBER);
        Optional<ParserRuleContext> numberNode = ExtractorUtils.findFirstChildNode(expressionNode, RuleName.NUMBER_LITERALS);
        if (numberNode.isPresent()) {
            result.setLiterals(NumberUtil.getExactlyNumber(numberNode.get().getText(), 10));
        }
        Optional<ParserRuleContext> stringNode = ExtractorUtils.findFirstChildNode(expressionNode, RuleName.STRING);
        Optional<ParserRuleContext> stringNode = ExtractorUtils.findFirstChildNode(expressionNode, RuleName.STRING_LITERALS);
        if (stringNode.isPresent()) {
            String text = stringNode.get().getText();
            result.setLiterals(text.substring(1, text.length() - 1));
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public final class OrderByItemExtractor implements CollectionSQLSegmentExtractor
        Collection<OrderByItemSegment> result = new LinkedList<>();
        for (ParserRuleContext each : ExtractorUtils.getAllDescendantNodes(ancestorNode, RuleName.ORDER_BY_ITEM)) {
            OrderDirection orderDirection = 2 == each.getChildCount() && OrderDirection.DESC.name().equalsIgnoreCase(each.getChild(1).getText()) ? OrderDirection.DESC : OrderDirection.ASC;
            Optional<ParserRuleContext> indexNode = ExtractorUtils.findFirstChildNode(each, RuleName.NUMBER);
            Optional<ParserRuleContext> indexNode = ExtractorUtils.findFirstChildNode(each, RuleName.NUMBER_LITERALS);
            if (indexNode.isPresent()) {
                result.add(new IndexOrderByItemSegment(NumberUtil.getExactlyNumber(indexNode.get().getText(), 10).intValue(), orderDirection, OrderDirection.ASC));
                continue;
+2 −2
Original line number Diff line number Diff line
@@ -109,9 +109,9 @@ public enum RuleName {
    
    PARAMETER_MARKER("ParameterMarker"),
    
    NUMBER("Number"),
    NUMBER_LITERALS("NumberLiterals"),
    
    STRING("String"),
    STRING_LITERALS("StringLiterals"),
    
    EXPR("Expr"),
    
+42 −17
Original line number Diff line number Diff line
@@ -23,26 +23,51 @@ parameterMarker
    : QUESTION_
    ;

number
   : NUMBER_
literals
    : stringLiterals
    | numberLiterals
    | dateTimeLiterals
    | hexadecimalLiterals
    | bitValueLiterals
    | booleanLiterals
    | nullValueLiterals
    ;

stringLiterals
    : characterSetName_? STRING_ collateName_?
    ;

string
    : STRING_
numberLiterals
   : NUMBER_
   ;

literals_
    : number
    | string
    | TRUE
    | FALSE
    | NULL
    | BIT_NUM_
    | HEX_DIGIT_
    | (DATE | TIME | TIMESTAMP) STRING_
dateTimeLiterals
    : (DATE | TIME | TIMESTAMP) STRING_
    | LBE_ identifier_ STRING_ RBE_
    | IDENTIFIER_ STRING_ COLLATE (STRING_ | IDENTIFIER_)?
    | characterSet_? BIT_NUM_ collateClause_?
    ;

hexadecimalLiterals
    : characterSetName_? HEX_DIGIT_ collateName_?
    ;

bitValueLiterals
    : characterSetName_? BIT_NUM_ collateName_?
    ;
    
booleanLiterals
    : TRUE | FALSE
    ;

nullValueLiterals
    : NULL
    ;

characterSetName_
    : IDENTIFIER_
    ;

collateName_
    : IDENTIFIER_
    ;

identifier_
@@ -153,7 +178,7 @@ bitExpr
simpleExpr
    : functionCall
    | parameterMarker
    | literals_
    | literals
    | columnName
    | simpleExpr COLLATE (STRING_ | identifier_)
    | variable_
@@ -314,7 +339,7 @@ orderByClause
    ;

orderByItem
    : (columnName | number | expr) (ASC | DESC)?
    : (columnName | numberLiterals | expr) (ASC | DESC)?
    ;

dataType
+3 −3
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ columnDefinition
inlineDataType_
    : commonDataTypeOption_
    | AUTO_INCREMENT
    | DEFAULT (literals_ | expr)
    | DEFAULT (literals | expr)
    | COLUMN_FORMAT (FIXED | DYNAMIC | DEFAULT)
    | STORAGE (DISK | MEMORY | DEFAULT)
    ;
@@ -126,7 +126,7 @@ alterSpecification_
    | DROP CHECK ignoredIdentifier_
    | ALTER CHECK ignoredIdentifier_ NOT? ENFORCED
    | ALGORITHM EQ_? (DEFAULT | INSTANT | INPLACE | COPY)
    | ALTER COLUMN? columnName (SET DEFAULT literals_ | DROP DEFAULT)
    | ALTER COLUMN? columnName (SET DEFAULT literals | DROP DEFAULT)
    | ALTER INDEX indexName (VISIBLE | INVISIBLE)
    | changeColumnSpecification
    | DEFAULT? characterSet_ collateClause_?
@@ -264,7 +264,7 @@ partitionLessThanValue_
    ;

partitionValueList_
    : literals_ (COMMA_ literals_)*
    : literals (COMMA_ literals)*
    ;

partitionDefinitionOption_
Loading