diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-09-07 15:53:06 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-09-07 15:53:06 +0200 |
commit | 1d92666865b35341e076efbefddf6e73b5e1542e (patch) | |
tree | 11c05985ec7679f73473e7ea2c769465698e2f08 /src/tokenizer.rs | |
parent | e6018e52ee6ad9a8f8a0672b75bf515faf74af1f (diff) | |
download | markdown-rs-1d92666865b35341e076efbefddf6e73b5e1542e.tar.gz markdown-rs-1d92666865b35341e076efbefddf6e73b5e1542e.tar.bz2 markdown-rs-1d92666865b35341e076efbefddf6e73b5e1542e.zip |
Add support for recoverable syntax errors
Diffstat (limited to 'src/tokenizer.rs')
-rw-r--r-- | src/tokenizer.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 8843e47..7dbd158 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -616,11 +616,12 @@ impl<'a> Tokenizer<'a> { } /// Flush. - pub fn flush(&mut self, state: State, resolve: bool) { + pub fn flush(&mut self, state: State, resolve: bool) -> Result<(), String> { let to = (self.point.index, self.point.vs); - push_impl(self, to, to, state, true); + let state = push_impl(self, to, to, state, true); + let result = state.to_result(); - if resolve { + if resolve && result.is_ok() { let resolvers = self.resolvers.split_off(0); let mut index = 0; while index < resolvers.len() { @@ -630,6 +631,8 @@ impl<'a> Tokenizer<'a> { self.map.consume(&mut self.events); } + + result } } @@ -678,6 +681,7 @@ fn push_impl( loop { match state { + State::Error(_) => break, State::Ok | State::Nok => { if let Some(attempt) = tokenizer.attempts.pop() { if attempt.kind == AttemptKind::Check || state == State::Nok { @@ -743,9 +747,12 @@ fn push_impl( tokenizer.consumed = true; if flush { - debug_assert!(matches!(state, State::Ok), "must be ok"); + debug_assert!(matches!(state, State::Ok | State::Error(_)), "must be ok"); } else { - debug_assert!(matches!(state, State::Next(_)), "must have a next state"); + debug_assert!( + matches!(state, State::Next(_) | State::Error(_)), + "must have a next state" + ); } state |