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

[RFC 0118] Extra semicolon as a warning instead of an syntax error #118

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions rfcs/0118-optional-final-semicolon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
feature: optional-final-semicolon
start-date: 2021-12-03
author: Lucas Eduardo Wendt
co-authors: (find a buddy later to help out with the RFC)
shepherd-team: (names, to be nominated and accepted by RFC steering committee)
shepherd-leader: (name to be appointed by RFC steering committee)
related-issues: (will contain links to implementation PRs)
---

# Summary
[summary]: #summary

Make it acceptable a semicolon at the end of a Nix expression raising a warning instead of a syntax error.

# Motivation
[motivation]: #motivation

Faster iterations.

Some people use full keyboard editors and hack around with their configurations, sometimes you move code from the final
part to a let expression or the reverse to test something or debug some faulty part then forgot a semicolon on the
final of the last line, the code fails with a syntax error then you reopen the editor just to remove the semicolon to
make the parser happy, then you forgot the semicolon when you put the thing back to a let expression. This should be
a recoverable syntax issue just raising a warning to remove that semicolon when all is over.

This would make iterations a little faster and bring a bit less friction, and give a better clue about what is going on in this case.

# Detailed design
[design]: #detailed-design

Allow an optional semicolon at the end of an expression raising a warning if it's provided.

Comment on lines +29 to +33
Copy link
Member

@Profpatsch Profpatsch Apr 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a detailed design.

I would expect to get a good idea of how this will be implemented technically.

Note that I tried adding an optional semicolon to the parser a few years ago, but it was rejected because my implementation was naïve (just have a giant lookahead essentially). So I’d like to see a technical design here that is feasible.

# Examples and Interactions
[examples-and-interactions]: #examples-and-interactions

=> 2+2
4
=> 2+2;
warning: extra semicolon at the end of the expression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For files, it should also show which file is having the extra semicolon.

4

The second example raises a syntax error on, for example, Nix 2.4

```
nix-repl> 2+2
4

nix-repl> 2+2;
error: syntax error, unexpected ';', expecting end of file

at «string»:1:4:

1| 2+2;
| ^
2|
```

# Drawbacks
[drawbacks]: #drawbacks

- Temporary unhandled edge case for secondary nix parsers like [rnix-parser](https://github.com/nix-community/rnix-parser) that by consequency affects [rnix-lsp](https://github.com/nix-community/rnix-lsp)

# Alternatives
[alternatives]: #alternatives

There are no alternatives so far.

The impact of not doing this is not critic.
Comment on lines +67 to +69
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One alternative is changing the error from:

error: syntax error, unexpected ';', expecting end of file

to something like:

error: syntax error, unexpected ';', expecting end of file
Consider removing the ';' at the end of the file or expression.

       at «string»:1:4:

            1| 1+2;
             |    ^

That said, allowing people to write ;, but outputting a warning might cause warnings in places when the parser touches a file lazily. Potentially warning about extraneous ; in files that I didn't write myself.


# Unresolved questions
[unresolved]: #unresolved-questions

What parts of the design are still TBD or unknowns?

# Future work
[future]: #future-work

What future work, if any, would be implied or impacted by this feature
without being directly part of the work?