Extract context-specific parsing to a separate module

This commit is contained in:
Juno Takano 2026-01-02 00:52:20 -03:00
commit 5ed2036e36
3 changed files with 158 additions and 120 deletions

View file

@ -0,0 +1,40 @@
use crate::syntax::content::parser::{
token::{Token, paragraph::Paragraph, preformat::PreFormat},
State,
};
pub mod anchor;
pub struct Context {
pub block: Block,
pub inline: Inline,
}
pub enum Block {
Paragraph,
Header(u8),
PreFormat,
None,
}
pub enum Inline {
Anchor,
Code,
Oblique,
None,
}
/// # Panics
/// Panics if there is an open header at end of input.
pub fn close(state: &State, tokens: &mut Vec<Token>) {
match state.context.block {
Block::PreFormat => {
tokens.push(Token::PreFormat(PreFormat::new(false)));
},
Block::Paragraph => {
tokens.push(Token::Paragraph(Paragraph::new(false)));
},
Block::Header(_) => panic!("End of input with open header"),
Block::None => (),
}
}