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/construct/character_reference.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/construct/character_reference.rs')
-rw-r--r-- | src/construct/character_reference.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/construct/character_reference.rs b/src/construct/character_reference.rs index 6e44502..8521f15 100644 --- a/src/construct/character_reference.rs +++ b/src/construct/character_reference.rs @@ -136,12 +136,12 @@ struct Info { /// > | a	b /// ^ /// ``` -pub fn start(tokenizer: &mut Tokenizer, code: Code) -> State { - match code { +pub fn start(tokenizer: &mut Tokenizer) -> State { + match tokenizer.current { Code::Char('&') if tokenizer.parse_state.constructs.character_reference => { tokenizer.enter(Token::CharacterReference); tokenizer.enter(Token::CharacterReferenceMarker); - tokenizer.consume(code); + tokenizer.consume(); tokenizer.exit(Token::CharacterReferenceMarker); State::Fn(Box::new(open)) } @@ -160,19 +160,19 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> State { /// > | a	b /// ^ /// ``` -fn open(tokenizer: &mut Tokenizer, code: Code) -> State { +fn open(tokenizer: &mut Tokenizer) -> State { let info = Info { buffer: String::new(), kind: Kind::Named, }; - if let Code::Char('#') = code { + if let Code::Char('#') = tokenizer.current { tokenizer.enter(Token::CharacterReferenceMarkerNumeric); - tokenizer.consume(code); + tokenizer.consume(); tokenizer.exit(Token::CharacterReferenceMarkerNumeric); - State::Fn(Box::new(|t, c| numeric(t, c, info))) + State::Fn(Box::new(|t| numeric(t, info))) } else { tokenizer.enter(Token::CharacterReferenceValue); - value(tokenizer, code, info) + value(tokenizer, info) } } @@ -185,18 +185,18 @@ fn open(tokenizer: &mut Tokenizer, code: Code) -> State { /// > | a	b /// ^ /// ``` -fn numeric(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { - if let Code::Char('x' | 'X') = code { +fn numeric(tokenizer: &mut Tokenizer, mut info: Info) -> State { + if let Code::Char('x' | 'X') = tokenizer.current { tokenizer.enter(Token::CharacterReferenceMarkerHexadecimal); - tokenizer.consume(code); + tokenizer.consume(); tokenizer.exit(Token::CharacterReferenceMarkerHexadecimal); tokenizer.enter(Token::CharacterReferenceValue); info.kind = Kind::Hexadecimal; - State::Fn(Box::new(|t, c| value(t, c, info))) + State::Fn(Box::new(|t| value(t, info))) } else { tokenizer.enter(Token::CharacterReferenceValue); info.kind = Kind::Decimal; - value(tokenizer, code, info) + value(tokenizer, info) } } @@ -213,8 +213,8 @@ fn numeric(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { /// > | a	b /// ^ /// ``` -fn value(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { - match code { +fn value(tokenizer: &mut Tokenizer, mut info: Info) -> State { + match tokenizer.current { Code::Char(';') if !info.buffer.is_empty() => { let unknown_named = Kind::Named == info.kind && !CHARACTER_REFERENCES.iter().any(|d| d.0 == info.buffer); @@ -224,7 +224,7 @@ fn value(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { } else { tokenizer.exit(Token::CharacterReferenceValue); tokenizer.enter(Token::CharacterReferenceMarkerSemi); - tokenizer.consume(code); + tokenizer.consume(); tokenizer.exit(Token::CharacterReferenceMarkerSemi); tokenizer.exit(Token::CharacterReference); State::Ok @@ -233,8 +233,8 @@ fn value(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> State { Code::Char(char) => { if info.buffer.len() < info.kind.max() && info.kind.allowed(char) { info.buffer.push(char); - tokenizer.consume(code); - State::Fn(Box::new(|t, c| value(t, c, info))) + tokenizer.consume(); + State::Fn(Box::new(|t| value(t, info))) } else { State::Nok } |