groovy git commit: Validate number format

2017-08-06 Thread sunlan
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X baa108488 -> 393262330


Validate number format

(cherry picked from commit 1edfb97)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 3932623300fb0ba1eb88f191bdfcd0a44af42ef1
Parents: baa1084
Author: sunlan 
Authored: Sun Aug 6 23:32:30 2017 +0800
Committer: sunlan 
Committed: Sun Aug 6 23:32:30 2017 +0800

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


http://git-wip-us.apache.org/repos/asf/groovy/blob/39326233/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 bbf7665..520e581 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
@@ -3145,7 +3145,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor implements Groov
 try {
 num = Numbers.parseInteger(null, text);
 } catch (Exception e) {
-this.numberFormatError = new Pair<>(ctx, e);
+this.numberFormatError = new Pair(ctx, e);
 }
 
 ConstantExpression constantExpression = new ConstantExpression(num, 
!text.startsWith(SUB_STR));
@@ -3163,7 +3163,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor implements Groov
 try {
 num = Numbers.parseDecimal(text);
 } catch (Exception e) {
-this.numberFormatError = new Pair<>(ctx, e);
+this.numberFormatError = new Pair(ctx, e);
 }
 
 ConstantExpression constantExpression = new ConstantExpression(num, 
!text.startsWith(SUB_STR));



groovy git commit: Validate number format

2017-08-06 Thread sunlan
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X e5d950c10 -> baa108488


Validate number format

(cherry picked from commit 1edfb97)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: baa108488e2687356692eaddd4282afa2fe6de13
Parents: e5d950c
Author: sunlan 
Authored: Sun Aug 6 23:04:36 2017 +0800
Committer: sunlan 
Committed: Sun Aug 6 23:11:13 2017 +0800

--
 .../apache/groovy/parser/antlr4/AstBuilder.java | 45 
 .../parser/antlr4/GroovyParserTest.groovy   |  4 ++
 .../groovy/parser/antlr4/SyntaxErrorTest.groovy |  5 +++
 .../src/test/resources/core/Number_01x.groovy   | 24 +++
 .../src/test/resources/fail/Number_01x.groovy   | 19 +
 .../src/test/resources/fail/Number_02x.groovy   | 19 +
 6 files changed, 107 insertions(+), 9 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/groovy/blob/baa10848/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 5c5f966..bbf7665 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
@@ -253,6 +253,10 @@ public class AstBuilder extends 
GroovyParserBaseVisitor implements Groov
 
 this.configureScriptClassNode();
 
+if (null != this.numberFormatError) {
+throw 
createParsingFailedException(this.numberFormatError.value.getMessage(), 
this.numberFormatError.key);
+}
+
 return moduleNode;
 }
 
@@ -2523,16 +2527,22 @@ public class AstBuilder extends 
GroovyParserBaseVisitor 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;
 
