groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Minor refactoring: conditionalStatement
Date Wed, 04 Oct 2017 18:27:12 GMT
Repository: groovy
Updated Branches:
  refs/heads/master b384a3923 -> 1783be3ae


Minor refactoring: conditionalStatement


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

Branch: refs/heads/master
Commit: 1783be3aed8697d30bf1a0374e577a0ea20de197
Parents: b384a39
Author: sunlan <sunlan@apache.org>
Authored: Thu Oct 5 02:27:04 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Thu Oct 5 02:27:04 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/1783be3a/src/antlr/GroovyParser.g4
----------------------------------------------------------------------
diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index ad504e1..23e7e7a 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -597,6 +597,11 @@ variableNames
     :   LPAREN variableDeclaratorId (COMMA variableDeclaratorId)+ rparen
     ;
 
+conditionalStatement
+    :   ifElseStatement
+    |   switchStatement
+    ;
+
 ifElseStatement
     :   IF expressionInPar nls tb=statement ((nls | sep) ELSE nls fb=statement)?
     ;
@@ -660,12 +665,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/1783be3a/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 226d200..157a5be 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
@@ -387,8 +387,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
@@ -670,11 +681,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 =
                 ctx.switchBlockStatementGroup().stream()


Mime
View raw message