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/05/25 13:42:20 UTC
groovy git commit: Refine node position of statements
Repository: groovy
Updated Branches:
refs/heads/master ac6c20c84 -> 7e4caea28
Refine node position of statements
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7e4caea2
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7e4caea2
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7e4caea2
Branch: refs/heads/master
Commit: 7e4caea28f576be32b6e6abec06ec48b82c8863e
Parents: ac6c20c
Author: sunlan <su...@apache.org>
Authored: Thu May 25 21:42:10 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Thu May 25 21:42:10 2017 +0800
----------------------------------------------------------------------
.../groovy/ast/LineColumnCheck_antlr4.txt | 2 +-
.../apache/groovy/parser/antlr4/GroovyParser.g4 | 14 ++++++++-----
.../apache/groovy/parser/antlr4/AstBuilder.java | 22 ++++++++++++--------
3 files changed, 23 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e4caea2/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr4.txt
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr4.txt b/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr4.txt
index 6f26726..4eb0cb8 100644
--- a/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr4.txt
+++ b/src/test/org/codehaus/groovy/ast/LineColumnCheck_antlr4.txt
@@ -24,7 +24,7 @@ if (expression) {
}
:::[IfStatement,(1:1),(5:2)];
-[BooleanExpression,(1:4),(1:16)][VariableExpression,(1:4),(1:16)];
+[BooleanExpression,(1:5),(1:15)][VariableExpression,(1:5),(1:15)];
[BlockStatement,(1:17),(3:2)];
[BlockStatement,(3:8),(5:2)]
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e4caea2/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyParser.g4
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyParser.g4 b/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyParser.g4
index 1d424d1..655008b 100644
--- a/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyParser.g4
+++ b/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyParser.g4
@@ -624,14 +624,14 @@ variableNames
switchStatement
locals[ String footprint = "" ]
- : SWITCH parExpression nls LBRACE nls switchBlockStatementGroup* nls RBRACE
+ : SWITCH expressionInPar nls LBRACE nls switchBlockStatementGroup* nls RBRACE
;
loopStatement
locals[ String footprint = "" ]
: FOR LPAREN forControl rparen nls statement #forStmtAlt
- | WHILE parExpression nls statement #whileStmtAlt
- | DO nls statement nls WHILE parExpression #doWhileStmtAlt
+ | WHILE expressionInPar nls statement #whileStmtAlt
+ | DO nls statement nls WHILE expressionInPar #doWhileStmtAlt
;
continueStatement
@@ -690,13 +690,13 @@ locals[ String footprint = "" ]
statement
: block #blockStmtAlt
- | IF parExpression nls tb=statement ((nls | sep) ELSE nls fb=statement)? #ifElseStmtAlt
+ | IF expressionInPar nls tb=statement ((nls | sep) ELSE nls fb=statement)? #ifElseStmtAlt
| loopStatement #loopStmtAlt
| tryCatchStatement #tryCatchStmtAlt
| switchStatement #switchStmtAlt
- | SYNCHRONIZED parExpression nls block #synchronizedStmtAlt
+ | SYNCHRONIZED expressionInPar nls block #synchronizedStmtAlt
| RETURN expression? #returnStmtAlt
| THROW expression #throwStmtAlt
@@ -791,6 +791,10 @@ castParExpression
;
parExpression
+ : expressionInPar
+ ;
+
+expressionInPar
: LPAREN enhancedStatementExpression rparen
;
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e4caea2/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 a7b9e97..faab339 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
@@ -354,7 +354,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
@Override
public IfStatement visitIfElseStmtAlt(IfElseStmtAltContext ctx) {
- Expression conditionExpression = this.visitParExpression(ctx.parExpression());
+ Expression conditionExpression = this.visitExpressionInPar(ctx.expressionInPar());
BooleanExpression booleanExpression =
this.configureAST(
new BooleanExpression(conditionExpression), conditionExpression);
@@ -468,7 +468,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
@Override
public WhileStatement visitWhileStmtAlt(WhileStmtAltContext ctx) {
- Expression conditionExpression = this.visitParExpression(ctx.parExpression());
+ Expression conditionExpression = this.visitExpressionInPar(ctx.expressionInPar());
BooleanExpression booleanExpression =
this.configureAST(
new BooleanExpression(conditionExpression), conditionExpression);
@@ -482,7 +482,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
@Override
public DoWhileStatement visitDoWhileStmtAlt(DoWhileStmtAltContext ctx) {
- Expression conditionExpression = this.visitParExpression(ctx.parExpression());
+ Expression conditionExpression = this.visitExpressionInPar(ctx.expressionInPar());
BooleanExpression booleanExpression =
this.configureAST(
@@ -657,7 +657,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return this.configureAST(
new SwitchStatement(
- this.visitParExpression(ctx.parExpression()),
+ this.visitExpressionInPar(ctx.expressionInPar()),
caseStatementList,
defaultStatementListSize == 0 ? EmptyStatement.INSTANCE : defaultStatementList.get(0)
),
@@ -729,15 +729,13 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
throw createParsingFailedException("Unsupported switch label: " + ctx.getText(), ctx);
}
-
@Override
public SynchronizedStatement visitSynchronizedStmtAlt(SynchronizedStmtAltContext ctx) {
return this.configureAST(
- new SynchronizedStatement(this.visitParExpression(ctx.parExpression()), this.visitBlock(ctx.block())),
+ new SynchronizedStatement(this.visitExpressionInPar(ctx.expressionInPar()), this.visitBlock(ctx.block())),
ctx);
}
-
@Override
public ExpressionStatement visitExpressionStmtAlt(ExpressionStmtAltContext ctx) {
return (ExpressionStatement) this.visit(ctx.statementExpression());
@@ -1815,7 +1813,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
@Override
public Expression visitParExpression(ParExpressionContext ctx) {
- Expression expression = this.visitEnhancedStatementExpression(ctx.enhancedStatementExpression());
+ Expression expression = this.visitExpressionInPar(ctx.expressionInPar());
expression.putNodeMetaData(IS_INSIDE_PARENTHESES, true);
@@ -1830,7 +1828,13 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
return this.configureAST(expression, ctx);
}
- @Override public Expression visitEnhancedStatementExpression(EnhancedStatementExpressionContext ctx) {
+ @Override
+ public Expression visitExpressionInPar(ExpressionInParContext ctx) {
+ return this.visitEnhancedStatementExpression(ctx.enhancedStatementExpression());
+ }
+
+ @Override
+ public Expression visitEnhancedStatementExpression(EnhancedStatementExpressionContext ctx) {
Expression expression;
if (asBoolean(ctx.statementExpression())) {