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/07/27 05:23:18 UTC

[groovy] branch master updated: GROOVY-8279: Adapt the groovysh with the new parser Parrot (closes #980)

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 47d106c  GROOVY-8279: Adapt the groovysh with the new parser Parrot (closes #980)
47d106c is described below

commit 47d106cddc069d0f7c9b3e75f1a35aec44685b03
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Jul 22 22:45:22 2019 +1000

    GROOVY-8279: Adapt the groovysh with the new parser Parrot (closes #980)
---
 .../org/apache/groovy/groovysh/Groovysh.groovy     | 24 ++++++++++++++++++++--
 .../org/apache/groovy/groovysh/Interpreter.groovy  |  4 +++-
 .../org/apache/groovy/groovysh/Parser.groovy       |  1 -
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
index 8eb85ba..4b5c388 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy
@@ -199,10 +199,30 @@ class Groovysh extends Shell {
                 if (!Boolean.valueOf(getPreference(INTERPRETER_MODE_PREFERENCE_KEY, 'false')) || isTypeOrMethodDeclaration(current)) {
                     // Evaluate the current buffer w/imports and dummy statement
                     List buff = [importsSpec] + [ 'true' ] + current
-                    setLastResult(result = interp.evaluate(buff))
+                    try {
+                        setLastResult(result = interp.evaluate(buff))
+                    } catch(MultipleCompilationErrorsException t) {
+                        // TODO antlr4 parser errors pop out here - can we rework to be like antlr2?
+                        if (t.message.contains('Unexpected input:') || t.message.contains("Missing ')'")) {
+                            // treat like INCOMPLETE case
+                            buffers.updateSelected(current)
+                            break
+                        }
+                        throw t
+                    }
                 } else {
                     // Evaluate Buffer wrapped with code storing bounded vars
-                    result = evaluateWithStoredBoundVars(importsSpec, current)
+                    try {
+                        result = evaluateWithStoredBoundVars(importsSpec, current)
+                    } catch(MultipleCompilationErrorsException t) {
+                        // TODO antlr4 parser errors pop out here - can we rework to be like antlr2?
+                        if (t.message.contains('Unexpected input:') || t.message.contains("Missing ')'")) {
+                            // treat like INCOMPLETE case
+                            buffers.updateSelected(current)
+                            break
+                        }
+                        throw t
+                    }
                 }
 
                 buffers.clearSelected()
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Interpreter.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Interpreter.groovy
index 1084bc5..5299657 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Interpreter.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Interpreter.groovy
@@ -95,7 +95,9 @@ class Interpreter implements Evaluator
         }
         finally {
             // Remove the script class generated
-            classLoader.removeClassCacheEntry(type?.name)
+            if (type?.name) {
+                classLoader.removeClassCacheEntry(type?.name)
+            }
 
             // Remove the inline closures from the cache as well
             classLoader.removeClassCacheEntry('$_run_closure')
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 286179d..44ce5ac 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
@@ -154,7 +154,6 @@ final class RigidParser implements Parsing
 
         try {
             parser = SourceUnit.create(SCRIPT_FILENAME, source, /*tolerance*/ 1)
-            parser.getConfiguration().setPluginFactory(ParserPluginFactory.antlr2()) // We have to stick to the old parser before GROOVY-8279 is fixed
             parser.parse()
 
             log.debug('Parse complete')