ast icon indicating copy to clipboard operation
ast copied to clipboard

Committing to a conversion

Open CAD97 opened this issue 7 years ago • 1 comments

In order to aid the creation of correct ASTs, it's sometimes useful to know when things go wrong when you don't expect. I propose adding a #[pest_ast(commit)] or similar, after which conversions in the sequence which would otherwise cause a Err(NoMatch) to propagate, instead cause a panic detailing where the error is.

CAD97 avatar Nov 10 '18 07:11 CAD97

This is probably a bit more involved than I'd wish, as it adds state to the conversion where it didn't exist before. However, here's a rough outline of what needs to change to support this:

Best guess: replace the FromPest::from_pest(inner)? with FromPest::from_pest(inner).map_err(|e| if commit { panic!(..) } else { e })?, and add code to manage the commit variable. We can rely on optimizing it out if it's never set.

https://github.com/pest-parser/ast/blob/db9e2b4d57fe61d85f7d3e768d026f0ec95776a7/derive/src/from_pest/field.rs#L58-L70

CAD97 avatar Nov 10 '18 07:11 CAD97