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 macro TypedParser will 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 modify generate in pest-generator to 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, where i is the index of the variant in those choices. And for clarity, I didn't use tuple structs for sequences, and name struct fields as field_i, where i is 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
pest-typed.
pest3.
(Some of these may be done in pest3 instead pest-typed, as pest-typed still needs compatibility with pest2)
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
Otherwise, this may cause panics or errors if users forget to modify them in the same time.
In my codes, the proc macro
TypedParserwill create structs for sequences, enums for choices and a lot of generics structs for strings, peek, and etc.I added several new traits, several helper structs and 1 proc macro. But I modify
generateinpest-generatorto avoid repetition.Something to be discussed
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
pest-typed.
pest3.
(Some of these may be done in pest3 instead pest-typed, as pest-typed still needs compatibility with pest2)
TypedParser.Boxwhen requested. See pest-generator/graph.rs.Done in TheVeryDarkness/pest-typed@e9b24d6.