This commit is contained in:
Noah Hellman 2022-12-01 18:09:09 +01:00
parent 78d6d502b6
commit 6f5829f686
3 changed files with 15 additions and 10 deletions

View file

@ -14,11 +14,9 @@ pub enum Atom {
Hardbreak, Hardbreak,
Escape, Escape,
Nbsp, Nbsp,
OpenMarker, // ??
Ellipsis, Ellipsis,
ImageMarker, // ??
EmDash,
EnDash, EnDash,
EmDash,
Lt, Lt,
Gt, Gt,
Ampersand, Ampersand,
@ -29,13 +27,12 @@ pub enum Atom {
pub enum Node { pub enum Node {
Str, Str,
// link // link
Url, //Url,
ImageSource, //ImageSource,
LinkReference, //LinkReference,
FootnoteReference, //FootnoteReference,
// verbatim
Verbatim, Verbatim,
RawFormat, RawFormat { format: Span },
InlineMath, InlineMath,
DisplayMath, DisplayMath,
} }
@ -138,6 +135,9 @@ impl<'s> Parser<'s> {
let atom = match first.kind { let atom = match first.kind {
lex::Kind::Escape => Escape, lex::Kind::Escape => Escape,
lex::Kind::Nbsp => Nbsp, 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::Lt) => Lt,
lex::Kind::Sym(lex::Symbol::Gt) => Gt, lex::Kind::Sym(lex::Symbol::Gt) => Gt,
lex::Kind::Sym(lex::Symbol::Quote2) => Quote, lex::Kind::Sym(lex::Symbol::Quote2) => Quote,

View file

@ -14,8 +14,10 @@ pub(crate) struct Token {
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum Kind { pub enum Kind {
Text, Text,
Newline,
Whitespace, Whitespace,
Nbsp, Nbsp,
Hardbreak,
Escape, Escape,
Integer, Integer,
Open(Delimiter), Open(Delimiter),
@ -124,6 +126,7 @@ impl<'s> Lexer<'s> {
let kind = match first { let kind = match first {
_ if escape && first == ' ' => Nbsp, _ if escape && first == ' ' => Nbsp,
_ if escape && first == '\n' => Hardbreak,
_ if escape => Text, _ if escape => Text,
'\\' => { '\\' => {
@ -136,6 +139,7 @@ impl<'s> Lexer<'s> {
} }
} }
'\n' => Newline,
_ if first.is_whitespace() => { _ if first.is_whitespace() => {
self.eat_while(char::is_whitespace); self.eat_while(char::is_whitespace);
Whitespace Whitespace

View file

@ -436,7 +436,8 @@ mod test {
test_parse!( test_parse!(
"para0\n\npara1", "para0\n\npara1",
Start(Paragraph, Attributes::none()), Start(Paragraph, Attributes::none()),
Str("para0\n"), Str("para0"),
Atom(Softbreak),
End(Paragraph), End(Paragraph),
Atom(Blankline), Atom(Blankline),
Start(Paragraph, Attributes::none()), Start(Paragraph, Attributes::none()),