From 8183323c432fc1359c634feb68bc372e13f0bd03 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 14 Jul 2022 17:40:10 +0200 Subject: Add support for container state * Fix to parse list item continuation based on how big the initial list item prefix was * Fix list items that start with blank lines --- src/util/skip.rs | 18 +++++++++++++----- src/util/span.rs | 4 ++-- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'src/util') 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, } -- cgit