groovy git commit: Refine parsing number

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

groovy git commit: Refine parsing number

sunlan
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X dc096a724 -> 3c100f78b


Refine parsing number

(cherry picked from commit 473bd1a)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 3c100f78b363e9a11933a25c8d6cfecbea4aaa28
Parents: dc096a7
Author: sunlan <[hidden email]>
Authored: Fri Aug 11 07:49:41 2017 +0800
Committer: sunlan <[hidden email]>
Committed: Fri Aug 11 07:50:35 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/3c100f78/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 4556a51..67ca907 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
@@ -2533,19 +2533,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);

Loading...