Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2FCD8200D0A for ; Wed, 4 Oct 2017 20:27:16 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 2E11F1609DD; Wed, 4 Oct 2017 18:27:16 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 72C4B1609D6 for ; Wed, 4 Oct 2017 20:27:15 +0200 (CEST) Received: (qmail 57034 invoked by uid 500); 4 Oct 2017 18:27:14 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 57025 invoked by uid 99); 4 Oct 2017 18:27:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Oct 2017 18:27:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8988FF5843; Wed, 4 Oct 2017 18:27:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sunlan@apache.org To: commits@groovy.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: groovy git commit: Minor refactoring: conditionalStatement Date: Wed, 4 Oct 2017 18:27:12 +0000 (UTC) archived-at: Wed, 04 Oct 2017 18:27:16 -0000 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 Authored: Thu Oct 5 02:27:04 2017 +0800 Committer: sunlan 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 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 implements Groov } @Override - public SwitchStatement visitSwitchStmtAlt(SwitchStmtAltContext ctx) { - return configureAST(this.visitSwitchStatement(ctx.switchStatement()), ctx); - } - - @Override public SwitchStatement visitSwitchStatement(SwitchStatementContext ctx) { List statementList = ctx.switchBlockStatementGroup().stream()