Created
November 30, 2016 21:38
-
-
Save fero23/9c34caaf34eb3d06d9fff4e16a3d7400 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Test grammar: | |
glurp_grammar! { | |
R: String => { Optional(R) ~ Char('R') } on {|opt, r| { | |
if Some(acc) = opt { | |
push(r); | |
acc | |
} else { | |
String::new() | |
} | |
}}; | |
} | |
Test: | |
let mut parser = Parser::new(); | |
parser.start_from(R); | |
println!("{:#?}", parser.parse("RRRRRR")); | |
Result: | |
Ok( | |
[ | |
Node { | |
rule: 1, | |
alt: 0, | |
children: [ | |
Node { | |
rule: 2, | |
alt: 0, | |
children: [ | |
Node { | |
rule: 1, | |
alt: 0, | |
children: [ | |
Node { | |
rule: 2, | |
alt: 0, | |
children: [ | |
Node { | |
rule: 1, | |
alt: 0, | |
children: [ | |
Node { | |
rule: 2, | |
alt: 0, | |
children: [ | |
Node { | |
rule: 1, | |
alt: 0, | |
children: [ | |
Node { | |
rule: 2, | |
alt: 0, | |
children: [ | |
Node { | |
rule: 1, | |
alt: 0, | |
children: [ | |
Node { | |
rule: 2, | |
alt: 0, | |
children: [ | |
Node { | |
rule: 1, | |
alt: 0, | |
children: [ | |
EmptyNode, | |
Node { | |
rule: 3, | |
alt: 0, | |
children: [ | |
Leaf( | |
'R' | |
) | |
] | |
} | |
] | |
} | |
] | |
}, | |
Node { | |
rule: 3, | |
alt: 0, | |
children: [ | |
Leaf( | |
'R' | |
) | |
] | |
} | |
] | |
} | |
] | |
}, | |
Node { | |
rule: 3, | |
alt: 0, | |
children: [ | |
Leaf( | |
'R' | |
) | |
] | |
} | |
] | |
} | |
] | |
}, | |
Node { | |
rule: 3, | |
alt: 0, | |
children: [ | |
Leaf( | |
'R' | |
) | |
] | |
} | |
] | |
} | |
] | |
}, | |
Node { | |
rule: 3, | |
alt: 0, | |
children: [ | |
Leaf( | |
'R' | |
) | |
] | |
} | |
] | |
} | |
] | |
}, | |
Node { | |
rule: 3, | |
alt: 0, | |
children: [ | |
Leaf( | |
'R' | |
) | |
] | |
} | |
] | |
} | |
] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment