Skip to content

Newline required at end of file with test statement #87

Open

Description

@lam2mo

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>'

Activity

  1. Zamua commented on Feb 21, 2020

    @Zamua
    Contributor

    What's the bug?

  2. lam2mo commented on Feb 21, 2020

    @lam2mo
    MemberAuthor

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

  3. changed the title [-]Newline required at end of file[/-] [+]Newline required at end of file with test statement[/+] on Feb 21, 2020
  4. Zamua commented on Feb 21, 2020

    @Zamua
    Contributor

    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

  5. lam2mo commented on Feb 21, 2020

    @lam2mo
    MemberAuthor

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

  6. self-assigned this
    on Feb 21, 2020
  7. Zamua commented on Feb 21, 2020

    @Zamua
    Contributor

    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.

  8. Zamua commented on Feb 21, 2020

    @Zamua
    Contributor

    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";
    
  9. added a commit that references this issue on Feb 21, 2020
    8b96948
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions