diff options
Diffstat (limited to '')
-rw-r--r-- | src/content/document.rs | 57 | ||||
-rw-r--r-- | src/content/flow.rs | 24 | ||||
-rw-r--r-- | src/content/string.rs | 8 | ||||
-rw-r--r-- | src/content/text.rs | 8 |
4 files changed, 37 insertions, 60 deletions
diff --git a/src/content/document.rs b/src/content/document.rs index 163dcda..f2c73e4 100644 --- a/src/content/document.rs +++ b/src/content/document.rs @@ -17,8 +17,7 @@ use crate::parser::ParseState; use crate::subtokenize::subtokenize; use crate::token::Token; use crate::tokenizer::{ - Code, Container, ContainerState, Event, EventType, Point, State, StateFn, StateFnResult, - Tokenizer, + Code, Container, ContainerState, Event, EventType, Point, State, StateFn, Tokenizer, }; use crate::util::edit_map::EditMap; use crate::util::{ @@ -122,7 +121,7 @@ pub fn document(parse_state: &mut ParseState, point: Point) -> Vec<Event> { /// ^ /// | > b /// ``` -fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { +fn start(tokenizer: &mut Tokenizer, code: Code) -> State { let info = DocumentInfo { index: 0, continued: 0, @@ -143,7 +142,7 @@ fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { /// > | > b /// ^ /// ``` -fn line_start(tokenizer: &mut Tokenizer, code: Code, mut info: DocumentInfo) -> StateFnResult { +fn line_start(tokenizer: &mut Tokenizer, code: Code, mut info: DocumentInfo) -> State { info.index = tokenizer.events.len(); info.inject.push((vec![], vec![])); info.continued = 0; @@ -163,7 +162,7 @@ fn container_existing_before( tokenizer: &mut Tokenizer, code: Code, mut info: DocumentInfo, -) -> StateFnResult { +) -> State { // If there are more existing containers, check whether the next one continues. if info.continued < info.stack.len() { let container = info.stack.remove(info.continued); @@ -198,7 +197,7 @@ fn container_existing_missing( tokenizer: &mut Tokenizer, code: Code, mut info: DocumentInfo, -) -> StateFnResult { +) -> State { let container = tokenizer.container.take().unwrap(); info.stack.insert(info.continued, container); container_new_before(tokenizer, code, info) @@ -215,7 +214,7 @@ fn container_existing_after( tokenizer: &mut Tokenizer, code: Code, mut info: DocumentInfo, -) -> StateFnResult { +) -> State { let container = tokenizer.container.take().unwrap(); info.stack.insert(info.continued, container); info.continued += 1; @@ -230,11 +229,7 @@ fn container_existing_after( /// > | > b /// ^ /// ``` -fn container_new_before( - tokenizer: &mut Tokenizer, - code: Code, - info: DocumentInfo, -) -> StateFnResult { +fn container_new_before(tokenizer: &mut Tokenizer, code: Code, info: DocumentInfo) -> State { // If we have completely continued, restore the flow’s past `interrupt` // status. if info.continued == info.stack.len() { @@ -288,11 +283,7 @@ fn container_new_before( /// > | > b /// ^ /// ``` -fn container_new_after( - tokenizer: &mut Tokenizer, - code: Code, - mut info: DocumentInfo, -) -> StateFnResult { +fn container_new_after(tokenizer: &mut Tokenizer, code: Code, mut info: DocumentInfo) -> State { let container = tokenizer.container.take().unwrap(); // Remove from the event stack. @@ -340,11 +331,7 @@ fn container_new_after( /// > | > b /// ^ /// ``` -fn containers_after( - tokenizer: &mut Tokenizer, - code: Code, - mut info: DocumentInfo, -) -> StateFnResult { +fn containers_after(tokenizer: &mut Tokenizer, code: Code, mut info: DocumentInfo) -> State { // Store the container events we parsed. info.inject .last_mut() @@ -363,12 +350,7 @@ fn containers_after( tokenizer.go_until( state, |code| matches!(code, Code::CarriageReturnLineFeed | Code::Char('\n' | '\r')), - move |(state, back)| { - ( - State::Fn(Box::new(move |t, c| flow_end(t, c, info, state))), - back, - ) - }, + move |state| Box::new(move |t, c| flow_end(t, c, info, state)), )(tokenizer, code) } @@ -379,12 +361,7 @@ fn containers_after( /// > | > b /// ^ ^ /// ``` -fn flow_end( - tokenizer: &mut Tokenizer, - code: Code, - mut info: DocumentInfo, - result: State, -) -> StateFnResult { +fn flow_end(tokenizer: &mut Tokenizer, code: Code, mut info: DocumentInfo, result: State) -> State { let paragraph = !tokenizer.events.is_empty() && tokenizer.events[skip::opt_back( &tokenizer.events, @@ -407,15 +384,16 @@ fn flow_end( info.interrupt_before = tokenizer.interrupt; match result { - State::Ok => { + State::Ok(back) => { + assert_eq!(back, 0); + if !info.stack.is_empty() { info.continued = 0; info = exit_containers(tokenizer, info, &Phase::Eof); } resolve(tokenizer, &mut info); - - (State::Ok, if matches!(code, Code::None) { 0 } else { 1 }) + result } State::Nok => unreachable!("unexpected `nok` from flow"), State::Fn(func) => { @@ -440,8 +418,7 @@ fn exit_containers( let next = info.next; info.next = Box::new(flow); // This is weird but Rust needs a function there. let result = tokenizer.flush(next); - assert!(matches!(result.0, State::Ok)); - assert_eq!(result.1, 0); + assert!(matches!(result, State::Ok(0))); if *phase == Phase::Prefix { info.index = tokenizer.events.len(); @@ -481,7 +458,7 @@ fn resolve(tokenizer: &mut Tokenizer, info: &mut DocumentInfo) { let mut index = 0; let mut inject = info.inject.split_off(0); inject.reverse(); - let mut first_line_ending_in_run: Option<usize> = None; + let mut first_line_ending_in_run = None; while let Some((before, mut after)) = inject.pop() { if !before.is_empty() { diff --git a/src/content/flow.rs b/src/content/flow.rs index 722e2bb..8aed92b 100644 --- a/src/content/flow.rs +++ b/src/content/flow.rs @@ -27,7 +27,7 @@ use crate::construct::{ thematic_break::start as thematic_break, }; use crate::token::Token; -use crate::tokenizer::{Code, State, StateFnResult, Tokenizer}; +use crate::tokenizer::{Code, State, Tokenizer}; /// Before flow. /// @@ -39,9 +39,9 @@ use crate::tokenizer::{Code, State, StateFnResult, Tokenizer}; /// | bravo /// |*** /// ``` -pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { +pub fn start(tokenizer: &mut Tokenizer, code: Code) -> State { match code { - Code::None => (State::Ok, 0), + Code::None => State::Ok(0), _ => tokenizer.attempt(blank_line, |ok| { Box::new(if ok { blank_line_after } else { initial_before }) })(tokenizer, code), @@ -60,9 +60,9 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { /// |~~~js /// |<div> /// ``` -fn initial_before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { +fn initial_before(tokenizer: &mut Tokenizer, code: Code) -> State { match code { - Code::None => (State::Ok, 0), + Code::None => State::Ok(0), _ => tokenizer.attempt_n( vec![ Box::new(code_indented), @@ -85,16 +85,16 @@ fn initial_before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { /// ```markdown /// ␠␠| /// ``` -fn blank_line_after(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { +fn blank_line_after(tokenizer: &mut Tokenizer, code: Code) -> State { match code { - Code::None => (State::Ok, 0), + Code::None => State::Ok(0), Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { tokenizer.enter(Token::BlankLineEnding); tokenizer.consume(code); tokenizer.exit(Token::BlankLineEnding); // Feel free to interrupt. tokenizer.interrupt = false; - (State::Fn(Box::new(start)), 0) + State::Fn(Box::new(start)) } _ => unreachable!("expected eol/eof"), } @@ -109,14 +109,14 @@ fn blank_line_after(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { /// asd /// ~~~| /// ``` -fn after(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { +fn after(tokenizer: &mut Tokenizer, code: Code) -> State { match code { - Code::None => (State::Ok, 0), + Code::None => State::Ok(0), Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { tokenizer.enter(Token::LineEnding); tokenizer.consume(code); tokenizer.exit(Token::LineEnding); - (State::Fn(Box::new(start)), 0) + State::Fn(Box::new(start)) } _ => unreachable!("expected eol/eof"), } @@ -127,6 +127,6 @@ fn after(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { /// ```markdown /// |asd /// ``` -fn before_paragraph(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { +fn before_paragraph(tokenizer: &mut Tokenizer, code: Code) -> State { tokenizer.go(paragraph, after)(tokenizer, code) } diff --git a/src/content/string.rs b/src/content/string.rs index f63b8be..fad2b6a 100644 --- a/src/content/string.rs +++ b/src/content/string.rs @@ -16,7 +16,7 @@ use crate::construct::{ character_escape::start as character_escape, character_reference::start as character_reference, partial_data::start as data, partial_whitespace::whitespace, }; -use crate::tokenizer::{Code, State, StateFnResult, Tokenizer}; +use crate::tokenizer::{Code, State, Tokenizer}; const MARKERS: [Code; 5] = [ Code::VirtualSpace, // `whitespace` @@ -27,9 +27,9 @@ const MARKERS: [Code; 5] = [ ]; /// Before string. -pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { +pub fn start(tokenizer: &mut Tokenizer, code: Code) -> State { match code { - Code::None => (State::Ok, 0), + Code::None => State::Ok(0), _ => tokenizer.attempt_n( vec![ Box::new(character_reference), @@ -45,6 +45,6 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { } /// At data. -fn before_data(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { +fn before_data(tokenizer: &mut Tokenizer, code: Code) -> State { tokenizer.go(|t, c| data(t, c, &MARKERS), start)(tokenizer, code) } diff --git a/src/content/text.rs b/src/content/text.rs index c339324..0d90cb4 100644 --- a/src/content/text.rs +++ b/src/content/text.rs @@ -27,7 +27,7 @@ use crate::construct::{ label_start_link::start as label_start_link, partial_data::start as data, partial_whitespace::whitespace, }; -use crate::tokenizer::{Code, State, StateFnResult, Tokenizer}; +use crate::tokenizer::{Code, State, Tokenizer}; const MARKERS: [Code; 12] = [ Code::VirtualSpace, // `whitespace` @@ -45,9 +45,9 @@ const MARKERS: [Code; 12] = [ ]; /// Before text. -pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { +pub fn start(tokenizer: &mut Tokenizer, code: Code) -> State { match code { - Code::None => (State::Ok, 0), + Code::None => State::Ok(0), _ => tokenizer.attempt_n( vec![ Box::new(attention), @@ -76,6 +76,6 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { /// ```markdown /// |qwe /// ``` -fn before_data(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { +fn before_data(tokenizer: &mut Tokenizer, code: Code) -> State { tokenizer.go(|t, c| data(t, c, &MARKERS), start)(tokenizer, code) } |