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: if-else
Date Wed, 04 Oct 2017 18:04:02 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 93bfa40f3 -> b384a3923


Minor refactoring: if-else


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

Branch: refs/heads/master
Commit: b384a3923484f03f8c8dab761f7928727634cce7
Parents: 93bfa40
Author: sunlan <sunlan@apache.org>
Authored: Thu Oct 5 02:03:53 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Thu Oct 5 02:03:53 2017 +0800

----------------------------------------------------------------------
 src/antlr/GroovyParser.g4                                     | 6 +++++-
 .../main/java/org/apache/groovy/parser/antlr4/AstBuilder.java | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b384a392/src/antlr/GroovyParser.g4
----------------------------------------------------------------------
diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index 59a6f4c..ad504e1 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -597,6 +597,10 @@ variableNames
     :   LPAREN variableDeclaratorId (COMMA variableDeclaratorId)+ rparen
     ;
 
+ifElseStatement
+    :   IF expressionInPar nls tb=statement ((nls | sep) ELSE nls fb=statement)?
+    ;
+
 switchStatement
 locals[ String footprint = "" ]
     :   SWITCH expressionInPar nls LBRACE nls switchBlockStatementGroup* nls RBRACE
@@ -656,7 +660,7 @@ locals[ String footprint = "" ]
 
 statement
     :   block                                                                           
                   #blockStmtAlt
-    |   IF expressionInPar nls tb=statement ((nls | sep) ELSE nls fb=statement)?        
                   #ifElseStmtAlt
+    |   ifElseStatement                                                                 
                   #ifElseStmtAlt
     |   loopStatement                                                                   
                   #loopStmtAlt
 
     |   tryCatchStatement                                                               
                   #tryCatchStmtAlt

http://git-wip-us.apache.org/repos/asf/groovy/blob/b384a392/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 29cd49e..226d200 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
@@ -388,6 +388,11 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
 
     @Override
     public IfStatement visitIfElseStmtAlt(IfElseStmtAltContext ctx) {
+        return configureAST(this.visitIfElseStatement(ctx.ifElseStatement()), ctx);
+    }
+
+    @Override
+    public IfStatement visitIfElseStatement(IfElseStatementContext ctx) {
         Expression conditionExpression = this.visitExpressionInPar(ctx.expressionInPar());
         BooleanExpression booleanExpression =
                 configureAST(
@@ -405,6 +410,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
         return configureAST(new IfStatement(booleanExpression, ifBlock, elseBlock), ctx);
     }
 
+
     @Override
     public Statement visitLoopStmtAlt(LoopStmtAltContext ctx) {
         return configureAST((Statement) this.visit(ctx.loopStatement()), ctx);
@@ -668,6 +674,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object>
implements Groov
         return configureAST(this.visitSwitchStatement(ctx.switchStatement()), ctx);
     }
 
+    @Override
     public SwitchStatement visitSwitchStatement(SwitchStatementContext ctx) {
         List<Statement> statementList =
                 ctx.switchBlockStatementGroup().stream()


Mime
View raw message