-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
libexpr: would you like to accept patches that improve error handling in the parser? #8584
Comments
I can't give a direct answer to your question, but these are my thoughts so far: It must not regress; neither performance nor the quality of error messages. It would be good to know for sure that this parser can be adapted sufficiently for your use case. If you need to switch away from this parser anyway, there's no point in proceeding with this. Tree-sitter is supposed to be tailored to your use case. Changes to the Nix grammar and/or parser are rare. |
For performance issue: error handling only affects what Nix will do when it encounters an error. If no errors occur, it should behave as usual. Quality of error messages: When designing compilers/interpreters, I think we usually try to guess what the user is missing (for example, the semicolon at the end of a statement in C/C++). The compiler can handle this error and continue parsing the remaining parts, so we can provide more error information (see my screenshot for reference).
I intend to maintain a fork of the parser to support ranges (as it appears that Nix only preserves the beginning of AST nodes, not their endings) and to preserve comments. This may have an impact on performance and not suitable for upstreaming here.
IMHO, this approach is not practical because the data structures in the forked parser have to be shared with libexpr, including Evaluation is necessary for dynamic bindings, dynamic envs, etc. e.g.
As mentioned above, this will not change the grammar. |
I want to believe this, but I think we should measure it.
Usually when this happens there will be cases where the tool assumes too much and produces nonsense errors instead of raising the first, valid error. One possible option is to put all the extra rules in their own section behind an ifdef. That would also settle the performance question.
You'd have to construct |
Thanks for quick response @roberth ❤️ . High-level, IMHO: Generally I want to see a consistent software ecosystem with shared components for nix tooling. Such as formatter, linter, and LSPs, however there are many nix parser implementation and they are different from this one in some details. (GLR parser with ambiguous grammar). e.g some parser could not handle
and some lexer do not look ahead for paths. I don't know if the community agrees with this idea, but I believe it will benefit on developer experience & new users exploring Nix language. And reply:
Frankly this is true in C++ world. We definitely want to avoid this in Nix.
I admit that nix itself is fast enough for re-runs, so I filed this issue here. Maybe "recovery from error" is not very suitable for CLIs, but
For implementation details, I would like to use a slightly modified parser in this repo (this is already implemented and landed in nixd), instead of reimpl many funny stuffs happend in the parser. Maintaining a tree-transformer is definitely more complicate than maintaining a slightly modified fork. |
I get that reusing as much of this C++ codebase as possible is the essence of your approach, but I must admit if that the only way to write a correct language server, it means we've failed to adequately specify the Nix language. I'm happy you are using the codebase in exciting news ways — I do want that to be an option, but I don't want it to be the only option. |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-07-24-nix-team-meeting-minutes-75/31112/1 |
Discussed during the Nix team meeting. As @roberth said, we can accept such contributions if:
|
On a side note, there was a similar discussion on nickel, and the outcome was that trying to directly enrich the grammar (lalrpop in that case) would be a lot of work for some debatable results. |
Is your feature request related to a problem? Please describe.
Nix community needs a language server that could be used for "goto definition" for lambdas nixpkgs, or "goto definition" for packages. I'm writting a parser that based on this official one that suitable for LSPs (that is, preserve comments, better error handling, and preserve ranges). Would you like to accept patches that add some error handling logic, instead of throwing
nix::ParseError
directly in the parser? This is critical to auto-completion for nixpkgs option system, e.g.Describe the solution you'd like
I have implemented these features in the repo (partial) https://github.com/nix-community/nixd . Basically just extending the syntax productions. e.g.
So far it can recover multiple errors like missing semi-colon, or missing
=
forbinds
:However currently nix parser would only report the first issue:
Would you like to accept these patches?
Describe alternatives you've considered
Maybe this is not suitable for nix library here.
Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: