Skip to content
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

How to make language specific AST? #99

Open
stevefan1999-personal opened this issue Oct 15, 2023 · 1 comment
Open

How to make language specific AST? #99

stevefan1999-personal opened this issue Oct 15, 2023 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@stevefan1999-personal
Copy link
Contributor

I want to produce my own AST like this:

pub struct Expr {
    Atom(Identifier),
    Constant(Constant),
    Unary(Operator, Box<Expr>),
    Binary(Box<Expr>, Operator, Box<Expr>),
    Declare(Type, Identifier, Option<Box<Expr>>),
}

What is the best way to let us handle the AST forming part?

@woutersl woutersl self-assigned this Oct 16, 2023
@woutersl woutersl added the question Further information is requested label Oct 16, 2023
@woutersl
Copy link
Member

At this time, there is no specific support for this in Hime. You can manually walk the AST/SPPF to reconstruct domain objects. That is what is done in the Hime SDK to load the grammar AST into domain objects for variables, rules, etc. I have other private examples like this.

What could be done for the Rust-specific runtime, is to expose a bunch of traits to mark structures that could be reconstructed from AST/SPPF and use that to produce the domain objects from the AST. Maybe we could hijack serde for this.

The ultimate solution would be to not produce the AST/SPPF at all and use user-configurable logic to build the domain objects, but that is way more complicated.

Ultimately, there is a difference in language theory between the concrete syntax tree, what we call AST/SPPF in Hime, i.e. the tree of tokens in the input ; and the real abstract syntax tree, which is what you mentions, domain objects. Those are separate things and the term AST in a bit of a misnomer in the parser generator ecosystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants