Skip to content

Commit

Permalink
GROOVY-8279: Adapt the groovysh with the new parser Parrot (closes ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
paulk-asert committed Jul 27, 2019
1 parent 1173f80 commit 47d106c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Expand Up @@ -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()
Expand Down
Expand Up @@ -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')
Expand Down
Expand Up @@ -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')
Expand Down

0 comments on commit 47d106c

Please sign in to comment.