initial parser working
All checks were successful
Test the running changes / Test (push) Successful in 35s

This commit is contained in:
2025-12-11 01:46:57 +02:00
parent 617f124ac1
commit 30369cfdd3
10 changed files with 767 additions and 4 deletions

69
src/ast.rs Normal file
View File

@@ -0,0 +1,69 @@
// Grammar rules:
//
// Markdown ::= Block Markdown | Block
//
// Block ::= (Heading | CodeBlock | Quote | Paragraph) "\n\n"
// Heading ::= "#{1,6}\s" Inline
// CodeBlock ::= "```.*\n" "(.*?\n)*" "```"
// Quote ::= ">" Block
// Paragraph ::= Inline
//
// Inline ::= InlineElem Inline | InlineElem
// InlineElem ::= Bold | Italic | Code | Link | Text
// Bold ::= "\*" Inline "\*"
// Italic ::= "_" Inline "_"
// Code ::= "`" "[.^`]*" "`"
// Link ::= "\[" Inline "\]\(" Href "\)"
// Href ::= "[.^\)]*"
// Text ::= "[.^`*_\[]*"
#[derive(Debug, PartialEq)]
pub enum Inline {
Bold { inner: Vec<Inline> },
Italic { inner: Vec<Inline> },
Link { inner: Vec<Inline>, href: Href },
Code { content: String },
Text { content: String },
}
#[derive(Debug, PartialEq)]
pub struct Href(pub String);
impl Href {
pub fn new(href: &str) -> Self {
// can check for link correctness
Self(href.to_string())
}
}
/*
pub struct Markdown {
block: Block,
rest: Option<Box<Markdown>>,
}
pub enum Block {
Heading(HeadingBlock),
Code(CodeBlock),
Quote(QuoteBlock),
Paragraph(ParagraphBlock),
}
pub struct HeadingBlock {
level: u8,
content: Inline,
}
pub struct CodeBlock {
lang: String,
content: String,
}
pub struct QuoteBlock {
content: Box<Block>,
}
pub struct ParagraphBlock {
content: String,
}
*/