You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/09/27 10:22:57 UTC

[groovy] branch master updated: groovysh: remove antlr2 RelaxedParser

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ac88d9  groovysh: remove antlr2 RelaxedParser
5ac88d9 is described below

commit 5ac88d976559910b7c3b01b73a58a32aa55f243f
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Sep 27 20:22:45 2019 +1000

    groovysh: remove antlr2 RelaxedParser
---
 .../org/apache/groovy/groovysh/Parser.groovy       |  6 +-
 .../apache/groovy/groovysh/RelaxedParser.groovy    | 84 ----------------------
 2 files changed, 2 insertions(+), 88 deletions(-)

diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Parser.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Parser.groovy
index b793d60..96f4c25 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Parser.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Parser.groovy
@@ -18,9 +18,8 @@
  */
 package org.apache.groovy.groovysh
 
-import org.codehaus.groovy.antlr.AntlrParserPluginFactory
+import org.apache.groovy.groovysh.antlr4.RelaxedParser
 import org.codehaus.groovy.control.CompilationFailedException
-import org.codehaus.groovy.control.CompilerConfiguration
 import org.codehaus.groovy.control.SourceUnit
 import org.codehaus.groovy.tools.shell.util.Logger
 import org.codehaus.groovy.tools.shell.util.Preferences
@@ -48,8 +47,7 @@ class Parser {
 
         switch (flavor) {
             case Preferences.PARSER_RELAXED:
-                boolean oldParserEnabled = CompilerConfiguration.DEFAULT.getPluginFactory() instanceof AntlrParserPluginFactory;
-                delegate = oldParserEnabled ? new RelaxedParser() : new org.apache.groovy.groovysh.antlr4.RelaxedParser()
+                delegate = new RelaxedParser()
                 break
 
             case Preferences.PARSER_RIGID:
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/RelaxedParser.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/RelaxedParser.groovy
deleted file mode 100644
index 21389f9..0000000
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/RelaxedParser.groovy
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.apache.groovy.groovysh
-
-import antlr.RecognitionException
-import antlr.TokenStreamException
-import antlr.collections.AST
-import org.apache.groovy.parser.antlr4.GroovyLangLexer
-import org.codehaus.groovy.antlr.SourceBuffer
-import org.codehaus.groovy.antlr.UnicodeEscapingReader
-import org.codehaus.groovy.antlr.parser.GroovyRecognizer
-import org.codehaus.groovy.tools.shell.util.Logger
-
-/**
- * A relaxed parser, which tends to allow more, but won't really catch valid syntax errors.
- */
-final class RelaxedParser implements Parsing {
-    private final Logger log = Logger.create(this.class)
-
-    private SourceBuffer sourceBuffer
-
-    private String[] tokenNames
-
-    @Override
-    ParseStatus parse(final Collection<String> buffer) {
-        assert buffer
-
-        sourceBuffer = new SourceBuffer()
-
-        def source = buffer.join(Parser.NEWLINE)
-
-        log.debug("Parsing: $source")
-
-        try {
-            doParse(new UnicodeEscapingReader(new StringReader(source), sourceBuffer))
-
-            log.debug('Parse complete')
-
-            return new ParseStatus(ParseCode.COMPLETE)
-        }
-        catch (e) {
-            switch (e.getClass()) {
-                case TokenStreamException:
-                case RecognitionException:
-                    log.debug("Parse incomplete: $e (${e.getClass().name})")
-
-                    return new ParseStatus(ParseCode.INCOMPLETE)
-
-                default:
-                    log.debug("Parse error: $e (${e.getClass().name})")
-
-                    return new ParseStatus(e)
-            }
-        }
-    }
-
-    protected AST doParse(final UnicodeEscapingReader reader) throws Exception {
-        GroovyLangLexer lexer = new GroovyLangLexer(reader)
-        reader.setLexer(lexer)
-
-        def parser = GroovyRecognizer.make(lexer)
-        parser.setSourceBuffer(sourceBuffer)
-        tokenNames = parser.tokenNames
-
-        parser.compilationUnit()
-        return parser.AST
-    }
-}
\ No newline at end of file