Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newline required at end of file with test statement #87

Open
lam2mo opened this issue Feb 20, 2020 · 6 comments
Open

Newline required at end of file with test statement #87

lam2mo opened this issue Feb 20, 2020 · 6 comments
Assignees
Labels

Comments

@lam2mo
Copy link
Member

lam2mo commented Feb 20, 2020

During the UI testing (see #84) I discovered that I was getting a parse error if the file ended with a "test" statement that didn't terminate with a newline. This may be a UI-only issue; more testing is necessary.

main() {
  println("Hello, world")
}
test 1 + 2 == 3
line 4:13 missing EOL at '<EOF>'
@lam2mo lam2mo added the bug label Feb 20, 2020
@Zamua
Copy link
Contributor

Zamua commented Feb 21, 2020

What's the bug?

@lam2mo
Copy link
Member Author

lam2mo commented Feb 21, 2020

Sorry, was going to come back and add more details later but today was crazy busy. Edited with more info.

@lam2mo lam2mo changed the title Newline required at end of file Newline required at end of file with test statement Feb 21, 2020
@Zamua
Copy link
Contributor

Zamua commented Feb 21, 2020

https://github.com/JMU-CS/less-java/blob/master/src/main/antlr/LJ.g4#L20

Yeah seems the grammar requires an EOL. Could we redefine EOL to be a new line character or end of file?

Here's some discussion I found online about that: http://antlr.1301665.n2.nabble.com/How-to-treat-EOF-as-NEWLINE-td7579363.html

The second to last comment seems to provide a solution:

Just read Lexer Grammar Ambiguities chapter in ANTLR reference. This
kind of grammar works as expected:

grammar Test;
rule: 'rule' newline;
newline: NEWLINE | EOF;
NEWLINE: '\n';

=)

-- Alexander

@lam2mo
Copy link
Member Author

lam2mo commented Feb 21, 2020

Aha. Figured it was something like that. Yes, this seems like a fine solution to me.

@Zamua Zamua self-assigned this Feb 21, 2020
@Zamua
Copy link
Contributor

Zamua commented Feb 21, 2020

Did some testing and I can't quite get it to work. It also appears that it's maybe not recommended: https://www.antlr3.org/pipermail/antlr-interest/2011-January/040642.html

That claims that it's probably easier to just add a new line to the input if there isn't one present. Dealing with it in the grammar can be more trouble than it's worth.

@Zamua
Copy link
Contributor

Zamua commented Feb 21, 2020

Can't figure out if there's an elegant way for me to add a commit to #84 but the change is simple.

before this line: https://github.com/lam2mo/less-java/blob/ui/src/main/java/com/github/lessjava/LJUI.java#L98

add:

code += "\n";

lam2mo added a commit to lam2mo/less-java that referenced this issue Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants