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 2018/02/25 12:01:32 UTC
[1/3] groovy git commit: Support command expression in parentheses
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_6_X d00b01834 -> 9a33a4118
Support command expression in parentheses
(cherry picked from commit ddd15c4)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/1e688d33
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/1e688d33
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/1e688d33
Branch: refs/heads/GROOVY_2_6_X
Commit: 1e688d33a8a0949c94a75583d479a70bf7abcc1e
Parents: d00b018
Author: danielsun1106 <re...@hotmail.com>
Authored: Sun Feb 25 17:44:02 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Sun Feb 25 20:01:02 2018 +0800
----------------------------------------------------------------------
src/antlr/GroovyParser.g4 | 4 +++-
.../java/org/apache/groovy/parser/antlr4/AstBuilder.java | 8 ++++----
.../org/apache/groovy/parser/antlr4/GroovyParserTest.groovy | 2 +-
3 files changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/1e688d33/src/antlr/GroovyParser.g4
----------------------------------------------------------------------
diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index 053dbb8..7514ba2 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -781,7 +781,7 @@ parExpression
;
expressionInPar
- : LPAREN enhancedExpression rparen
+ : LPAREN enhancedStatementExpression rparen
;
expressionList[boolean canSpread]
@@ -909,10 +909,12 @@ expression
enhancedStatementExpression #assignmentExprAlt
;
+/*
enhancedExpression
: expression
| standardLambdaExpression
;
+*/
commandExpression
: pathExpression
http://git-wip-us.apache.org/repos/asf/groovy/blob/1e688d33/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 464c1ea..f56449c 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
@@ -199,7 +199,6 @@ import static org.apache.groovy.parser.antlr4.GroovyLangParser.ElementValuePairs
import static org.apache.groovy.parser.antlr4.GroovyLangParser.ElementValuesContext;
import static org.apache.groovy.parser.antlr4.GroovyLangParser.EnhancedArgumentListContext;
import static org.apache.groovy.parser.antlr4.GroovyLangParser.EnhancedArgumentListElementContext;
-import static org.apache.groovy.parser.antlr4.GroovyLangParser.EnhancedExpressionContext;
import static org.apache.groovy.parser.antlr4.GroovyLangParser.EnhancedForControlContext;
import static org.apache.groovy.parser.antlr4.GroovyLangParser.EnhancedStatementExpressionContext;
import static org.apache.groovy.parser.antlr4.GroovyLangParser.EnumConstantContext;
@@ -2097,6 +2096,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return configureAST(new ExpressionStatement((Expression) this.visit(ctx.expression())), ctx);
}
+/*
@Override
public Expression visitEnhancedExpression(EnhancedExpressionContext ctx) {
Expression expression;
@@ -2111,7 +2111,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return configureAST(expression, ctx);
}
-
+*/
@Override
public ExpressionStatement visitCommandExprAlt(CommandExprAltContext ctx) {
@@ -2237,7 +2237,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
@Override
public Expression visitExpressionInPar(ExpressionInParContext ctx) {
- return this.visitEnhancedExpression(ctx.enhancedExpression());
+ //return this.visitEnhancedExpression(ctx.enhancedExpression());
+ return this.visitEnhancedStatementExpression(ctx.enhancedStatementExpression());
}
@Override
@@ -3419,7 +3420,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return configureAST(new VariableExpression(text), ctx);
}
-
@Override
public ListExpression visitList(ListContext ctx) {
if (asBoolean(ctx.COMMA()) && !asBoolean(ctx.expressionList())) {
http://git-wip-us.apache.org/repos/asf/groovy/blob/1e688d33/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
index d43fbe0..769d378 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
@@ -342,7 +342,7 @@ class GroovyParserTest extends GroovyTestCase {
doTest('core/Command_03.groovy', [ExpressionStatement, Parameter])
doTest('core/Command_04.groovy', [ExpressionStatement])
doTest('core/Command_05.groovy')
-// doRunAndTest('core/Command_06x.groovy')
+ doRunAndTest('core/Command_06x.groovy')
}
/*
[3/3] groovy git commit: Refine "Support command expression in
parentheses"
Posted by su...@apache.org.
Refine "Support command expression in parentheses"
(cherry picked from commit cf2483d)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/9a33a411
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/9a33a411
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/9a33a411
Branch: refs/heads/GROOVY_2_6_X
Commit: 9a33a41187fafe804ef37ab29c9c8a49eae139b7
Parents: 93c4e38
Author: danielsun1106 <re...@hotmail.com>
Authored: Sun Feb 25 19:31:38 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Sun Feb 25 20:01:13 2018 +0800
----------------------------------------------------------------------
.../gls/syntax/MethodCallValidationTest.groovy | 2 --
.../apache/groovy/parser/antlr4/AstBuilder.java | 18 ++++++++++++++++++
.../groovy/parser/antlr4/SyntaxErrorTest.groovy | 3 +++
.../resources/fail/MethodDeclaration_04x.groovy | 19 +++++++++++++++++++
.../resources/fail/MethodDeclaration_05x.groovy | 19 +++++++++++++++++++
5 files changed, 59 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/9a33a411/src/test/gls/syntax/MethodCallValidationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/syntax/MethodCallValidationTest.groovy b/src/test/gls/syntax/MethodCallValidationTest.groovy
index 670b097..9fe6d52 100644
--- a/src/test/gls/syntax/MethodCallValidationTest.groovy
+++ b/src/test/gls/syntax/MethodCallValidationTest.groovy
@@ -21,8 +21,6 @@ package gls.syntax
public class MethodCallValidationTest extends gls.CompilableTestSupport {
void testDeclarationInMethodCall() {
- if (true) return; // skip for the time being
-
shouldNotCompile """
foo(String a)
"""
http://git-wip-us.apache.org/repos/asf/groovy/blob/9a33a411/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 f56449c..5be23c5 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
@@ -2152,6 +2152,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
methodCallExpression = configureAST(this.createCallMethodCallExpression(baseExpr, arguments), arguments);
}
+ methodCallExpression.putNodeMetaData(IS_COMMAND_EXPRESSION, true);
+
if (!asBoolean(ctx.commandArgument())) {
return configureAST(methodCallExpression, ctx);
}
@@ -3458,6 +3460,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
public Expression visitExpressionListElement(ExpressionListElementContext ctx) {
Expression expression = (Expression) this.visit(ctx.expression());
+ validateExpressionListElement(ctx, expression);
+
if (asBoolean(ctx.MUL())) {
return configureAST(new SpreadExpression(expression), ctx);
}
@@ -3465,6 +3469,19 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return configureAST(expression, ctx);
}
+ private void validateExpressionListElement(ExpressionListElementContext ctx, Expression expression) {
+ if (!(expression instanceof MethodCallExpression && isTrue(expression, IS_COMMAND_EXPRESSION))) {
+ return;
+ }
+
+ // statements like `foo(String a)` is invalid
+ MethodCallExpression methodCallExpression = (MethodCallExpression) expression;
+ String methodName = methodCallExpression.getMethodAsString();
+ if (Character.isUpperCase(methodName.codePointAt(0)) || PRIMITIVE_TYPE_SET.contains(methodName)) {
+ throw createParsingFailedException("Invalid method declaration", ctx);
+ }
+ }
+
// literal { --------------------------------------------------------------------
@Override
@@ -4840,6 +4857,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
private static final String IS_STRING = "_IS_STRING";
private static final String IS_INTERFACE_WITH_DEFAULT_METHODS = "_IS_INTERFACE_WITH_DEFAULT_METHODS";
private static final String IS_INSIDE_CONDITIONAL_EXPRESSION = "_IS_INSIDE_CONDITIONAL_EXPRESSION";
+ private static final String IS_COMMAND_EXPRESSION = "_IS_COMMAND_EXPRESSION";
private static final String PATH_EXPRESSION_BASE_EXPR = "_PATH_EXPRESSION_BASE_EXPR";
private static final String PATH_EXPRESSION_BASE_EXPR_GENERICS_TYPES = "_PATH_EXPRESSION_BASE_EXPR_GENERICS_TYPES";
http://git-wip-us.apache.org/repos/asf/groovy/blob/9a33a411/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index f0a372a..80a6d62 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -151,6 +151,9 @@ class SyntaxErrorTest extends GroovyTestCase {
TestUtils.shouldFail('fail/MethodDeclaration_01.groovy');
TestUtils.doRunAndShouldFail('fail/MethodDeclaration_02x.groovy');
TestUtils.doRunAndShouldFail('fail/MethodDeclaration_03x.groovy');
+ TestUtils.doRunAndShouldFail('fail/MethodDeclaration_04x.groovy');
+ TestUtils.doRunAndShouldFail('fail/MethodDeclaration_05x.groovy');
+
}
void "test groovy core - ConstructorDeclaration"() {
http://git-wip-us.apache.org/repos/asf/groovy/blob/9a33a411/subprojects/parser-antlr4/src/test/resources/fail/MethodDeclaration_04x.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/fail/MethodDeclaration_04x.groovy b/subprojects/parser-antlr4/src/test/resources/fail/MethodDeclaration_04x.groovy
new file mode 100644
index 0000000..8457f00
--- /dev/null
+++ b/subprojects/parser-antlr4/src/test/resources/fail/MethodDeclaration_04x.groovy
@@ -0,0 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+foo(String a)
http://git-wip-us.apache.org/repos/asf/groovy/blob/9a33a411/subprojects/parser-antlr4/src/test/resources/fail/MethodDeclaration_05x.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/fail/MethodDeclaration_05x.groovy b/subprojects/parser-antlr4/src/test/resources/fail/MethodDeclaration_05x.groovy
new file mode 100644
index 0000000..15ab3f1
--- /dev/null
+++ b/subprojects/parser-antlr4/src/test/resources/fail/MethodDeclaration_05x.groovy
@@ -0,0 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+foo(int a)
[2/3] groovy git commit: Fix the failing tests
Posted by su...@apache.org.
Fix the failing tests
(cherry picked from commit c690063)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/93c4e38d
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/93c4e38d
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/93c4e38d
Branch: refs/heads/GROOVY_2_6_X
Commit: 93c4e38d542f2c022e2e37d2c2bf42bf0741bfb1
Parents: 1e688d3
Author: danielsun1106 <re...@hotmail.com>
Authored: Sun Feb 25 18:36:22 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Sun Feb 25 20:01:07 2018 +0800
----------------------------------------------------------------------
src/test/gls/syntax/MethodCallValidationTest.groovy | 2 ++
.../groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/93c4e38d/src/test/gls/syntax/MethodCallValidationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/syntax/MethodCallValidationTest.groovy b/src/test/gls/syntax/MethodCallValidationTest.groovy
index 9fe6d52..670b097 100644
--- a/src/test/gls/syntax/MethodCallValidationTest.groovy
+++ b/src/test/gls/syntax/MethodCallValidationTest.groovy
@@ -21,6 +21,8 @@ package gls.syntax
public class MethodCallValidationTest extends gls.CompilableTestSupport {
void testDeclarationInMethodCall() {
+ if (true) return; // skip for the time being
+
shouldNotCompile """
foo(String a)
"""
http://git-wip-us.apache.org/repos/asf/groovy/blob/93c4e38d/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
index 769d378..bbe35c7 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
@@ -342,7 +342,7 @@ class GroovyParserTest extends GroovyTestCase {
doTest('core/Command_03.groovy', [ExpressionStatement, Parameter])
doTest('core/Command_04.groovy', [ExpressionStatement])
doTest('core/Command_05.groovy')
- doRunAndTest('core/Command_06x.groovy')
+ doRunAndTestAntlr4('core/Command_06x.groovy')
}
/*