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 2015/11/07 18:09:35 UTC
incubator-groovy git commit: GROOVY-2178 - Shell can not handle
multi-line list defs (closes #181)
Repository: incubator-groovy
Updated Branches:
refs/heads/master 1eb37ea96 -> a6d88f6eb
GROOVY-2178 - Shell can not handle multi-line list defs (closes #181)
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/a6d88f6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/a6d88f6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/a6d88f6e
Branch: refs/heads/master
Commit: a6d88f6ebdce5e9509b8cbbff69c382c5ecee75c
Parents: 1eb37ea
Author: John Wagenleitner <jo...@gmail.com>
Authored: Sat Nov 7 07:28:48 2015 -0800
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sat Nov 7 18:09:16 2015 +0100
----------------------------------------------------------------------
.../codehaus/groovy/tools/shell/Parser.groovy | 22 +++++++++++++-
.../tools/shell/GroovyshParsersTest.groovy | 11 +++++++
.../groovy/tools/shell/GroovyshTest.groovy | 30 ++++++++++++++++++++
3 files changed, 62 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/a6d88f6e/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Parser.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Parser.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Parser.groovy
index ea546e7..ecb8477 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Parser.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Parser.groovy
@@ -181,7 +181,8 @@ final class RigidParser implements Parsing
// HACK: Super insane hack... we detect a syntax error, but might still ignore
// it depending on the line ending
if (ignoreSyntaxErrorForLineEnding(buffer[-1].trim()) ||
- isAnnotationExpression(e, buffer[-1].trim())) {
+ isAnnotationExpression(e, buffer[-1].trim()) ||
+ hasUnmatchedOpenBracketOrParen(source)) {
log.debug("Ignoring parse failure; might be valid: $e")
} else {
error = e
@@ -211,6 +212,25 @@ final class RigidParser implements Parsing
return false
}
+ static boolean hasUnmatchedOpenBracketOrParen(String source) {
+ if (!source) {
+ return false
+ }
+ int parens = 0
+ int brackets = 0
+ for (ch in source) {
+ switch(ch) {
+ case '[': ++brackets; break;
+ case ']': --brackets; break;
+ case '(': ++parens; break;
+ case ')': --parens; break;
+ default:
+ break
+ }
+ }
+ return (brackets > 0 || parens > 0)
+ }
+
static boolean isAnnotationExpression(CompilationFailedException e, String line) {
return e.getMessage().contains('unexpected token: @') && ANNOTATION_PATTERN.matcher(line).find()
}
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/a6d88f6e/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/GroovyshParsersTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/GroovyshParsersTest.groovy b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/GroovyshParsersTest.groovy
index e20eb0f..5c66da0 100644
--- a/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/GroovyshParsersTest.groovy
+++ b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/GroovyshParsersTest.groovy
@@ -36,4 +36,15 @@ class GroovyshParsersTest extends GroovyTestCase {
assert RigidParser.isAnnotationExpression(mcee, '@Override')
}
}
+
+ void testHasUnmatchedOpenBracketOrParen() {
+ assert RigidParser.hasUnmatchedOpenBracketOrParen('a = [')
+ assert !RigidParser.hasUnmatchedOpenBracketOrParen('a = [1,2,3]')
+ assert !RigidParser.hasUnmatchedOpenBracketOrParen('a = 1,2,3]')
+
+ assert RigidParser.hasUnmatchedOpenBracketOrParen('myfunc(3')
+ assert !RigidParser.hasUnmatchedOpenBracketOrParen('myfunc(1,2,3)')
+ assert !RigidParser.hasUnmatchedOpenBracketOrParen('a = 1,2,3)')
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/a6d88f6e/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/GroovyshTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/GroovyshTest.groovy b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/GroovyshTest.groovy
index ae7c0fd..5f893e2 100644
--- a/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/GroovyshTest.groovy
+++ b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/GroovyshTest.groovy
@@ -97,6 +97,36 @@ class GroovyshTest extends GroovyTestCase {
}
}
+ void testIncompleteBracketMultilineExpr() {
+ Groovysh groovysh = createGroovysh()
+ groovysh.execute('a = [')
+ groovysh.execute('1,')
+ groovysh.execute('2,')
+ groovysh.execute('3')
+ groovysh.execute(']')
+ groovysh.execute('a.size() == 3')
+ assert mockOut.toString().contains('true')
+ }
+
+ void testIncompleteParenMultilineExpr() {
+ Groovysh groovysh = createGroovysh()
+ groovysh.execute('mc = { num1, num2 -> num1 + num2 }')
+ groovysh.execute('mc(3')
+ groovysh.execute(',')
+ groovysh.execute('7')
+ groovysh.execute(') == 10')
+ assert mockOut.toString().contains('true')
+ }
+
+ void testIncompleteBraceMultilineExpr() {
+ Groovysh groovysh = createGroovysh()
+ groovysh.execute('mc = {')
+ groovysh.execute('3')
+ groovysh.execute('}')
+ groovysh.execute('mc() == 3')
+ assert mockOut.toString().contains('true')
+ }
+
void testMissingPropertyExpr() {
Groovysh groovysh = createGroovysh()
// this is a special case, e.g. happens for Gradle DefaultExtraPropertiesExtension