diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-21 17:24:56 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-21 17:24:56 +0200 |
commit | 56ff5c73c7ec19b349e7d60d04ce1057c006d6ec (patch) | |
tree | b4107ae0e0219f871a2f2764215ad979b2b0d75f /src/content/string.rs | |
parent | 7effd171218fff68f051671f1373cee467a8f921 (diff) | |
download | markdown-rs-56ff5c73c7ec19b349e7d60d04ce1057c006d6ec.tar.gz markdown-rs-56ff5c73c7ec19b349e7d60d04ce1057c006d6ec.tar.bz2 markdown-rs-56ff5c73c7ec19b349e7d60d04ce1057c006d6ec.zip |
Make data a construct
Diffstat (limited to '')
-rw-r--r-- | src/content/string.rs | 50 |
1 files changed, 9 insertions, 41 deletions
diff --git a/src/content/string.rs b/src/content/string.rs index bae2646..3338c90 100644 --- a/src/content/string.rs +++ b/src/content/string.rs @@ -14,8 +14,14 @@ use crate::construct::{ character_escape::start as character_escape, character_reference::start as character_reference, + partial_data::start as data, }; -use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer}; +use crate::tokenizer::{Code, State, StateFnResult, Tokenizer}; + +const MARKERS: [Code; 2] = [ + Code::Char('&'), // `character_reference` + Code::Char('\\'), // `character_escape` +]; /// Before string. /// @@ -33,49 +39,11 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { } } -/// Before string, not at a character reference or character escape. -/// -/// We’re at data. +/// At data. /// /// ```markdown /// |qwe /// ``` fn before_data(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { - match code { - Code::None => (State::Ok, None), - Code::CarriageReturnLineFeed | Code::Char('\r' | '\n') => { - tokenizer.enter(TokenType::LineEnding); - tokenizer.consume(code); - tokenizer.exit(TokenType::LineEnding); - (State::Fn(Box::new(start)), None) - } - _ => { - tokenizer.enter(TokenType::Data); - tokenizer.consume(code); - (State::Fn(Box::new(in_data)), None) - } - } -} - -/// In data. -/// -/// ```markdown -/// q|w|e -/// ``` -fn in_data(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { - match code { - Code::None | Code::CarriageReturnLineFeed | Code::Char('\r' | '\n') => { - tokenizer.exit(TokenType::Data); - before_data(tokenizer, code) - } - // To do: somehow get these markers from constructs. - Code::Char('&' | '\\') => { - tokenizer.exit(TokenType::Data); - start(tokenizer, code) - } - _ => { - tokenizer.consume(code); - (State::Fn(Box::new(in_data)), None) - } - } + tokenizer.go(|t, c| data(t, c, MARKERS.to_vec()), start)(tokenizer, code) } |