From 6f5829f686d62bf650d5bc90396a640f2c361904 Mon Sep 17 00:00:00 2001 From: Noah Hellman Date: Thu, 1 Dec 2022 18:09:09 +0100 Subject: [PATCH] wip --- src/inline.rs | 18 +++++++++--------- src/lex.rs | 4 ++++ src/lib.rs | 3 ++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/inline.rs b/src/inline.rs index f531ecc..61b57b6 100644 --- a/src/inline.rs +++ b/src/inline.rs @@ -14,11 +14,9 @@ pub enum Atom { Hardbreak, Escape, Nbsp, - OpenMarker, // ?? Ellipsis, - ImageMarker, // ?? - EmDash, EnDash, + EmDash, Lt, Gt, Ampersand, @@ -29,13 +27,12 @@ pub enum Atom { pub enum Node { Str, // link - Url, - ImageSource, - LinkReference, - FootnoteReference, - // verbatim + //Url, + //ImageSource, + //LinkReference, + //FootnoteReference, Verbatim, - RawFormat, + RawFormat { format: Span }, InlineMath, DisplayMath, } @@ -138,6 +135,9 @@ impl<'s> Parser<'s> { let atom = match first.kind { lex::Kind::Escape => Escape, lex::Kind::Nbsp => Nbsp, + lex::Kind::Seq(lex::Sequence::Period) if first.len == 3 => Ellipsis, + lex::Kind::Seq(lex::Sequence::Hyphen) if first.len == 2 => EnDash, + lex::Kind::Seq(lex::Sequence::Hyphen) if first.len == 3 => EmDash, lex::Kind::Sym(lex::Symbol::Lt) => Lt, lex::Kind::Sym(lex::Symbol::Gt) => Gt, lex::Kind::Sym(lex::Symbol::Quote2) => Quote, diff --git a/src/lex.rs b/src/lex.rs index 185d29a..ed0d06f 100644 --- a/src/lex.rs +++ b/src/lex.rs @@ -14,8 +14,10 @@ pub(crate) struct Token { #[derive(Debug, Clone, PartialEq, Eq)] pub enum Kind { Text, + Newline, Whitespace, Nbsp, + Hardbreak, Escape, Integer, Open(Delimiter), @@ -124,6 +126,7 @@ impl<'s> Lexer<'s> { let kind = match first { _ if escape && first == ' ' => Nbsp, + _ if escape && first == '\n' => Hardbreak, _ if escape => Text, '\\' => { @@ -136,6 +139,7 @@ impl<'s> Lexer<'s> { } } + '\n' => Newline, _ if first.is_whitespace() => { self.eat_while(char::is_whitespace); Whitespace diff --git a/src/lib.rs b/src/lib.rs index 641a0cf..dad77f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -436,7 +436,8 @@ mod test { test_parse!( "para0\n\npara1", Start(Paragraph, Attributes::none()), - Str("para0\n"), + Str("para0"), + Atom(Softbreak), End(Paragraph), Atom(Blankline), Start(Paragraph, Attributes::none()),