diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-08-09 14:04:27 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-08-09 14:04:27 +0200 |
commit | 8f8d72a749a39845fd03ae259533abe73dc7dcdf (patch) | |
tree | ebc54d404f5a5e7e406f6323131dae1ed7a79c50 /src/construct/code_indented.rs | |
parent | fafcfd55e5f7ea8b87cab4bbf979730d81749402 (diff) | |
download | markdown-rs-8f8d72a749a39845fd03ae259533abe73dc7dcdf.tar.gz markdown-rs-8f8d72a749a39845fd03ae259533abe73dc7dcdf.tar.bz2 markdown-rs-8f8d72a749a39845fd03ae259533abe73dc7dcdf.zip |
Add support for passing `ok`, `nok` as separate states to attempts
Diffstat (limited to '')
-rw-r--r-- | src/construct/code_indented.rs | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/construct/code_indented.rs b/src/construct/code_indented.rs index 516b493..0906e5f 100644 --- a/src/construct/code_indented.rs +++ b/src/construct/code_indented.rs @@ -65,7 +65,11 @@ pub fn start(tokenizer: &mut Tokenizer) -> State { if !tokenizer.interrupt && tokenizer.parse_state.constructs.code_indented { tokenizer.enter(Token::CodeIndented); let state_name = space_or_tab_min_max(tokenizer, TAB_SIZE, TAB_SIZE); - tokenizer.go(state_name, StateName::CodeIndentedAtBreak) + tokenizer.attempt( + state_name, + State::Fn(StateName::CodeIndentedAtBreak), + State::Nok, + ) } else { State::Nok } @@ -80,13 +84,11 @@ pub fn start(tokenizer: &mut Tokenizer) -> State { pub fn at_break(tokenizer: &mut Tokenizer) -> State { match tokenizer.current { None => after(tokenizer), - Some(b'\n') => tokenizer.attempt(StateName::CodeIndentedFurtherStart, |ok| { - State::Fn(if ok { - StateName::CodeIndentedAtBreak - } else { - StateName::CodeIndentedAfter - }) - }), + Some(b'\n') => tokenizer.attempt( + StateName::CodeIndentedFurtherStart, + State::Fn(StateName::CodeIndentedAtBreak), + State::Fn(StateName::CodeIndentedAfter), + ), _ => { tokenizer.enter(Token::CodeFlowChunk); inside(tokenizer) @@ -143,13 +145,11 @@ pub fn further_start(tokenizer: &mut Tokenizer) -> State { } _ if !tokenizer.lazy => { let state_name = space_or_tab_min_max(tokenizer, TAB_SIZE, TAB_SIZE); - tokenizer.attempt(state_name, |ok| { - State::Fn(if ok { - StateName::CodeIndentedFurtherEnd - } else { - StateName::CodeIndentedFurtherBegin - }) - }) + tokenizer.attempt( + state_name, + State::Fn(StateName::CodeIndentedFurtherEnd), + State::Fn(StateName::CodeIndentedFurtherBegin), + ) } _ => State::Nok, } @@ -175,7 +175,11 @@ pub fn further_end(_tokenizer: &mut Tokenizer) -> State { /// ``` pub fn further_begin(tokenizer: &mut Tokenizer) -> State { let state_name = space_or_tab(tokenizer); - tokenizer.attempt_opt(state_name, StateName::CodeIndentedFurtherAfter) + tokenizer.attempt( + state_name, + State::Fn(StateName::CodeIndentedFurtherAfter), + State::Fn(StateName::CodeIndentedFurtherAfter), + ) } /// After whitespace, not indented enough. |