-String integerLiteralText = 
constantExpression.getNodeMetaData(INTEGER_LITERAL_TEXT);
-if (null != integerLiteralText) {
-return this.configureAST(new 
ConstantExpression(Numbers.parseInteger(null, SUB_STR + integerLiteralText)), 
ctx);
-}
+try {
+String integerLiteralText = 
constantExpression.getNodeMetaData(INTEGER_LITERAL_TEXT);
+if (null != integerLiteralText) {
+return this.configureAST(new 
ConstantExpression(Numbers.parseInteger(null, SUB_STR + integerLiteralText)), 
ctx);
+}
 
-String floatingPointLiteralText = 
constantExpression.getNodeMetaData(FLOATING_POINT_LITERAL_TEXT);
-if (null != floatingPointLiteralText) {
-return this.configureAST(new 
ConstantExpression(Numbers.parseDecimal(SUB_STR + floatingPointLiteralText)), 
ctx);
+String floatingPointLiteralText = 
constantExpression.getNodeMetaData(FLOATING_POINT_LITERAL_TEXT);
+if (null != floatingPointLiteralText) {
+return this.configureAST(new 
ConstantExpression(Numbers.parseDecimal(SUB_STR + floatingPointLiteralText)), 
ctx);
+}
+} catch (Exception e) {
+throw createParsingFailedException(e.getMessage(), 
ctx);
 }
 
 throw new GroovyBugError("Failed to find the original 
number literal text: " + constantExpression.getText());
@@ -3131,7 +3141,14 @@ public class AstBuilder extends 
GroovyParserBaseVisitor implements Groov
 public ConstantExpression visitIntegerLiteralAlt(IntegerLiteralAltContext 
ctx) {
 String text = ctx.IntegerLiteral().getText();
 
-ConstantExpression constantExpression = new 
ConstantExpression(Numbers.parseInteger(null, text), !text.startsWith(SUB_STR));
+Number num = null;
+try {
+num = Numbers.parseInteger(null, text);
+} catch (Exception e) {
+this.numberFormatError = new Pair<>(ctx, e);
+}
+
+ConstantExpression constantExpression = new ConstantExpression(num, 

groovy git commit: Validate number format

2017-08-06 Thread sunlan
Repository: groovy
Updated Branches:
  refs/heads/master cc91ef3e0 -> 1edfb974d


Validate number format


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

Branch: refs/heads/master
Commit: 1edfb974dec232be1000629943d3437e7ce2f214
Parents: cc91ef3
Author: sunlan 
Authored: Sun Aug 6 23:04:36 2017 +0800
Committer: sunlan 
Committed: Sun Aug 6 23:04:36 2017 +0800

--
 .../apache/groovy/parser/antlr4/AstBuilder.java | 45 
 .../parser/antlr4/GroovyParserTest.groovy   |  4 ++
 .../groovy/parser/antlr4/SyntaxErrorTest.groovy |  5 +++
 .../src/test/resources/core/Number_01x.groovy   | 24 +++
 .../src/test/resources/fail/Number_01x.groovy   | 19 +
 .../src/test/resources/fail/Number_02x.groovy   | 19 +
 6 files changed, 107 insertions(+), 9 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/groovy/blob/1edfb974/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 d3773f6..f980110 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
@@ -255,6 +255,10 @@ public class AstBuilder extends 
GroovyParserBaseVisitor implements Groov
 
 this.configureScriptClassNode();
 
+if (null != this.numberFormatError) {
+throw 
createParsingFailedException(this.numberFormatError.value.getMessage(), 
this.numberFormatError.key);
+}
+
 return moduleNode;
 }
 
@@ -2495,16 +2499,22 @@ public class AstBuilder extends 
GroovyParserBaseVisitor 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;
 
-String integerLiteralText = 
constantExpression.getNodeMetaData(INTEGER_LITERAL_TEXT);
-if (null != integerLiteralText) {
-return this.configureAST(new 
ConstantExpression(Numbers.parseInteger(null, SUB_STR + integerLiteralText)), 
ctx);
-}
+try {
+String integerLiteralText = 
constantExpression.getNodeMetaData(INTEGER_LITERAL_TEXT);
+if (null != integerLiteralText) {
+return this.configureAST(new 
ConstantExpression(Numbers.parseInteger(null, SUB_STR + integerLiteralText)), 
ctx);
+}
 
-String floatingPointLiteralText = 
constantExpression.getNodeMetaData(FLOATING_POINT_LITERAL_TEXT);
-if (null != floatingPointLiteralText) {
-return this.configureAST(new 
ConstantExpression(Numbers.parseDecimal(SUB_STR + floatingPointLiteralText)), 
ctx);
+String floatingPointLiteralText = 
constantExpression.getNodeMetaData(FLOATING_POINT_LITERAL_TEXT);
+if (null != floatingPointLiteralText) {
+return this.configureAST(new 
ConstantExpression(Numbers.parseDecimal(SUB_STR + floatingPointLiteralText)), 
ctx);
+}
+} catch (Exception e) {
+throw createParsingFailedException(e.getMessage(), 
ctx);
 }
 
 throw new GroovyBugError("Failed to find the original 
number literal text: " + constantExpression.getText());
@@ -3089,7 +3099,14 @@ public class AstBuilder extends 
GroovyParserBaseVisitor implements Groov
 public ConstantExpression visitIntegerLiteralAlt(IntegerLiteralAltContext 
ctx) {
 String text = ctx.IntegerLiteral().getText();
 
-ConstantExpression constantExpression = new 
ConstantExpression(Numbers.parseInteger(null, text), !text.startsWith(SUB_STR));
+Number num = null;
+try {
+num = Numbers.parseInteger(null, text);
+} catch (Exception e) {
+this.numberFormatError = new Pair<>(ctx, e);
+}
+
+ConstantExpression constantExpression = new ConstantExpression(num, 
!text.startsWith(SUB_STR));