Skip to content

Generating statically typed syntax tree. #882

@TheVeryDarkness

Description

@TheVeryDarkness

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions