Skip to content

Collecting elements between branches #394

Closed Answered by kevinmehall
oovm asked this question in Q&A
Discussion options

You must be logged in to vote

I'd probably write that as

struct Expr {
    a: Option<char>,
    b: Option<char>,
}
peg::parser!( grammar example() for str {
    pub rule select() -> Expr
        = a:a() { Expr { a: Some(a), b: None } }
        / b:b() { Expr { a: None, b: Some(b) } }
   
    rule a() -> char = "a" { 'a' }
    rule b() -> char = "b" { 'b' }
});

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@oovm
Comment options

Answer selected by oovm
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #393 on December 26, 2024 18:53.