diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-07-25 17:42:20 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-07-25 17:42:20 +0200 |
commit | 5ee6edf222658e73ee97871972b6fbeef444451b (patch) | |
tree | c9233c7a8584a2d027ef1b7443e3e5b59918ca2b /src/content/flow.rs | |
parent | 91dc4b1f461fa76df7163f68b2a6db361a71beea (diff) | |
download | markdown-rs-5ee6edf222658e73ee97871972b6fbeef444451b.tar.gz markdown-rs-5ee6edf222658e73ee97871972b6fbeef444451b.tar.bz2 markdown-rs-5ee6edf222658e73ee97871972b6fbeef444451b.zip |
Refactor to not pass codes around
Diffstat (limited to 'src/content/flow.rs')
-rw-r--r-- | src/content/flow.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/content/flow.rs b/src/content/flow.rs index 2b2ee6d..ea09cd9 100644 --- a/src/content/flow.rs +++ b/src/content/flow.rs @@ -39,12 +39,12 @@ use crate::tokenizer::{Code, State, Tokenizer}; /// | bravo /// |*** /// ``` -pub fn start(tokenizer: &mut Tokenizer, code: Code) -> State { - match code { +pub fn start(tokenizer: &mut Tokenizer) -> State { + match tokenizer.current { Code::None => State::Ok, _ => tokenizer.attempt(blank_line, |ok| { Box::new(if ok { blank_line_after } else { initial_before }) - })(tokenizer, code), + })(tokenizer), } } @@ -60,8 +60,8 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> State { /// |~~~js /// |<div> /// ``` -fn initial_before(tokenizer: &mut Tokenizer, code: Code) -> State { - match code { +fn initial_before(tokenizer: &mut Tokenizer) -> State { + match tokenizer.current { Code::None => State::Ok, _ => tokenizer.attempt_n( vec![ @@ -74,7 +74,7 @@ fn initial_before(tokenizer: &mut Tokenizer, code: Code) -> State { Box::new(definition), ], |ok| Box::new(if ok { after } else { before_paragraph }), - )(tokenizer, code), + )(tokenizer), } } @@ -85,12 +85,12 @@ fn initial_before(tokenizer: &mut Tokenizer, code: Code) -> State { /// ```markdown /// ␠␠| /// ``` -fn blank_line_after(tokenizer: &mut Tokenizer, code: Code) -> State { - match code { +fn blank_line_after(tokenizer: &mut Tokenizer) -> State { + match tokenizer.current { Code::None => State::Ok, Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { tokenizer.enter(Token::BlankLineEnding); - tokenizer.consume(code); + tokenizer.consume(); tokenizer.exit(Token::BlankLineEnding); // Feel free to interrupt. tokenizer.interrupt = false; @@ -109,12 +109,12 @@ fn blank_line_after(tokenizer: &mut Tokenizer, code: Code) -> State { /// asd /// ~~~| /// ``` -fn after(tokenizer: &mut Tokenizer, code: Code) -> State { - match code { +fn after(tokenizer: &mut Tokenizer) -> State { + match tokenizer.current { Code::None => State::Ok, Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { tokenizer.enter(Token::LineEnding); - tokenizer.consume(code); + tokenizer.consume(); tokenizer.exit(Token::LineEnding); State::Fn(Box::new(start)) } @@ -127,6 +127,6 @@ fn after(tokenizer: &mut Tokenizer, code: Code) -> State { /// ```markdown /// |asd /// ``` -fn before_paragraph(tokenizer: &mut Tokenizer, code: Code) -> State { - tokenizer.go(paragraph, after)(tokenizer, code) +fn before_paragraph(tokenizer: &mut Tokenizer) -> State { + tokenizer.go(paragraph, after)(tokenizer) } |