You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to us...@groovy.codehaus.org
Am 02.03.2015 12:38, schrieb jitendra...@gmail.com:
> Hi,
> How does groovy detect a line break even without keeping a
> semicolon--";".
in the parser you mean? "\n" becomes significant. So sometimes it is
just swallowed (like in 1+\n2) and sometimes not (like in 1\n+2). It
depends on the grammar rule
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to us...@groovy.codehaus.org
class GroovyMain {
static void main(String... args) {
new GroovyHello().sayHello()
new JavaHello().sayHello()
}
}
For example, in above line of code there is no semicolon placed, what is the grammer rule which force groovy to undertand that there is a line break and compile without any error. Thanks.
View this message in context: Re: How does groovy detect a line break
Owen Rubel
unread,
Mar 4, 2015, 12:30:39 PM3/4/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to us...@groovy.codehaus.org
if there is output in the underlying method, you can detect off that. If it's a stream then pipe into log, pipe into buffer, etc and detect there.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to us...@groovy.codehaus.org
Did your code example get reformatted? The code you posted doesn't compile (after defining the classes GroovyHello and JavaHello of course). There is no grammar rule -- that I know of -- that will accept that. If you want to put multiple statements on one line they must be separated by semi-colons. Otherwise Groovy is going to try and parse it all as one statement.
Cheers,
Keith
------------------------------
Research Associate Department of Computer Science Vassar College Poughkeepsie, NY
Jitendra Singh
unread,
Mar 5, 2015, 1:36:29 AM3/5/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to us...@groovy.codehaus.org
The code got reformatted while posting its actually line by line as corrected below with new exapmle>
My query will fit in now, you could see now none of the line is ended by a ; . How does groovy detect this line break?
Thanks
--
Regards, Jitendra Singh
Jim White
unread,
Mar 5, 2015, 2:19:54 AM3/5/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to us...@groovy.codehaus.org
I haven't looked at Groovy's grammar (it's in ANTLR) but I'm pretty sure the rule is effectively that an EOL is treated as a ; if that would end a syntactically valid statement.
Therefore this is two statements:
1
+ 2
because this is valid:
1 ;
+ 2
and this is one statement:
1 +
2
because this is not:
1 + ;
2
A simple means to make an expression span multiple lines therefore is to embed the EOL within some parenthesis like this single statement:
Meaning, there is a newline allowed after the "new" without terminating
the expression, you can have typeArguments for generics, but there is no
newline allowed before the type itself. The parameters to the new call
can be after a newline, the classblock not.... according to this rule at
least. If you ask now why there are not more nls in there... we would
have to check what the parser generator then says about that. Working
around the limitations of the generated parser is no easy task.