Extract context-specific parsing to a separate module
This commit is contained in:
parent
5c0f786686
commit
5ed2036e36
3 changed files with 158 additions and 120 deletions
40
src/syntax/content/parser/context.rs
Normal file
40
src/syntax/content/parser/context.rs
Normal 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 => (),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue