[
https://issues.apache.org/jira/browse/GROOVY-11660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17951347#comment-17951347
]
Paul King edited comment on GROOVY-11660 at 5/14/25 7:10 AM:
-------------------------------------------------------------
That is by (the current) design. Basically, newline acts as a statement
terminator if the statement can validly finish at that point, with some well
understood exceptions.
The following code is valid (though not recommended) in Groovy:
{code:groovy}
class Blah {
public String
}
def b = new Blah()
b.String = 3
println b.String // => 3
{code}
So, parsing stops after "public String" with "String" being the identifier. If
using the groovyConsole, try "Script -> Inspect CST" to confirm.
One exception is unterminated quotes or brackets, e.g. for below, termination
won't be attempted after the first line:
{code:groovy}
println """
$b.String
"""
{code}
Otherwise, there are a few specific places where we do lookahead, e.g. for this:
{code:groovy}
println b.String
.multiply(4) // => 12
{code}
A standalone statement can't start with a dot, so we also don't terminate on
the previous line.
was (Author: paulk):
That is by the (current) design. Basically, newline acts as a statement
terminator if the statement can validly finish at that point, with some well
understood exceptions.
The following code is valid (though not recommended) in Groovy:
{code:groovy}
class Blah {
public String
}
def b = new Blah()
b.String = 3
println b.String // => 3
{code}
So, parsing stops after "public String" with "String" being the identifier. If
using the groovyConsole, try "Script -> Inspect CST" to confirm.
One exception is unterminated quotes or brackets, e.g. for below, termination
won't be attempted after the first line:
{code:groovy}
println """
$b.String
"""
{code}
Otherwise, there are a few specific places where we do lookahead, e.g. for this:
{code:groovy}
println b.String
.multiply(4) // => 12
{code}
A standalone statement can't start with a dot, so we also don't terminate on
the previous line.
> Variables declared on multiple lines cause an ANTLR error
> ---------------------------------------------------------
>
> Key: GROOVY-11660
> URL: https://issues.apache.org/jira/browse/GROOVY-11660
> Project: Groovy
> Issue Type: Improvement
> Components: parser-antlr4
> Affects Versions: 5.0.0-alpha-12
> Reporter: Saravanan
> Priority: Minor
>
> This code fails during antlr parsing, but is valid Java code because of the ;
> {code:java}
> // code placeholder
> class Blah {
> // This errors out early in the ANTLR phase
> public String
> myMemberVariable;
> public fn() {
> // This also fails in the ANTLR phase
> String
> somethingElse = "BLAH";
> }
> }{code}
> The member variable declaration in unambiguous even in groovy parlance. Can
> this be fixed in the antlr parser? Not so sure about the statement inside the
> function, it feels like its valid groovy code (type on the first line and a
> dynamic variable assignment on the next) but even that fails. The expectation
> though is that it is evaluated as String somethingElse = "BLAH". Is that
> expectation valid?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)