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

Prog8 sensitive to ending on newline #40

Closed
cyborgar opened this issue May 13, 2021 · 7 comments
Closed

Prog8 sensitive to ending on newline #40

cyborgar opened this issue May 13, 2021 · 7 comments

Comments

@cyborgar
Copy link

This is just a small annoyance and possibly just cause by my choice of editor (Emacs). The editor does not automatically add a newline at the last line when editing normally.

test.p8:9:1: missing EOL at ''

Attaching a minimal file that reproduce the error.

test.zip

@irmen
Copy link
Owner

irmen commented May 14, 2021

This isn't easily fixable in the grammar, as a module file consists of blocks and a block (and other scopes) are required to be finalized with an EOL.

However it can probably be worked around quite easily in the ModuleImporter by just appending a single EOL character before feeding it to the parser

@cyborgar
Copy link
Author

I think that would be a nice solution, just for convenience. It's one of those "fix by cheating" that requires good comments in the code to prevent accidental removal later.

@irmen irmen closed this as completed in ae5d770 May 14, 2021
@meisl
Copy link
Contributor

meisl commented May 19, 2021

Hi, I had been stumbling over this as well. It is minor, but still annoying IMHO.

It should be possible to adjust the grammar, something like treating EOF as a scope-terminator just like EOL.

I think this should be fixed, so I'd vote for re-opening this issue. Not utterly urgent, though.

@irmen
Copy link
Owner

irmen commented May 20, 2021

@meisl It has been fixed in the linked commit, just not by changing the grammar but by adjusting the input file. I was adjusting that anyway already to normalize the line endings.

@meisl
Copy link
Contributor

meisl commented Jun 8, 2021

Sorry, I obviously misunderstood.

@irmen
Copy link
Owner

irmen commented Jun 8, 2021

Maybe it can be fixed in the grammar file itself and then the line munging in the code could be removed, but I couldn't get it to work. My Antlr-Fu isn't big enough.

@meisl
Copy link
Contributor

meisl commented Jun 9, 2021

How about changing

block: identifier integerliteral? '{' EOL (block_statement | EOL) * '}' EOL ;

to

    block: identifier integerliteral? '{' EOL (block_statement | EOL) * '}' (EOL | EOF) ;

?

Line endings should more efficiently be dealt with there, too: change

EOL : [\n]+ ;

to

    EOL: ('\r'? '\n')+ ;

(saves searching and basically copying the whole file content)


p.s.: beware, that's purely by looking at it - haven't tried it. Seems that it's getting time for me to set things up for building myself...

meisl pushed a commit to meisl/prog8 that referenced this issue Jun 12, 2021
meisl pushed a commit to meisl/prog8 that referenced this issue Jun 12, 2021
meisl pushed a commit to meisl/prog8 that referenced this issue Jun 13, 2021
meisl pushed a commit to meisl/prog8 that referenced this issue Jun 13, 2021
meisl pushed a commit to meisl/prog8 that referenced this issue Jun 13, 2021
meisl pushed a commit to meisl/prog8 that referenced this issue Jun 13, 2021
meisl pushed a commit to meisl/prog8 that referenced this issue Jun 13, 2021
…ust have a newline after their closing `}`
meisl pushed a commit to meisl/prog8 that referenced this issue Jun 13, 2021
…doesn't actually fail with old grammar, but a built jar does - WHY?!*
meisl pushed a commit to meisl/prog8 that referenced this issue Jun 14, 2021
…): also test sole \r AND do not allow any recovery, neither from parser not lexer.
meisl pushed a commit to meisl/prog8 that referenced this issue Jun 14, 2021
meisl pushed a commit to meisl/prog8 that referenced this issue Jun 14, 2021
… a "synthesized double EOF" (behavior remains exactly the same)
irmen added a commit that referenced this issue Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants