Add a way to specify a parser stack limit#308
Add a way to specify a parser stack limit#308zsol wants to merge 4 commits intokevinmehall:masterfrom
Conversation
I don't think it's workable to treat reaching the stack limit as a simple parse failure because it will cause For example, with the grammar peg::parser! { grammar test() for str {
stack_limit 2;
rule keyword() -> Expr
= "foo" { Expr::Foo }
/ "bar" { Expr::Bar }
pub rule expr() -> Expr
= "(" e: expr() ")" { e }
/ keyword()
/ v:$(['a'..='z']+) { Expr::Variable(v.to_string()) }
}}the input |
TODO:
STACK OVERFLOWexpected string to something nicerThis PR implements a new
stack_limitdirective in the meta grammar. When specified, the generated parser will keep track of rule invocation depth and error out when the depth is beyond the specified maximum.I'm not married to any of the naming and syntax here, feel free to suggest better alternatives.
A better way of raising errors from this might be to introduce a new
RuleResultvariant that immediately terminates parsing instead of carrying on with alternatives. I think that's a great future improvement, but didn't consider for this PR because it would expand the scope quite a bit.Fixes #282. This PR depends on #307.