aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/attention.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/construct/attention.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/construct/attention.rs')
-rw-r--r--src/construct/attention.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/construct/attention.rs b/src/construct/attention.rs
index b4265f0..1aa25c0 100644
--- a/src/construct/attention.rs
+++ b/src/construct/attention.rs
@@ -54,7 +54,6 @@
use crate::token::Token;
use crate::tokenizer::{Code, Event, EventType, Point, State, Tokenizer};
use crate::unicode::PUNCTUATION;
-use crate::util::edit_map::EditMap;
/// Character code kinds.
#[derive(Debug, PartialEq)]
@@ -201,7 +200,7 @@ fn inside(tokenizer: &mut Tokenizer, code: Code, marker: MarkerKind) -> State {
/// Resolve attention sequences.
#[allow(clippy::too_many_lines)]
-fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
+fn resolve_attention(tokenizer: &mut Tokenizer) {
let codes = &tokenizer.parse_state.codes;
let mut start = 0;
let mut balance = 0;
@@ -340,7 +339,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
// Remove closing sequence if fully used.
if sequence_close.size == 0 {
sequences.remove(close);
- map.add(close_event_index, 2, vec![]);
+ tokenizer.map.add(close_event_index, 2, vec![]);
} else {
// Shift remaining closing sequence forward.
// Do it here because a sequence can open and close different
@@ -362,7 +361,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
// Remove opening sequence if fully used.
if sequence_open.size == 0 {
sequences.remove(open);
- map.add(open_event_index, 2, vec![]);
+ tokenizer.map.add(open_event_index, 2, vec![]);
next_index -= 1;
} else {
// Shift remaining opening sequence backwards.
@@ -372,7 +371,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
}
// Opening.
- map.add_before(
+ tokenizer.map.add_before(
// Add after the current sequence (it might remain).
open_event_index + 2,
0,
@@ -420,7 +419,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
],
);
// Closing.
- map.add(
+ tokenizer.map.add(
close_event_index,
0,
vec![
@@ -484,8 +483,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
index += 1;
}
- // This resolver is needed.
- true
+ tokenizer.map.consume(&mut tokenizer.events);
}
/// Classify whether a character code represents whitespace, punctuation, or