From 0eeff9148e327183e532752f46421a75506dd7a6 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 29 Jul 2022 18:22:59 +0200 Subject: Refactor to improve states * Remove custom kind wrappers, use plain bytes instead * Remove `Into`s, use the explicit expected types instead * Refactor to use `slice.as_str` in most places * Remove unneeded unique check before adding a definition * Use a shared CDATA prefix in constants * Inline byte checks into matches * Pass bytes back from parser instead of whole parse state * Refactor to work more often on bytes * Rename custom `size` to `len` --- src/construct/code_indented.rs | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src/construct/code_indented.rs') diff --git a/src/construct/code_indented.rs b/src/construct/code_indented.rs index 4a3a9f6..81a3080 100644 --- a/src/construct/code_indented.rs +++ b/src/construct/code_indented.rs @@ -62,11 +62,11 @@ use crate::tokenizer::{State, Tokenizer}; /// ``` pub fn start(tokenizer: &mut Tokenizer) -> State { // Do not interrupt paragraphs. - if tokenizer.interrupt || !tokenizer.parse_state.constructs.code_indented { - State::Nok - } else { + if !tokenizer.interrupt && tokenizer.parse_state.constructs.code_indented { tokenizer.enter(Token::CodeIndented); tokenizer.go(space_or_tab_min_max(TAB_SIZE, TAB_SIZE), at_break)(tokenizer) + } else { + State::Nok } } @@ -129,29 +129,26 @@ fn after(tokenizer: &mut Tokenizer) -> State { /// | bbb /// ``` fn further_start(tokenizer: &mut Tokenizer) -> State { - if tokenizer.lazy { - State::Nok - } else { - match tokenizer.current { - Some(b'\n') => { - tokenizer.enter(Token::LineEnding); - tokenizer.consume(); - tokenizer.exit(Token::LineEnding); - State::Fn(Box::new(further_start)) - } - _ => tokenizer.attempt(space_or_tab_min_max(TAB_SIZE, TAB_SIZE), |ok| { - Box::new(if ok { further_end } else { further_begin }) - })(tokenizer), + match tokenizer.current { + Some(b'\n') if !tokenizer.lazy => { + tokenizer.enter(Token::LineEnding); + tokenizer.consume(); + tokenizer.exit(Token::LineEnding); + State::Fn(Box::new(further_start)) } + _ if !tokenizer.lazy => tokenizer.attempt(space_or_tab_min_max(TAB_SIZE, TAB_SIZE), |ok| { + Box::new(if ok { further_end } else { further_begin }) + })(tokenizer), + _ => State::Nok, } } -/// After a proper indent. +/// At an eol, which is followed by an indented line. /// /// ```markdown -/// | aaa -/// > | bbb -/// ^ +/// > | aaa +/// ^ +/// | bbb /// ``` fn further_end(_tokenizer: &mut Tokenizer) -> State { State::Ok -- cgit