cbuschka / beanshell2

Automatically exported from code.google.com/p/beanshell2
0 stars 0 forks source link

Parser Error When Omitting Semi-colons in Blocks #91

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This isn't necessarily something to fix, possibly warn about...

The original manual makes a misleading statement about semi-colons.

http://www.beanshell.org/manual/embeddedmode.html#eval%28%29

eval():
"It is not necessary to add a trailing ";" semi-colon at the end of the 
evaluated string. BeanShell always adds one at the end of the string."

To test, run "java -jar bsh-2.1.6.jar" to get the BeanShell Desktop.

This is indeed true for simple statements.
~ ~ ~ ~
bsh % print("Hello World")

Hello World
bsh % 
~ ~ ~ ~

Interestingly, the Workspace doesn't wait for a second enter keypress when 
including the semi-colon.
~ ~ ~ ~
bsh % print("Hello World");
Hello World
bsh %
~ ~ ~ ~

However, when evaluating a loop, with a block that omits semi-colons, BeanShell 
Desktop throws errors about unexpected braces (or anything else that comes 
after the first missing semi-colon).

~ ~ ~ ~
bsh % for (i=0; i<3; i++) {
  print(i)
}
// Error: Parser Error: Parse error at line 1, column 199.  Encountered: }
~ ~ ~ ~

~ ~ ~ ~
bsh % for (i=0; i<3; i++) {
  print(i);
}
0
1
2
bsh % 
~ ~ ~ ~

As a workaround one can double-space the block: follow each semi-colonless line 
with blank line.
~ ~ ~ ~
bsh % for (i=0; i<1; i++) {
  print("Hello")

  print("World")

}
Hello
World
bsh %
~ ~ ~ ~

Original issue reported on code.google.com by tvtro...@gmail.com on 1 Oct 2013 at 3:35

GoogleCodeExporter commented 8 years ago
The behaviour is a bit weird, but this is exactly the same behaviour as in the 
'original' Beanshell (v2.0b4).

I think it was never intended like you understand this 'feature'. The 'blank 
line' example should isssue a 'Parse Error', but I won't fix thsi to prevent 
further compatibility issues.

Original comment by pejob...@gmail.com on 2 Oct 2013 at 11:46