1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
use super::block_tokenizer::{BlockTokenizer, LineType}; #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum HeadingLevel { Level1, Level2, Level3, } #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum ListType { Unordered, Ordered, } #[derive(Debug, Eq, PartialEq)] pub enum Block { Heading { level: HeadingLevel, content: String, }, Text { content: String }, FencedBlock { decorator: Option<String>, content: String, }, List { list_type: ListType, items: Vec<String>, }, } #[derive(Debug)] pub struct BlockParser { tokenizer: BlockTokenizer, } #[derive(Debug)] pub struct TextAccumulator {} impl BlockParser { pub fn new(tokenizer: BlockTokenizer) -> Self { BlockParser { tokenizer } } fn parse_text(&mut self) -> Option<Block> { None } } impl Iterator for BlockParser { type Item = Block; fn next(&mut self) -> Option<Self::Item> { loop { match self.tokenizer.peek() { None => return None, Some(LineType::Blank) => continue, Some(LineType::Text) => return self.parse_text(), _ => return None, }; } } } #[cfg(test)] mod tests { use super::*; use super::super::block_tokenizer::BlockTokenizer; #[test] fn it_works() { let mut parser = BlockParser::new(BlockTokenizer::new("foo bar")); assert_eq!(Some(Block::Text { content: "foo bar".to_string() }), parser.next()); } }