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" })
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue