You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This makes the parser only collect module AST nodes first into the modules vector, then once its finished, the parser collects the function AST nodes into the functions vector.
This is problematic, and restricts the language I want to develop.
Mainly, code like this, fail to parse ...
mod core {fnx(){// okay so far}mod y {// error: parser crashes, // since it expects all modules to exist before functions, // so it can not process this random module that exists out of place.}}
After many hours of trial and error, I figured out how to solve this.
We need to represent the nested items as an enum, and store those items into a vector.
Hi everyone,
I'm loving using pest for building a compiler.
I would request to collect the common issues that happen while using pest from users, and documenting them.
To help pest maintainers in this effort, we can collect the common issues we faced, along with how we solved them.
Using our testimonials, pest maintainers can prepare better documentation for future users.
If it's okay with everyone, I will start.
How to parse recursive nested AST nodes using rust/pest/pest-ast?
Using pest-ast, it took me few hours to figure out how to represent a grammar of "A module can contain modules and functions"
Initially I thought this representation would work, but it doesn't:
This makes the parser only collect module AST nodes first into the
modules
vector, then once its finished, the parser collects the function AST nodes into thefunctions
vector.This is problematic, and restricts the language I want to develop.
Mainly, code like this, fail to parse ...
After many hours of trial and error, I figured out how to solve this.
We need to represent the nested items as an enum, and store those items into a vector.
This works perfectly!
So, if it's okay with pest maintainers,
I would request other users to also report their issues, and also report if/how they fixed them.
Thanks!
The text was updated successfully, but these errors were encountered: