We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi, I'm trying pest-ast for my project. So far, it's been super-helpful.
Now, I have a few cases for which I cannot find a type mapping. i have looked in issues, in the examples of pest-ast and the examples of derive.
pest-ast
derive
comparison = { arith_expr ~ (comp_op ~ arith_expr)* }
In #8, I see an example:
struct assigns<'pest>( #[pest_ast(outer)] Span<'pest>, Vec<struct _1(assign<'pest>)>, assign<'pest>, );
But Vec<struct _1(assign<'pest>)> is not a valid Rust, there are no anonymous structs.
Vec<struct _1(assign<'pest>)>
I can try to extract a named struct, but there is no grammar rule to put into pest_ast, and pest_ast is required:
pest_ast
#[derive(Debug, FromPest)] // FIXME: This probably shouldn't work! #[pest_ast(rule(Rule::comparison))] pub struct ComparisonPart2 { pub op: CompOr, pub expr: ArithExpr } #[derive(Debug, FromPest)] #[pest_ast(rule(Rule::comparison))] // comparison = { arith_expr ~ (comp_op ~ arith_expr)* } pub struct Comparison { pub expr: ArithExpr, pub continuation: Vec<ComparisonPart2>, // pub continuation: Vec<(CompOr, ArithExpr)>, }
I'm not sure it will work (I haven't finished a mapping for my grammar yet).
arith_expr = { term ~ ((plus|minus) ~ term)* } How do I map the (plus|minus) part? To an enum like this?
arith_expr = { term ~ ((plus|minus) ~ term)* }
(plus|minus)
#[derive(Debug, FromPest)] #[pest_ast(rule(Rule::plus))] pub struct Plus { } #[derive(Debug, FromPest)] #[pest_ast(rule(Rule::minus))] pub struct Minus { } #[derive(Debug, FromPest)] #[pest_ast(rule(Rule::arith_expr))] pub enum PlusMinus { Plus{ plus: Plus }, Minus{ minus: Minus }, } #[derive(Debug, FromPest)] #[pest_ast(rule(Rule::arith_expr))] pub struct ArithExprPart2 { pub op: PlusMinus, pub term: Term, } #[derive(Debug, FromPest)] #[pest_ast(rule(Rule::arith_expr))] // arith_expr = { term ~ ((plus|minus) ~ term)* } pub struct ArithExpr { pub term: Term, pub tail: Vec<ArithExprPart2> }
It would be great to have a such example. It would be a bit less great to know it's impossible as of now.
Thank you!
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hi, I'm trying pest-ast for my project. So far, it's been super-helpful.
Now, I have a few cases for which I cannot find a type mapping. i have looked in issues, in the examples of
pest-ast
and the examples ofderive
.A repetition of an anonymous sequence
comparison = { arith_expr ~ (comp_op ~ arith_expr)* }
In #8, I see an example:
But
Vec<struct _1(assign<'pest>)>
is not a valid Rust, there are no anonymous structs.I can try to extract a named struct, but there is no grammar rule to put into
pest_ast
, andpest_ast
is required:I'm not sure it will work (I haven't finished a mapping for my grammar yet).
A nested choice
arith_expr = { term ~ ((plus|minus) ~ term)* }
How do I map the
(plus|minus)
part? To an enum like this?It would be great to have a such example. It would be a bit less great to know it's impossible as of now.
Thank you!
The text was updated successfully, but these errors were encountered: