From 8ee0ad79771af5b9d1d24b29a3f79ea890cd4207 Mon Sep 17 00:00:00 2001 From: jutty Date: Thu, 1 Jan 2026 03:11:27 -0300 Subject: [PATCH] Add Oblique token --- src/syntax/content/parser.rs | 14 +++++- src/syntax/content/parser/token.rs | 3 ++ src/syntax/content/parser/token/oblique.rs | 54 ++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/syntax/content/parser/token/oblique.rs diff --git a/src/syntax/content/parser.rs b/src/syntax/content/parser.rs index d5fbb80..cfe9563 100644 --- a/src/syntax/content/parser.rs +++ b/src/syntax/content/parser.rs @@ -4,7 +4,7 @@ use crate::types::Config; use super::{Parseable as _, Token, LexMap}; use token::{ anchor::Anchor, linebreak::LineBreak, paragraph::Paragraph, header::Header, - preformat::PreFormat, literal::Literal, code::Code, + preformat::PreFormat, literal::Literal, code::Code, oblique::Oblique, }; use lexeme::Lexeme; @@ -78,6 +78,10 @@ fn lex(text: &str, map: LexMap, config: &Config) -> Vec { state.context.inline = InlineContext::Code; tokens.push(Token::Code(Code::new(true))); continue; + } else if Oblique::probe(lexeme) { + state.context.inline = InlineContext::Oblique; + tokens.push(Token::Oblique(Oblique::new(true))); + continue; } else if Anchor::probe(lexeme) { state.context.inline = InlineContext::Anchor; state.buffers.anchor.clear(); @@ -97,6 +101,13 @@ fn lex(text: &str, map: LexMap, config: &Config) -> Vec { continue; } }, + InlineContext::Oblique => { + if Oblique::probe(lexeme) { + state.context.inline = InlineContext::None; + tokens.push(Token::Oblique(Oblique::new(false))); + continue; + } + }, InlineContext::Anchor => { let buffer = &mut state.buffers.anchor; let candidate = &mut buffer.candidate; @@ -192,6 +203,7 @@ enum BlockContext { enum InlineContext { Anchor, Code, + Oblique, None, } diff --git a/src/syntax/content/parser/token.rs b/src/syntax/content/parser/token.rs index 8951a37..4f9fa8d 100644 --- a/src/syntax/content/parser/token.rs +++ b/src/syntax/content/parser/token.rs @@ -8,6 +8,7 @@ pub mod span; pub mod header; pub mod preformat; pub mod code; +pub mod oblique; #[derive(Debug, Eq, PartialEq)] pub enum Token { @@ -16,6 +17,7 @@ pub enum Token { Header(header::Header), LineBreak(linebreak::LineBreak), Literal(literal::Literal), + Oblique(oblique::Oblique), Paragraph(paragraph::Paragraph), PreFormat(preformat::PreFormat), Span(span::Span), @@ -29,6 +31,7 @@ impl Token { Token::Header(ref d) => d.render(), Token::LineBreak(ref d) => d.render(), Token::Literal(ref d) => d.render(), + Token::Oblique(ref d) => d.render(), Token::Paragraph(ref d) => d.render(), Token::PreFormat(ref d) => d.render(), Token::Span(ref d) => d.render(), diff --git a/src/syntax/content/parser/token/oblique.rs b/src/syntax/content/parser/token/oblique.rs new file mode 100644 index 0000000..136bb99 --- /dev/null +++ b/src/syntax/content/parser/token/oblique.rs @@ -0,0 +1,54 @@ +use crate::{ + syntax::content::{Parseable, Lexeme}, +}; + +#[derive(Debug, Eq, PartialEq)] +pub struct Oblique { + open: bool, +} + +impl Oblique { + pub fn new(open: bool) -> Oblique { + Oblique { open } + } +} + +impl Parseable for Oblique { + fn probe(lexeme: &Lexeme) -> bool { + lexeme.text() == "_" + } + + fn lex(_lexeme: &Lexeme) -> Oblique { + panic!("Attempt to lex an oblique tag directly from a lexeme") + } + + fn render(&self) -> String { + if self.open { + String::from("") + } else { + String::from("") + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn render() { + let code_open = Oblique::new(true); + assert_eq!(code_open.render(), ""); + + let code_closed = Oblique::new(false); + assert_eq!(code_closed.render(), ""); + } + + #[test] + #[should_panic( + expected = "Attempt to lex an oblique tag directly from a lexeme" + )] + fn lex() { + Oblique::lex(&Lexeme::new("", "")); + } +}