diff options
Diffstat (limited to 'src/compiler.rs')
| -rw-r--r-- | src/compiler.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index d12ee4b..bd23cd8 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -39,6 +39,37 @@ macro_rules! expect { }; } +macro_rules! parse_branch { + ($compiler:expr, $block:expr, [ $( $call:expr ),* ]) => { + let block_length = $block.ops.len(); + let token_length = $compiler.curr; + let num_errors = $compiler.errors.len(); + let mut stored_errors = Vec::new(); + let mut success = false; + // We risk getting a lot of errors if we are in an invalid state + // when we start the parse. + while !$compiler.panic { + $( + $call; + if !$compiler.panic { + success = true; + break; + } + $compiler.panic = false; + $compiler.curr = token_length; + let thrown_errors = $compiler.errors.len() - num_errors - 1; + stored_errors.extend($compiler.errors.split_off(thrown_errors)); + $block.ops.truncate(block_length); + )* + break; + } + + if !success { + $compiler.errors.extend(stored_errors); + } + }; +} + nextable_enum!(Prec { No, Assert, |
