Initial draft of a public API to navigate and manipulate VHDL syntax#1
Initial draft of a public API to navigate and manipulate VHDL syntax#1Schottkyc137 wants to merge 106 commits intomasterfrom
Conversation
This is opposed to the previous implementation where the leading trivia would only return the immediate leading trivia stored in the token, which could be confusing. To get the trivia between two tokens, the user would have to manually extract leading and trailing trivias for the current and the previous resp. next token.
Implement greedy name parsing
… into syntax-crate
|
Finally had some more time to work on this and I think it's looking quite good. The current status is that the new There are also a bunch of other changes - like a new snapshot-based testing system which simplifies writing tests a bunch, optional I think that this might be ready to be merged into the main branch quite soon. There is still a bit of clean-up to do and of course lots of testing. @skaupper do have any further comments on this? I think requesting a full review from you is unreasonable as this is a gigantic PR with > 300 files changed - but if you have any high level comments I'd appreciate them! |
44757e6 to
cfc9b27
Compare
|
Being able to parse the example project is already pretty good. If I see that correctly the parser still uses the hand coded productions with the generated syntax nodes being the interface to the user together with the One thing I am curious about: The generated nodes do not distinguish between mandatory and optional tokens or am I missing something? E.g. As far as I see error reporting is supported in a basic form. Do you have plans for error recovery as well? In some of the examples you mention that the parser API is not finalized. Do you want to further improve that after merging it or is that part of the cleanup? |
|
Thanks for the feedback! I really appreciate it! The fact that all That being said, I agree that the current design makes certain applications very un-ergonomic, especially if a consumer only wants to accept correct source code.
So I think I prefer option 1, if any. It's a you-get-what-you-pay-for solution, can easily be generated from the YAML files and can has an intuitive API. Concerning the finalization of the parser API: This is what I plan to do after merging. I think that at some point done is good enough and a 40k merge request is already tons of changes. The only thing I want to avoid is merging something this big and after a couple of weeks / months decide that it needs to be refactored. That would defeat the whole point. The only thing I'm currently considering is whether the actual AST nodes need a little refactoring. I have started to build a linter as a use-case for the library because it is something I had not thought about in the first place (and I'd also appreciate a good VHDL linter;). Refactoring |
|
Okay I get where you want to go with the AST now. Even if you would like to accept incorrect code, how should that work? I've toyed around with the example given in entity baz
port (
a: in std_ulogic
);
end entity baz;
entity foo is
end entity bar;To be fair, error recovery is still a TODO according to Lets say the parser can recover from an error by synchronizing to an |
Currently, the scope of this library is to parse correct code (tbh that's hard enough :D).
I will try to motivate the need for a structure (AST / CST / SyntaxNodes) that support having incomplete or erroneous nodes and tokens, and it's the applications:
This raises the issue that you would have to re-implement complex recovery logic instead of at one central place.
I believe that this is the critical point: At what granularity does the AST allow erroneous nodes? I believe that the answer should be either at every possible position or at none. The case "at every possible position" is used for the examples above and the case "none" is used for documentation generators, test bench extractors, and in general code that expects to work with correct VHDL code. Currently implemented is the "errors are possible everywhere" API whereas what's still missing is the "everything is correct (or there are diagnostics)" API. |
9f9f4e3 to
e2ec8ea
Compare
|
Now part of the main repo |
No description provided.