diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-08-11 17:26:17 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-08-11 17:26:17 +0200 |
commit | 0d9c4611922535533746d1a86f10ef4e701c950e (patch) | |
tree | dd776161db75ba264b67830635b736ca5dd5c314 /src/construct/definition.rs | |
parent | 90969231bfcdfcd09bae646abba17d832b633376 (diff) | |
download | markdown-rs-0d9c4611922535533746d1a86f10ef4e701c950e.tar.gz markdown-rs-0d9c4611922535533746d1a86f10ef4e701c950e.tar.bz2 markdown-rs-0d9c4611922535533746d1a86f10ef4e701c950e.zip |
Refactor attempts to remove unneeded state name
Diffstat (limited to 'src/construct/definition.rs')
-rw-r--r-- | src/construct/definition.rs | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/src/construct/definition.rs b/src/construct/definition.rs index ee930b1..11f1062 100644 --- a/src/construct/definition.rs +++ b/src/construct/definition.rs @@ -124,13 +124,12 @@ pub fn start(tokenizer: &mut Tokenizer) -> State { if possible && tokenizer.parse_state.constructs.definition { tokenizer.enter(Name::Definition); - // Note: arbitrary whitespace allowed even if code (indented) is on. - let name = space_or_tab(tokenizer); tokenizer.attempt( - name, State::Next(StateName::DefinitionBefore), State::Next(StateName::DefinitionBefore), - ) + ); + // Note: arbitrary whitespace allowed even if code (indented) is on. + State::Retry(space_or_tab(tokenizer)) } else { State::Nok } @@ -148,11 +147,8 @@ pub fn before(tokenizer: &mut Tokenizer) -> State { tokenizer.tokenize_state.token_1 = Name::DefinitionLabel; tokenizer.tokenize_state.token_2 = Name::DefinitionLabelMarker; tokenizer.tokenize_state.token_3 = Name::DefinitionLabelString; - tokenizer.attempt( - StateName::LabelStart, - State::Next(StateName::DefinitionLabelAfter), - State::Nok, - ) + tokenizer.attempt(State::Next(StateName::DefinitionLabelAfter), State::Nok); + State::Retry(StateName::LabelStart) } _ => State::Nok, } @@ -193,12 +189,11 @@ pub fn label_after(tokenizer: &mut Tokenizer) -> State { /// ^ /// ``` pub fn marker_after(tokenizer: &mut Tokenizer) -> State { - let name = space_or_tab_eol(tokenizer); tokenizer.attempt( - name, State::Next(StateName::DefinitionDestinationBefore), State::Next(StateName::DefinitionDestinationBefore), - ) + ); + State::Retry(space_or_tab_eol(tokenizer)) } /// Before a destination. @@ -215,10 +210,10 @@ pub fn destination_before(tokenizer: &mut Tokenizer) -> State { tokenizer.tokenize_state.token_5 = Name::DefinitionDestinationString; tokenizer.tokenize_state.size_b = usize::MAX; tokenizer.attempt( - StateName::DestinationStart, State::Next(StateName::DefinitionDestinationAfter), State::Next(StateName::DefinitionDestinationMissing), - ) + ); + State::Retry(StateName::DestinationStart) } /// After a destination. @@ -235,10 +230,10 @@ pub fn destination_after(tokenizer: &mut Tokenizer) -> State { tokenizer.tokenize_state.token_5 = Name::Data; tokenizer.tokenize_state.size_b = 0; tokenizer.attempt( - StateName::DefinitionTitleBefore, State::Next(StateName::DefinitionAfter), State::Next(StateName::DefinitionAfter), - ) + ); + State::Retry(StateName::DefinitionTitleBefore) } /// Without destination. @@ -262,12 +257,11 @@ pub fn destination_missing(tokenizer: &mut Tokenizer) -> State { /// ^ /// ``` pub fn after(tokenizer: &mut Tokenizer) -> State { - let name = space_or_tab(tokenizer); tokenizer.attempt( - name, State::Next(StateName::DefinitionAfterWhitespace), State::Next(StateName::DefinitionAfterWhitespace), - ) + ); + State::Retry(space_or_tab(tokenizer)) } /// After a definition, after optional whitespace. @@ -306,7 +300,7 @@ pub fn after_whitespace(tokenizer: &mut Tokenizer) -> State { _ => { tokenizer.tokenize_state.end = 0; State::Nok - }, + } } } @@ -319,12 +313,11 @@ pub fn after_whitespace(tokenizer: &mut Tokenizer) -> State { /// ^ /// ``` pub fn title_before(tokenizer: &mut Tokenizer) -> State { - let name = space_or_tab_eol(tokenizer); tokenizer.attempt( - name, State::Next(StateName::DefinitionTitleBeforeMarker), State::Nok, - ) + ); + State::Retry(space_or_tab_eol(tokenizer)) } /// Before a title, after a line ending. @@ -338,11 +331,8 @@ pub fn title_before_marker(tokenizer: &mut Tokenizer) -> State { tokenizer.tokenize_state.token_1 = Name::DefinitionTitle; tokenizer.tokenize_state.token_2 = Name::DefinitionTitleMarker; tokenizer.tokenize_state.token_3 = Name::DefinitionTitleString; - tokenizer.attempt( - StateName::TitleStart, - State::Next(StateName::DefinitionTitleAfter), - State::Nok, - ) + tokenizer.attempt(State::Next(StateName::DefinitionTitleAfter), State::Nok); + State::Retry(StateName::TitleStart) } /// After a title. @@ -355,12 +345,11 @@ pub fn title_after(tokenizer: &mut Tokenizer) -> State { tokenizer.tokenize_state.token_1 = Name::Data; tokenizer.tokenize_state.token_2 = Name::Data; tokenizer.tokenize_state.token_3 = Name::Data; - let name = space_or_tab(tokenizer); tokenizer.attempt( - name, State::Next(StateName::DefinitionTitleAfterOptionalWhitespace), State::Next(StateName::DefinitionTitleAfterOptionalWhitespace), - ) + ); + State::Retry(space_or_tab(tokenizer)) } /// After a title, after optional whitespace. |