You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/08/10 23:49:49 UTC

groovy git commit: Refine parsing number

Repository: groovy
Updated Branches:
  refs/heads/master c11ab0708 -> 473bd1a65


Refine parsing number


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/473bd1a6
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/473bd1a6
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/473bd1a6

Branch: refs/heads/master
Commit: 473bd1a6524781229a93c9233a622d7a1bec96de
Parents: c11ab07
Author: sunlan <su...@apache.org>
Authored: Fri Aug 11 07:49:41 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Fri Aug 11 07:49:41 2017 +0800

----------------------------------------------------------------------
 .../org/apache/groovy/parser/antlr4/AstBuilder.java  | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/473bd1a6/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index af3dcb9..9ae615e 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -2505,19 +2505,26 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
             }
             case SUB: {
                 if (expression instanceof ConstantExpression && !insidePar) {
-                    this.numberFormatError = null; // reset the numberFormatError, try to parse the negative number
-
                     ConstantExpression constantExpression = (ConstantExpression) expression;
 
                     try {
                         String integerLiteralText = constantExpression.getNodeMetaData(INTEGER_LITERAL_TEXT);
                         if (null != integerLiteralText) {
-                            return this.configureAST(new ConstantExpression(Numbers.parseInteger(null, SUB_STR + integerLiteralText)), ctx);
+
+                            ConstantExpression result = new ConstantExpression(Numbers.parseInteger(null, SUB_STR + integerLiteralText));
+
+                            this.numberFormatError = null; // reset the numberFormatError
+
+                            return this.configureAST(result, ctx);
                         }
 
                         String floatingPointLiteralText = constantExpression.getNodeMetaData(FLOATING_POINT_LITERAL_TEXT);
                         if (null != floatingPointLiteralText) {
-                            return this.configureAST(new ConstantExpression(Numbers.parseDecimal(SUB_STR + floatingPointLiteralText)), ctx);
+                            ConstantExpression result = new ConstantExpression(Numbers.parseDecimal(SUB_STR + floatingPointLiteralText));
+
+                            this.numberFormatError = null; // reset the numberFormatError
+
+                            return this.configureAST(result, ctx);
                         }
                     } catch (Exception e) {
                         throw createParsingFailedException(e.getMessage(), ctx);