diff --git a/src/syntax/content/parser/point.rs b/src/syntax/content/parser/point.rs index 139c7a1..fb4a918 100644 --- a/src/syntax/content/parser/point.rs +++ b/src/syntax/content/parser/point.rs @@ -4,7 +4,7 @@ use crate::{ Parseable as _, parser::{ lexeme::Lexeme, - token::{Token, oblique::Oblique}, + token::{Token, oblique::Oblique, bold::Bold}, state::State, }, }, @@ -20,6 +20,11 @@ pub fn parse( tokens.push(Token::Oblique(Oblique::new(!state.switches.oblique))); state.switches.oblique = !state.switches.oblique; return true; + } else if Bold::probe(lexeme) { + log!("Bold probed {lexeme}"); + tokens.push(Token::Bold(Bold::new(!state.switches.bold))); + state.switches.bold = !state.switches.bold; + return true; } false } diff --git a/src/syntax/content/parser/state.rs b/src/syntax/content/parser/state.rs index 84343a7..e98e127 100644 --- a/src/syntax/content/parser/state.rs +++ b/src/syntax/content/parser/state.rs @@ -16,6 +16,7 @@ pub struct State { #[derive(Clone, Debug)] pub struct Switches { pub oblique: bool, + pub bold: bool, } #[derive(Clone, Debug)] @@ -70,7 +71,10 @@ impl Default for State { block: Block::None, }, dom_ids: HashMap::default(), - switches: Switches { oblique: false }, + switches: Switches { + oblique: false, + bold: false, + }, buffers: Buffers { anchor: AnchorBuffer { candidate: Anchor::default(), diff --git a/src/syntax/content/parser/token.rs b/src/syntax/content/parser/token.rs index 88d6578..37f0c67 100644 --- a/src/syntax/content/parser/token.rs +++ b/src/syntax/content/parser/token.rs @@ -1,20 +1,22 @@ use crate::syntax::content::Parseable as _; -pub mod literal; pub mod anchor; -pub mod linebreak; -pub mod paragraph; -pub mod span; -pub mod header; -pub mod preformat; +pub mod bold; pub mod code; -pub mod oblique; -pub mod list; +pub mod header; pub mod item; +pub mod linebreak; +pub mod list; +pub mod literal; +pub mod oblique; +pub mod paragraph; +pub mod preformat; +pub mod span; #[derive(Debug, Eq, PartialEq, Clone)] pub enum Token { Anchor(anchor::Anchor), + Bold(bold::Bold), Code(code::Code), Header(header::Header), Item(item::Item), @@ -31,6 +33,7 @@ impl Token { pub fn render(&self) -> String { match *self { Token::Anchor(ref d) => d.render(), + Token::Bold(ref d) => d.render(), Token::Code(ref d) => d.render(), Token::Header(ref d) => d.render(), Token::Item(ref d) => d.render(), @@ -49,6 +52,7 @@ impl std::fmt::Display for Token { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { let data = match *self { Token::Anchor(ref d) => format!("{d}"), + Token::Bold(ref d) => format!("{d}"), Token::Code(ref d) => format!("{d}"), Token::Header(ref d) => format!("{d}"), Token::Item(ref d) => format!("{d}"), diff --git a/src/syntax/content/parser/token/bold.rs b/src/syntax/content/parser/token/bold.rs new file mode 100644 index 0000000..a0fd845 --- /dev/null +++ b/src/syntax/content/parser/token/bold.rs @@ -0,0 +1,61 @@ +use crate::{ + syntax::content::{Parseable, Lexeme}, +}; + +#[derive(Debug, Clone, Eq, PartialEq)] +pub struct Bold { + open: bool, +} + +impl Bold { + pub fn new(open: bool) -> Bold { + Bold { open } + } +} + +impl Parseable for Bold { + fn probe(lexeme: &Lexeme) -> bool { + lexeme.text() == "*" + } + + fn lex(_lexeme: &Lexeme) -> Bold { + panic!("Attempt to lex a bold tag directly from a lexeme") + } + + fn render(&self) -> String { + if self.open { + String::from("") + } else { + String::from("") + } + } +} + +impl std::fmt::Display for Bold { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + let display_open_state = if self.open { "open" } else { "closed" }; + write!(f, "Bold [{display_open_state}]") + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn render() { + let code_open = Bold::new(true); + assert_eq!(code_open.render(), ""); + + let code_closed = Bold::new(false); + assert_eq!(code_closed.render(), ""); + } + + #[test] + #[should_panic( + expected = "Attempt to lex a bold tag directly from a lexeme" + )] + fn lex() { + Bold::lex(&Lexeme::new("", "")); + } +} diff --git a/src/syntax/content/parser/token/item.rs b/src/syntax/content/parser/token/item.rs index 7d03bd6..a4aa0d1 100644 --- a/src/syntax/content/parser/token/item.rs +++ b/src/syntax/content/parser/token/item.rs @@ -8,7 +8,7 @@ pub struct Item { impl Parseable for Item { fn probe(lexeme: &Lexeme) -> bool { (lexeme.match_as_char('-') || lexeme.match_as_char('+')) - && lexeme.match_next_as_char(' ') + && lexeme.match_next_as_char(' ') } fn lex(_lexeme: &Lexeme) -> Item { diff --git a/src/syntax/content/parser/token/list.rs b/src/syntax/content/parser/token/list.rs index 513fa2d..ae2d130 100644 --- a/src/syntax/content/parser/token/list.rs +++ b/src/syntax/content/parser/token/list.rs @@ -17,7 +17,6 @@ impl Parseable for List { } fn render(&self) -> String { - let bar = if self.open { "" } else { "/" }; let tag = if self.ordered { "ol" } else { "ul" };