aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct
diff options
context:
space:
mode:
Diffstat (limited to 'src/construct')
-rw-r--r--src/construct/attention.rs66
-rw-r--r--src/construct/heading_atx.rs2
-rw-r--r--src/construct/label_end.rs16
-rw-r--r--src/construct/list.rs3
-rw-r--r--src/construct/paragraph.rs2
-rw-r--r--src/construct/partial_data.rs6
6 files changed, 29 insertions, 66 deletions
diff --git a/src/construct/attention.rs b/src/construct/attention.rs
index ac6aecf..38164a8 100644
--- a/src/construct/attention.rs
+++ b/src/construct/attention.rs
@@ -153,12 +153,8 @@ struct Sequence {
event_index: usize,
/// The (shifted) point where this sequence starts.
start_point: Point,
- /// The (shifted) index where this sequence starts.
- start_index: usize,
/// The (shifted) point where this sequence end.
end_point: Point,
- /// The (shifted) index where this sequence end.
- end_index: usize,
/// The number of markers we can still use.
size: usize,
/// Whether this sequence can open attention.
@@ -221,14 +217,14 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
if enter.token_type == Token::AttentionSequence {
let end = start + 1;
let exit = &tokenizer.events[end];
- let marker = MarkerKind::from_code(codes[enter.index]);
- let before = classify_character(if enter.index > 0 {
- codes[enter.index - 1]
+ let marker = MarkerKind::from_code(codes[enter.point.index]);
+ let before = classify_character(if enter.point.index > 0 {
+ codes[enter.point.index - 1]
} else {
Code::None
});
- let after = classify_character(if exit.index < codes.len() {
- codes[exit.index]
+ let after = classify_character(if exit.point.index < codes.len() {
+ codes[exit.point.index]
} else {
Code::None
});
@@ -245,10 +241,8 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
event_index: start,
balance,
start_point: enter.point.clone(),
- start_index: enter.index,
end_point: exit.point.clone(),
- end_index: exit.index,
- size: exit.index - enter.index,
+ size: exit.point.index - enter.point.index,
open: if marker == MarkerKind::Asterisk {
open
} else {
@@ -332,18 +326,12 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
let sequence_close = &mut sequences[close];
let close_event_index = sequence_close.event_index;
- let seq_close_enter = (
- sequence_close.start_point.clone(),
- sequence_close.start_index,
- );
+ let seq_close_enter = sequence_close.start_point.clone();
sequence_close.size -= take;
sequence_close.start_point.column += take;
sequence_close.start_point.offset += take;
- sequence_close.start_index += take;
- let seq_close_exit = (
- sequence_close.start_point.clone(),
- sequence_close.start_index,
- );
+ sequence_close.start_point.index += take;
+ let seq_close_exit = sequence_close.start_point.clone();
// Stay on this closing sequence for the next iteration: it
// might close more things.
@@ -359,18 +347,17 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
// other sequences, and the remainder can be on any side or
// somewhere in the middle.
let mut enter = &mut tokenizer.events[close_event_index];
- enter.point = seq_close_exit.0.clone();
- enter.index = seq_close_exit.1;
+ enter.point = seq_close_exit.clone();
}
let sequence_open = &mut sequences[open];
let open_event_index = sequence_open.event_index;
- let seq_open_exit = (sequence_open.end_point.clone(), sequence_open.end_index);
+ let seq_open_exit = sequence_open.end_point.clone();
sequence_open.size -= take;
sequence_open.end_point.column -= take;
sequence_open.end_point.offset -= take;
- sequence_open.end_index -= take;
- let seq_open_enter = (sequence_open.end_point.clone(), sequence_open.end_index);
+ sequence_open.end_point.index -= take;
+ let seq_open_enter = sequence_open.end_point.clone();
// Remove opening sequence if fully used.
if sequence_open.size == 0 {
@@ -381,8 +368,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
// Shift remaining opening sequence backwards.
// See note above for why that happens here.
let mut exit = &mut tokenizer.events[open_event_index + 1];
- exit.point = seq_open_enter.0.clone();
- exit.index = seq_open_enter.1;
+ exit.point = seq_open_enter.clone();
}
// Opening.
@@ -398,8 +384,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
} else {
Token::Strong
},
- point: seq_open_enter.0.clone(),
- index: seq_open_enter.1,
+ point: seq_open_enter.clone(),
link: None,
},
Event {
@@ -409,8 +394,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
} else {
Token::StrongSequence
},
- point: seq_open_enter.0.clone(),
- index: seq_open_enter.1,
+ point: seq_open_enter.clone(),
link: None,
},
Event {
@@ -420,8 +404,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
} else {
Token::StrongSequence
},
- point: seq_open_exit.0.clone(),
- index: seq_open_exit.1,
+ point: seq_open_exit.clone(),
link: None,
},
Event {
@@ -431,8 +414,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
} else {
Token::StrongText
},
- point: seq_open_exit.0.clone(),
- index: seq_open_exit.1,
+ point: seq_open_exit.clone(),
link: None,
},
],
@@ -449,8 +431,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
} else {
Token::StrongText
},
- point: seq_close_enter.0.clone(),
- index: seq_close_enter.1,
+ point: seq_close_enter.clone(),
link: None,
},
Event {
@@ -460,8 +441,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
} else {
Token::StrongSequence
},
- point: seq_close_enter.0.clone(),
- index: seq_close_enter.1,
+ point: seq_close_enter.clone(),
link: None,
},
Event {
@@ -471,8 +451,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
} else {
Token::StrongSequence
},
- point: seq_close_exit.0.clone(),
- index: seq_close_exit.1,
+ point: seq_close_exit.clone(),
link: None,
},
Event {
@@ -482,8 +461,7 @@ fn resolve_attention(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
} else {
Token::Strong
},
- point: seq_close_exit.0.clone(),
- index: seq_close_exit.1,
+ point: seq_close_exit.clone(),
link: None,
},
],
diff --git a/src/construct/heading_atx.rs b/src/construct/heading_atx.rs
index 0e4cda5..e544064 100644
--- a/src/construct/heading_atx.rs
+++ b/src/construct/heading_atx.rs
@@ -216,7 +216,6 @@ pub fn resolve(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
event_type: EventType::Enter,
token_type: Token::HeadingAtxText,
point: tokenizer.events[start].point.clone(),
- index: tokenizer.events[start].index,
link: None,
}],
);
@@ -231,7 +230,6 @@ pub fn resolve(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
event_type: EventType::Exit,
token_type: Token::HeadingAtxText,
point: tokenizer.events[end].point.clone(),
- index: tokenizer.events[end].index,
link: None,
}],
);
diff --git a/src/construct/label_end.rs b/src/construct/label_end.rs
index 883e314..2dd8222 100644
--- a/src/construct/label_end.rs
+++ b/src/construct/label_end.rs
@@ -216,8 +216,8 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
id: normalize_identifier(&serialize(
&tokenizer.parse_state.codes,
&Span {
- start_index: tokenizer.events[label_start.start.1].index,
- end_index: tokenizer.events[label_end_start - 1].index,
+ start_index: tokenizer.events[label_start.start.1].point.index,
+ end_index: tokenizer.events[label_end_start - 1].point.index,
},
false,
)),
@@ -538,9 +538,9 @@ fn full_reference_after(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult
let event = &events[index];
if event.token_type == Token::ReferenceString {
if event.event_type == EventType::Exit {
- end = Some(event.index);
+ end = Some(event.point.index);
} else {
- start = Some(event.index);
+ start = Some(event.point.index);
break;
}
}
@@ -635,14 +635,12 @@ pub fn resolve_media(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
event_type: EventType::Enter,
token_type: Token::Data,
point: events[data_enter_index].point.clone(),
- index: events[data_enter_index].index,
link: None,
},
Event {
event_type: EventType::Exit,
token_type: Token::Data,
point: events[data_exit_index].point.clone(),
- index: events[data_exit_index].index,
link: None,
},
],
@@ -685,14 +683,12 @@ pub fn resolve_media(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
Token::Image
},
point: group_enter_event.point.clone(),
- index: group_enter_event.index,
link: None,
},
Event {
event_type: EventType::Enter,
token_type: Token::Label,
point: group_enter_event.point.clone(),
- index: group_enter_event.index,
link: None,
},
],
@@ -708,7 +704,6 @@ pub fn resolve_media(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
event_type: EventType::Enter,
token_type: Token::LabelText,
point: events[text_enter_index].point.clone(),
- index: events[text_enter_index].index,
link: None,
}],
);
@@ -721,7 +716,6 @@ pub fn resolve_media(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
event_type: EventType::Exit,
token_type: Token::LabelText,
point: events[text_exit_index].point.clone(),
- index: events[text_exit_index].index,
link: None,
}],
);
@@ -735,7 +729,6 @@ pub fn resolve_media(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
event_type: EventType::Exit,
token_type: Token::Label,
point: events[label_exit_index].point.clone(),
- index: events[label_exit_index].index,
link: None,
}],
);
@@ -748,7 +741,6 @@ pub fn resolve_media(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
event_type: EventType::Exit,
token_type: Token::Link,
point: events[group_end_index].point.clone(),
- index: events[group_end_index].index,
link: None,
}],
);
diff --git a/src/construct/list.rs b/src/construct/list.rs
index 12c666b..06be7ec 100644
--- a/src/construct/list.rs
+++ b/src/construct/list.rs
@@ -317,7 +317,8 @@ fn after(tokenizer: &mut Tokenizer, code: Code, blank: bool) -> StateFnResult {
tokenizer.events.len() - 1,
&[Token::ListItem],
);
- let prefix = tokenizer.index - tokenizer.events[start].index + (if blank { 1 } else { 0 });
+ let prefix = tokenizer.point.index - tokenizer.events[start].point.index
+ + (if blank { 1 } else { 0 });
let container = tokenizer.container.as_mut().unwrap();
container.blank_initial = blank;
diff --git a/src/construct/paragraph.rs b/src/construct/paragraph.rs
index 3932ad8..a2eb6ff 100644
--- a/src/construct/paragraph.rs
+++ b/src/construct/paragraph.rs
@@ -112,10 +112,8 @@ pub fn resolve(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
// Add Exit:LineEnding position info to Exit:Data.
let line_ending_exit = &tokenizer.events[exit_index + 2];
let line_ending_point = line_ending_exit.point.clone();
- let line_ending_index = line_ending_exit.index;
let data_exit = &mut tokenizer.events[exit_index - 1];
data_exit.point = line_ending_point;
- data_exit.index = line_ending_index;
// Link Enter:Data on the previous line to Enter:Data on this line.
if let Some(link) = &mut tokenizer.events[exit_index - 2].link {
diff --git a/src/construct/partial_data.rs b/src/construct/partial_data.rs
index ea71bcf..ceeb89b 100644
--- a/src/construct/partial_data.rs
+++ b/src/construct/partial_data.rs
@@ -99,11 +99,7 @@ pub fn resolve_data(tokenizer: &mut Tokenizer, map: &mut EditMap) -> bool {
// Change positional info.
let exit_far = &tokenizer.events[exit_far_index];
- let point_end = exit_far.point.clone();
- let index_end = exit_far.index;
- let exit = &mut tokenizer.events[exit_index];
- exit.point = point_end;
- exit.index = index_end;
+ tokenizer.events[exit_index].point = exit_far.point.clone();
index = exit_far_index;
continue;