-
-
Notifications
You must be signed in to change notification settings - Fork 289
Open
Labels
Milestone
Description
I'm working to add some codes to pest to support generating statically typed syntax tree in my fork, and I'm going to make a pull request after fixing all bugs and maybe adding some documentations and tests.
As we can see, there are several crates doing similar things, such as pest-ast and pest-consume. So I'm afraid that you may not accept this contribution if my implementation is bad or you don't agree with my design.
I'll talk about what I did and what I'm going to do then. If you have any suggestions, please tell me.
My principles
- Users don't need to write the same thing twice in pest grammar files and rust codes. (This is also why pest-ast and pest-consume do not fully satisfy me. Typically I need to write a lot of codes with attributes with them)
Otherwise, this may cause panics or errors if users forget to modify them in the same time.
In my codes, the proc macroTypedParserwill create structs for sequences, enums for choices and a lot of generics structs for strings, peek, and etc. - Re-use previous codes in pest without too many changes.
I added several new traits, several helper structs and 1 proc macro. But I modifygenerateinpest-generatorto avoid repetition. - Generate essential document comments.
Something to be discussed
- In Rust, according to what I've learned, enum variants must be named, currently I name them
var_i, whereiis the index of the variant in those choices. And for clarity, I didn't use tuple structs for sequences, and name struct fields asfield_i, whereiis the index.
This may not be the best choice, and please tell me if there is a better design :)
Maybe using node tags?
TODO list
(Some of these may be done in pest3 instead pest-typed, as pest-typed still needs compatibility with pest2)
- Fix all bugs.
- Add docs and tests to
TypedParser. - Support node hooks (maybe a bit like visitor in ANTLR?). And the node (and its type) will be replaced by the return value (and its type) of the hook.
- Use fewer
Boxwhen requested. See pest-generator/graph.rs.
Done in TheVeryDarkness/pest-typed@e9b24d6. - Avoid recursion. This may be impossible.
- Support input streams or async input streams. See Restoration of the pest3 work effort 🙌 #885 (comment).
- Support custom input type.
- Provide a feature to store the syntax tree in an arena.
- Support checking only. Done in pest3. Related commits are pest-parser/pest3@787efde and pest-parser/pest3@ae7ddb6.
Reactions are currently unavailable