initial parser working
All checks were successful
Test the running changes / Test (push) Successful in 35s
All checks were successful
Test the running changes / Test (push) Successful in 35s
This commit is contained in:
69
src/ast.rs
Normal file
69
src/ast.rs
Normal 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,
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user