diff options
Diffstat (limited to '')
-rw-r--r-- | src/util/skip.rs | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/src/util/skip.rs b/src/util/skip.rs index d2ad914..371418f 100644 --- a/src/util/skip.rs +++ b/src/util/skip.rs @@ -1,31 +1,30 @@ //! Utilities to deal with lists of events. -use crate::token::Token; -use crate::tokenizer::{Event, EventType}; +use crate::event::{Event, Kind, Name}; -/// Skip from `index`, optionally past `token_types`. -pub fn opt(events: &[Event], index: usize, token_types: &[Token]) -> usize { - skip_opt_impl(events, index, token_types, true) +/// Skip from `index`, optionally past `names`. +pub fn opt(events: &[Event], index: usize, names: &[Name]) -> usize { + skip_opt_impl(events, index, names, true) } -/// Skip from `index`, optionally past `token_types`, backwards. -pub fn opt_back(events: &[Event], index: usize, token_types: &[Token]) -> usize { - skip_opt_impl(events, index, token_types, false) +/// Skip from `index`, optionally past `names`, backwards. +pub fn opt_back(events: &[Event], index: usize, names: &[Name]) -> usize { + skip_opt_impl(events, index, names, false) } -pub fn to_back(events: &[Event], index: usize, token_types: &[Token]) -> usize { - to_impl(events, index, token_types, false) +pub fn to_back(events: &[Event], index: usize, names: &[Name]) -> usize { + to_impl(events, index, names, false) } -pub fn to(events: &[Event], index: usize, token_types: &[Token]) -> usize { - to_impl(events, index, token_types, true) +pub fn to(events: &[Event], index: usize, names: &[Name]) -> usize { + to_impl(events, index, names, true) } -pub fn to_impl(events: &[Event], mut index: usize, token_types: &[Token], forward: bool) -> usize { +pub fn to_impl(events: &[Event], mut index: usize, names: &[Name], forward: bool) -> usize { while index < events.len() { - let current = &events[index].token_type; + let current = &events[index].name; - if token_types.contains(current) { + if names.contains(current) { break; } @@ -36,23 +35,14 @@ pub fn to_impl(events: &[Event], mut index: usize, token_types: &[Token], forwar } /// Skip internals. -fn skip_opt_impl( - events: &[Event], - mut index: usize, - token_types: &[Token], - forward: bool, -) -> usize { +fn skip_opt_impl(events: &[Event], mut index: usize, names: &[Name], forward: bool) -> usize { let mut balance = 0; - let open = if forward { - EventType::Enter - } else { - EventType::Exit - }; + let open = if forward { Kind::Enter } else { Kind::Exit }; while index < events.len() { - let current = &events[index].token_type; + let current = &events[index].name; - if !token_types.contains(current) || events[index].event_type != open { + if !names.contains(current) || events[index].kind != open { break; } @@ -60,13 +50,13 @@ fn skip_opt_impl( balance += 1; loop { - balance = if events[index].event_type == open { + balance = if events[index].kind == open { balance + 1 } else { balance - 1 }; - if events[index].token_type == *current && balance == 0 { + if events[index].name == *current && balance == 0 { index = if forward { index + 1 } else { index - 1 }; break; } |