aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util/skip.rs18
-rw-r--r--src/util/span.rs4
2 files changed, 15 insertions, 7 deletions
diff --git a/src/util/skip.rs b/src/util/skip.rs
index 10ba364..d2ad914 100644
--- a/src/util/skip.rs
+++ b/src/util/skip.rs
@@ -5,15 +5,23 @@ use crate::tokenizer::{Event, EventType};
/// Skip from `index`, optionally past `token_types`.
pub fn opt(events: &[Event], index: usize, token_types: &[Token]) -> usize {
- skip_opt_with_direction(events, index, token_types, true)
+ skip_opt_impl(events, index, token_types, true)
}
/// Skip from `index`, optionally past `token_types`, backwards.
pub fn opt_back(events: &[Event], index: usize, token_types: &[Token]) -> usize {
- skip_opt_with_direction(events, index, token_types, false)
+ skip_opt_impl(events, index, token_types, false)
}
-pub fn to(events: &[Event], mut index: usize, token_types: &[Token]) -> usize {
+pub fn to_back(events: &[Event], index: usize, token_types: &[Token]) -> usize {
+ to_impl(events, index, token_types, false)
+}
+
+pub fn to(events: &[Event], index: usize, token_types: &[Token]) -> usize {
+ to_impl(events, index, token_types, true)
+}
+
+pub fn to_impl(events: &[Event], mut index: usize, token_types: &[Token], forward: bool) -> usize {
while index < events.len() {
let current = &events[index].token_type;
@@ -21,14 +29,14 @@ pub fn to(events: &[Event], mut index: usize, token_types: &[Token]) -> usize {
break;
}
- index += 1;
+ index = if forward { index + 1 } else { index - 1 };
}
index
}
/// Skip internals.
-fn skip_opt_with_direction(
+fn skip_opt_impl(
events: &[Event],
mut index: usize,
token_types: &[Token],
diff --git a/src/util/span.rs b/src/util/span.rs
index 32dd00f..72b451d 100644
--- a/src/util/span.rs
+++ b/src/util/span.rs
@@ -6,9 +6,9 @@ use crate::util::codes::serialize as serialize_codes;
/// A struct representing the span of an opening and closing event of a token.
#[derive(Debug)]
pub struct Span {
- /// Absolute offset (and `index` in `codes`) of where this span starts.
+ /// Absolute offset (an `index` in `codes`) of where this span starts.
pub start_index: usize,
- /// Absolute offset (and `index` in `codes`) of where this span ends.
+ /// Absolute offset (an `index` in `codes`) of where this span ends.
pub end_index: usize,
}