Use the new DOM parser on the input file

This commit is contained in:
mars 2022-10-09 00:48:05 -06:00
parent 5ac8032f92
commit 2aa36d9b02
4 changed files with 33 additions and 14 deletions

View File

@ -32,11 +32,13 @@ lines.")
(h3 "Styling " (italic "even ") "works " (bold "in ") (strikethrough "headers."))
(ul "Unordered list entry")
(ul "Unordered list entry")
(ul "Unordered list entry")
(ul
(li "Unordered list entry")
(li "Unordered list entry")
(li "Unordered list entry"))
(ol "List entry 1")
(ol "List entry 2")
(ol "List entry 3")
(ol
(li "List entry 1")
(li "List entry 2")
(li "List entry 3"))
)

View File

@ -155,6 +155,10 @@ fn main() {
println!("{:#?}", expr);
let dom = parse::Parser::parse(&expr);
println!("{:#?}", dom);
let cons = expr.as_cons().unwrap().to_vec().0;
let style = Stylesheet::default();
let width = 40;

View File

@ -13,7 +13,7 @@ impl Parser {
let mut tags = Vec::new();
for val in parser.vals.into_iter() {
for val in parser.vals.into_iter().rev() {
let mut parser = Self::from_value(&val);
let kind = parser
@ -42,7 +42,8 @@ impl Parser {
pub fn parse_args(&mut self) -> (Vec<(String, Value)>, Vec<Value>) {
let args = Vec::new();
let children = std::mem::replace(&mut self.vals, Vec::new());
let mut children = std::mem::replace(&mut self.vals, Vec::new());
children.reverse();
(args, children)
}
@ -87,12 +88,20 @@ impl Parser {
let mut children = Vec::new();
for child in children_vals.into_iter() {
let mut parser = Self::from_value(&child);
let node = match parser.parse_any_tag_kind() {
AnyTagKind::Text(kind) => BlockNode::Text(self.parse_text_tag(kind)),
AnyTagKind::Leaf(kind) => BlockNode::Leaf(self.parse_leaf_tag(kind)),
AnyTagKind::Block(kind) => BlockNode::Block(self.parse_block_tag(kind)),
let node = match child {
Value::Cons(cons) => {
let mut parser = Self::from_cons(&cons);
match parser.parse_any_tag_kind() {
AnyTagKind::Text(kind) => BlockNode::Text(parser.parse_text_tag(kind)),
AnyTagKind::Leaf(kind) => BlockNode::Leaf(parser.parse_leaf_tag(kind)),
AnyTagKind::Block(kind) => BlockNode::Block(parser.parse_block_tag(kind)),
}
}
Value::String(string) => BlockNode::Text(TextTag {
kind: TextTagKind::Plain,
children: vec![TextNode::Text(string.to_string())],
}),
_ => panic!("Block tag child must be either a string or a cons"),
};
children.push(node);

View File

@ -4,6 +4,7 @@ use strum::EnumString;
#[derive(Clone, Debug, Hash, PartialEq, Eq, EnumString)]
#[strum(serialize_all = "kebab-case", ascii_case_insensitive)]
pub enum TextTagKind {
Plain,
Italic,
Bold,
Underline,
@ -38,6 +39,9 @@ pub struct LeafTag {
#[derive(Clone, Debug, Hash, PartialEq, Eq, EnumString)]
#[strum(serialize_all = "kebab-case", ascii_case_insensitive)]
pub enum BlockTagKind {
H1,
H2,
H3,
P,
Ul,
Ol,