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/content/string.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 'src/content/string.rs')
-rw-r--r-- | src/content/string.rs | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/content/string.rs b/src/content/string.rs index 697ec2c..b3df6ec 100644 --- a/src/content/string.rs +++ b/src/content/string.rs @@ -28,25 +28,27 @@ pub fn start(tokenizer: &mut Tokenizer) -> State { pub fn before(tokenizer: &mut Tokenizer) -> State { match tokenizer.current { None => State::Ok, - _ => tokenizer.attempt_n( - vec![ - StateName::CharacterReferenceStart, - StateName::CharacterEscapeStart, - ], - |ok| { - State::Fn(if ok { - StateName::StringBefore - } else { - StateName::StringBeforeData - }) - }, + Some(b'&') => tokenizer.attempt( + StateName::CharacterReferenceStart, + State::Fn(StateName::StringBefore), + State::Fn(StateName::StringBeforeData), ), + Some(b'\\') => tokenizer.attempt( + StateName::CharacterEscapeStart, + State::Fn(StateName::StringBefore), + State::Fn(StateName::StringBeforeData), + ), + _ => before_data(tokenizer), } } /// At data. pub fn before_data(tokenizer: &mut Tokenizer) -> State { - tokenizer.go(StateName::DataStart, StateName::StringBefore) + tokenizer.attempt( + StateName::DataStart, + State::Fn(StateName::StringBefore), + State::Nok, + ) } /// Resolve whitespace. |