aboutsummaryrefslogtreecommitdiffstats
path: root/src/tokenizer.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-22 18:46:33 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-22 18:57:19 +0200
commitbac358ee5c341729e50630f2569a69b4d580ce47 (patch)
tree9ea5f311dcad46e54dfaa55a2985c75925ff6c83 /src/tokenizer.rs
parent0525454e33ed6bcd7b43da1c0969c1d592e743d9 (diff)
downloadmarkdown-rs-bac358ee5c341729e50630f2569a69b4d580ce47.tar.gz
markdown-rs-bac358ee5c341729e50630f2569a69b4d580ce47.tar.bz2
markdown-rs-bac358ee5c341729e50630f2569a69b4d580ce47.zip
Refactor to use a single shared edit map
Diffstat (limited to 'src/tokenizer.rs')
-rw-r--r--src/tokenizer.rs23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index 685198e..eb8bac4 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -95,7 +95,7 @@ pub type StateFn = dyn FnOnce(&mut Tokenizer, Code) -> State;
/// 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, &mut EditMap) -> bool;
+pub type Resolver = dyn FnOnce(&mut Tokenizer);
/// The result of a state.
pub enum State {
@@ -191,6 +191,8 @@ pub struct Tokenizer<'a> {
pub stack: Vec<Token>,
/// Previous character code.
pub previous: Code,
+ /// To do.
+ pub map: EditMap,
/// Current character code.
current: Code,
/// Current relative and absolute place in the file.
@@ -246,6 +248,7 @@ impl<'a> Tokenizer<'a> {
stack: vec![],
events: vec![],
parse_state,
+ map: EditMap::new(),
label_start_stack: vec![],
label_start_list_loose: vec![],
media_list: vec![],
@@ -255,7 +258,7 @@ impl<'a> Tokenizer<'a> {
container: None,
// Assume about 10 resolvers.
resolvers: Vec::with_capacity(10),
- resolver_ids: Vec::with_capacity(10)
+ resolver_ids: Vec::with_capacity(10),
}
}
@@ -635,25 +638,13 @@ 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);
- let consume = resolver(self, &mut map);
-
- if consume {
- map.consume(&mut self.events);
- consumed = true;
- map = EditMap::new();
- } else {
- consumed = false;
- }
+ resolver(self);
}
- if !consumed {
- map.consume(&mut self.events);
- }
+ self.map.consume(&mut self.events);
}
result