Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 0f6bd3eb7 -> d91eb131d


Minor refactoring: conditionalStatement

(cherry picked from commit 1783be3)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: d91eb131d12d170cbd3ca68cb3cbfc7a2203484d
Parents: 0f6bd3e
Author: sunlan <sun...@apache.org>
Authored: Thu Oct 5 02:27:04 2017 +0800
Committer: sunlan <sun...@apache.org>
Committed: Thu Oct 5 02:27:46 2017 +0800

----------------------------------------------------------------------
 src/antlr/GroovyParser.g4                       |  8 ++++++--
 .../apache/groovy/parser/antlr4/AstBuilder.java | 20 +++++++++++++-------
 2 files changed, 19 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d91eb131/src/antlr/GroovyParser.g4
----------------------------------------------------------------------
diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index 0d7b5db..700344b 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -630,6 +630,11 @@ variableNames
     :   LPAREN variableDeclaratorId (COMMA variableDeclaratorId)+ rparen
     ;
 
+conditionalStatement
+    :   ifElseStatement
+    |   switchStatement
+    ;
+
 ifElseStatement
     :   IF expressionInPar nls tb=statement ((nls | sep) ELSE nls 
fb=statement)?
     ;
@@ -693,12 +698,11 @@ locals[ String footprint = "" ]
 
 statement
     :   block                                                                  
                             #blockStmtAlt
-    |   ifElseStatement                                                        
                             #ifElseStmtAlt
+    |   conditionalStatement                                                   
                             #conditionalStmtAlt
     |   loopStatement                                                          
                             #loopStmtAlt
 
     |   tryCatchStatement                                                      
                             #tryCatchStmtAlt
 
-    |   switchStatement                                                        
                             #switchStmtAlt
     |   SYNCHRONIZED expressionInPar nls block                                 
                             #synchronizedStmtAlt
     |   RETURN expression?                                                     
                             #returnStmtAlt
     |   THROW expression                                                       
                             #throwStmtAlt

http://git-wip-us.apache.org/repos/asf/groovy/blob/d91eb131/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 28e4e73..7dfef2a 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
@@ -391,8 +391,19 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
     }
 
     @Override
-    public IfStatement visitIfElseStmtAlt(IfElseStmtAltContext ctx) {
-        return configureAST(this.visitIfElseStatement(ctx.ifElseStatement()), 
ctx);
+    public Statement visitConditionalStmtAlt(ConditionalStmtAltContext ctx) {
+        return 
configureAST(this.visitConditionalStatement(ctx.conditionalStatement()), ctx);
+    }
+
+    @Override
+    public Statement visitConditionalStatement(ConditionalStatementContext 
ctx) {
+        if (asBoolean(ctx.ifElseStatement())) {
+            return 
configureAST(this.visitIfElseStatement(ctx.ifElseStatement()), ctx);
+        } else if (asBoolean(ctx.switchStatement())) {
+            return 
configureAST(this.visitSwitchStatement(ctx.switchStatement()), ctx);
+        }
+
+        throw createParsingFailedException("Unsupported conditional 
statement", ctx);
     }
 
     @Override
@@ -686,11 +697,6 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
     }
 
     @Override
-    public SwitchStatement visitSwitchStmtAlt(SwitchStmtAltContext ctx) {
-        return configureAST(this.visitSwitchStatement(ctx.switchStatement()), 
ctx);
-    }
-
-    @Override
     public SwitchStatement visitSwitchStatement(SwitchStatementContext ctx) {
         List<Statement> statementList = new LinkedList<>();
         for (SwitchBlockStatementGroupContext c : 
ctx.switchBlockStatementGroup()) {

Reply via email to