aboutsummaryrefslogtreecommitdiffstats
path: root/src/tokenizer.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-20 18:00:52 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-20 18:00:52 +0200
commit75c2109c6051009b220436bd823970a374f4f9fd (patch)
treec8123e6e4a0a71e2daec77d76c0dc4485bad2240 /src/tokenizer.rs
parent86801cdb3b114b30a14d4b8c01c8fb70b2bcee82 (diff)
downloadmarkdown-rs-75c2109c6051009b220436bd823970a374f4f9fd.tar.gz
markdown-rs-75c2109c6051009b220436bd823970a374f4f9fd.tar.bz2
markdown-rs-75c2109c6051009b220436bd823970a374f4f9fd.zip
Refactor to share edit map
Diffstat (limited to 'src/tokenizer.rs')
-rw-r--r--src/tokenizer.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index cba1752..5d03c92 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -13,6 +13,7 @@
use crate::parser::ParseState;
use crate::token::{Token, VOID_TOKENS};
+use crate::util::edit_map::EditMap;
/// Embedded content type.
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -91,7 +92,7 @@ pub type StateFnResult = (State, Option<Vec<Code>>);
/// Resolvers are supposed to change the list of events, because parsing is
/// sometimes messy, and they help expose a cleaner interface of events to
/// the compiler and other users.
-pub type Resolver = dyn FnOnce(&mut Tokenizer);
+pub type Resolver = dyn FnOnce(&mut Tokenizer, &mut EditMap) -> bool;
/// The result of a state.
pub enum State {
@@ -624,10 +625,24 @@ impl<'a> Tokenizer<'a> {
result = flush_impl(self, func);
self.drained = true;
+ let mut map = EditMap::new();
+ let mut consumed = false;
while !self.resolvers.is_empty() {
let resolver = self.resolvers.remove(0);
- resolver(self);
+ let consume = resolver(self, &mut map);
+
+ if consume {
+ map.consume(&mut self.events);
+ consumed = true;
+ map = EditMap::new();
+ } else {
+ consumed = false;
+ }
+ }
+
+ if !consumed {
+ map.consume(&mut self.events);
}
}