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/08/07 15:30:15 UTC
groovy git commit: Revert "Refine antlr4 parser plugin"
Repository: groovy
Updated Branches:
refs/heads/master 53d5af898 -> 7b573c0d2
Revert "Refine antlr4 parser plugin"
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7b573c0d
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7b573c0d
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7b573c0d
Branch: refs/heads/master
Commit: 7b573c0d2fd8513b40ef342ac124c25198a7a6dc
Parents: 53d5af8
Author: sunlan <su...@apache.org>
Authored: Mon Aug 7 23:29:55 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Mon Aug 7 23:29:55 2017 +0800
----------------------------------------------------------------------
.../parser/antlr4/Antlr4ParserPlugin.java | 42 +++++---------------
.../apache/groovy/parser/antlr4/AstBuilder.java | 7 ----
2 files changed, 9 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/7b573c0d/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/Antlr4ParserPlugin.java
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/Antlr4ParserPlugin.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/Antlr4ParserPlugin.java
index 457c64f..0b4728f 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/Antlr4ParserPlugin.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/Antlr4ParserPlugin.java
@@ -18,6 +18,7 @@
*/
package org.apache.groovy.parser.antlr4;
+import org.codehaus.groovy.GroovyBugError;
import org.codehaus.groovy.ast.ModuleNode;
import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.control.ParserPlugin;
@@ -29,7 +30,6 @@ import org.codehaus.groovy.syntax.ParserException;
import org.codehaus.groovy.syntax.Reduction;
import java.io.IOException;
-import java.io.Reader;
/**
* A parser plugin for the new parser
@@ -39,55 +39,31 @@ import java.io.Reader;
*/
public class Antlr4ParserPlugin implements ParserPlugin {
private ReaderSource readerSource;
- private AstBuilder builder;
@Override
- public Reduction parseCST(SourceUnit sourceUnit, Reader reader) throws CompilationFailedException {
- handleSourceUnit(sourceUnit, reader);
- this.builder = new AstBuilder(sourceUnit, null);
- builder.buildCST();
+ public Reduction parseCST(SourceUnit sourceUnit, java.io.Reader reader) throws CompilationFailedException {
+ try {
+ this.readerSource = new StringReaderSource(IOGroovyMethods.getText(reader), sourceUnit.getConfiguration());
+ } catch (IOException e) {
+ throw new GroovyBugError("Failed to create StringReaderSource instance", e);
+ }
return null;
}
@Override
public ModuleNode buildAST(SourceUnit sourceUnit, ClassLoader classLoader, Reduction cst) throws ParserException {
- handleSourceUnit(sourceUnit, null);
-
- if (null == this.builder) {
- this.builder = new AstBuilder(sourceUnit, classLoader);
- }
-
- return builder.buildAST();
- }
-
- private void handleSourceUnit(SourceUnit sourceUnit, Reader reader) {
try {
ReaderSource readerSource = sourceUnit.getSource();
- initReaderSource(sourceUnit, reader, readerSource);
-
if (null == readerSource || null == readerSource.getReader()) {
sourceUnit.setSource(this.readerSource);
}
} catch (IOException e) {
sourceUnit.setSource(this.readerSource);
}
- }
-
- private void initReaderSource(SourceUnit sourceUnit, Reader reader, ReaderSource readerSource) throws IOException {
- if (null != this.readerSource) {
- return;
- }
- if (null != readerSource && null != readerSource.getReader()) {
- this.readerSource = readerSource;
- return;
- }
-
- if (null == reader) {
- return;
- }
+ AstBuilder builder = new AstBuilder(sourceUnit, classLoader);
- this.readerSource = new StringReaderSource(IOGroovyMethods.getText(reader), sourceUnit.getConfiguration());
+ return builder.buildAST();
}
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/7b573c0d/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 98a3b10..af3dcb9 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
@@ -172,10 +172,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
}
public GroovyParserRuleContext buildCST() throws CompilationFailedException {
- if (null != this.cst) {
- return this.cst;
- }
-
GroovyParserRuleContext result;
try {
@@ -197,8 +193,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
throw convertException(t);
}
- this.cst = result;
-
return result;
}
@@ -4531,7 +4525,6 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
}
}
- private GroovyParserRuleContext cst;
private final ModuleNode moduleNode;
private final SourceUnit sourceUnit;
private final ClassLoader classLoader; // Our ClassLoader, which provides information on external types