Implement list token
This commit is contained in:
parent
67b6d5db9f
commit
0ec784034a
5 changed files with 166 additions and 9 deletions
41
src/syntax/content/parser/token/item.rs
Normal file
41
src/syntax/content/parser/token/item.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use crate::syntax::content::{Parseable, Lexeme};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Item {
|
||||
open: bool,
|
||||
}
|
||||
|
||||
impl Parseable for Item {
|
||||
fn probe(lexeme: &Lexeme) -> bool {
|
||||
(lexeme.match_as_char('-') || lexeme.match_as_char('+'))
|
||||
&& lexeme.match_next_as_char(' ')
|
||||
}
|
||||
|
||||
fn lex(_lexeme: &Lexeme) -> Item {
|
||||
Item { open: false }
|
||||
}
|
||||
|
||||
fn render(&self) -> String {
|
||||
if self.open {
|
||||
String::from("<li>")
|
||||
} else {
|
||||
String::from("</li>")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Item {
|
||||
pub fn new(open: bool) -> Item {
|
||||
Item { open }
|
||||
}
|
||||
|
||||
pub fn probe_end(lexeme: &Lexeme) -> bool {
|
||||
lexeme.match_as_char('\n')
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Item {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "Item [{}]", if self.open { "open" } else { "closed" })
|
||||
}
|
||||
}
|
||||
47
src/syntax/content/parser/token/list.rs
Normal file
47
src/syntax/content/parser/token/list.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
use crate::syntax::content::{Parseable, Lexeme};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct List {
|
||||
open: bool,
|
||||
ordered: bool,
|
||||
}
|
||||
|
||||
impl Parseable for List {
|
||||
fn probe(lexeme: &Lexeme) -> bool {
|
||||
(lexeme.match_as_char('-') || lexeme.match_as_char('+'))
|
||||
&& lexeme.match_next_as_char(' ')
|
||||
}
|
||||
|
||||
fn lex(_lexeme: &Lexeme) -> List {
|
||||
panic!("Attempt to lex a List directly from a lexeme")
|
||||
}
|
||||
|
||||
fn render(&self) -> String {
|
||||
|
||||
let bar = if self.open { "" } else { "/" };
|
||||
let tag = if self.ordered { "ol" } else { "ul" };
|
||||
|
||||
format!("<{bar}{tag}>")
|
||||
}
|
||||
}
|
||||
|
||||
impl List {
|
||||
pub fn new(open: bool, ordered: bool) -> List {
|
||||
List { open, ordered }
|
||||
}
|
||||
|
||||
pub fn probe_end(lexeme: &Lexeme) -> bool {
|
||||
lexeme.match_as_char('\n')
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for List {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"List [{} {}]",
|
||||
if self.open { "open" } else { "closed" },
|
||||
if self.ordered { "ordered" } else { "unordered" },
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue