inline: use lex kinds
import Sequence and use Delimiter, Symbol consistently
This commit is contained in:
parent
f192ea2aa6
commit
5d6d0e0840
1 changed files with 63 additions and 67 deletions
|
@ -3,6 +3,7 @@ use crate::lex;
|
||||||
use crate::Span;
|
use crate::Span;
|
||||||
|
|
||||||
use lex::Delimiter;
|
use lex::Delimiter;
|
||||||
|
use lex::Sequence;
|
||||||
use lex::Symbol;
|
use lex::Symbol;
|
||||||
|
|
||||||
use Atom::*;
|
use Atom::*;
|
||||||
|
@ -148,11 +149,11 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
|
|
||||||
fn parse_verbatim(&mut self, first: &lex::Token) -> Option<()> {
|
fn parse_verbatim(&mut self, first: &lex::Token) -> Option<()> {
|
||||||
let (mut kind, opener_len) = match first.kind {
|
let (mut kind, opener_len) = match first.kind {
|
||||||
lex::Kind::Seq(lex::Sequence::Dollar) => {
|
lex::Kind::Seq(Sequence::Dollar) => {
|
||||||
let math_opt = (first.len <= 2)
|
let math_opt = (first.len <= 2)
|
||||||
.then(|| {
|
.then(|| {
|
||||||
if let Some(lex::Token {
|
if let Some(lex::Token {
|
||||||
kind: lex::Kind::Seq(lex::Sequence::Backtick),
|
kind: lex::Kind::Seq(Sequence::Backtick),
|
||||||
len,
|
len,
|
||||||
}) = self.peek()
|
}) = self.peek()
|
||||||
{
|
{
|
||||||
|
@ -174,7 +175,7 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
}
|
}
|
||||||
math_opt
|
math_opt
|
||||||
}
|
}
|
||||||
lex::Kind::Seq(lex::Sequence::Backtick) => Some((Verbatim, first.len)),
|
lex::Kind::Seq(Sequence::Backtick) => Some((Verbatim, first.len)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
|
@ -190,7 +191,7 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
let mut non_whitespace_last = None;
|
let mut non_whitespace_last = None;
|
||||||
|
|
||||||
while let Some(t) = self.eat() {
|
while let Some(t) = self.eat() {
|
||||||
if matches!(t.kind, lex::Kind::Seq(lex::Sequence::Backtick)) && t.len == opener_len {
|
if matches!(t.kind, lex::Kind::Seq(Sequence::Backtick)) && t.len == opener_len {
|
||||||
if matches!(kind, Verbatim)
|
if matches!(kind, Verbatim)
|
||||||
&& matches!(
|
&& matches!(
|
||||||
self.lexer.peek().map(|t| &t.kind),
|
self.lexer.peek().map(|t| &t.kind),
|
||||||
|
@ -242,10 +243,10 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
self.reset_span();
|
self.reset_span();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((lex::Kind::Seq(lex::Sequence::Backtick), pos)) = non_whitespace_first {
|
if let Some((lex::Kind::Seq(Sequence::Backtick), pos)) = non_whitespace_first {
|
||||||
span_inner = span_inner.with_start(pos);
|
span_inner = span_inner.with_start(pos);
|
||||||
}
|
}
|
||||||
if let Some((lex::Kind::Seq(lex::Sequence::Backtick), pos)) = non_whitespace_last {
|
if let Some((lex::Kind::Seq(Sequence::Backtick), pos)) = non_whitespace_last {
|
||||||
span_inner = span_inner.with_end(pos);
|
span_inner = span_inner.with_end(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,10 +299,9 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
self.events.drain(i..);
|
self.events.drain(i..);
|
||||||
|
|
||||||
self.push(EventKind::Attributes);
|
self.push(EventKind::Attributes);
|
||||||
self.push_sp(EventKind::Enter(Container::Span), span_str.empty_before());
|
self.push_sp(EventKind::Enter(Span), span_str.empty_before());
|
||||||
self.push_sp(EventKind::Str, span_str);
|
self.push_sp(EventKind::Str, span_str);
|
||||||
|
return self.push_sp(EventKind::Exit(Span), span_str.empty_after());
|
||||||
return self.push_sp(EventKind::Exit(Container::Span), span_str.empty_after());
|
|
||||||
} else {
|
} else {
|
||||||
return self.push_sp(EventKind::Placeholder, self.span.empty_before());
|
return self.push_sp(EventKind::Placeholder, self.span.empty_before());
|
||||||
}
|
}
|
||||||
|
@ -447,9 +447,8 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
self.push(EventKind::Exit(cont))
|
self.push(EventKind::Exit(cont))
|
||||||
}
|
}
|
||||||
DelimEventKind::Quote(ty) => {
|
DelimEventKind::Quote(ty) => {
|
||||||
self.events[e_opener].kind =
|
self.events[e_opener].kind = EventKind::Atom(Quote { ty, left: true });
|
||||||
EventKind::Atom(Atom::Quote { ty, left: true });
|
self.push(EventKind::Atom(Quote { ty, left: false }))
|
||||||
self.push(EventKind::Atom(Atom::Quote { ty, left: false }))
|
|
||||||
}
|
}
|
||||||
DelimEventKind::Span(ty) => self.post_span(ty, e_opener),
|
DelimEventKind::Span(ty) => self.post_span(ty, e_opener),
|
||||||
};
|
};
|
||||||
|
@ -460,7 +459,7 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
if event_closer.span.is_empty()
|
if event_closer.span.is_empty()
|
||||||
&& matches!(
|
&& matches!(
|
||||||
event_closer.kind,
|
event_closer.kind,
|
||||||
EventKind::Exit(Container::ReferenceLink | Container::ReferenceImage)
|
EventKind::Exit(ReferenceLink | ReferenceImage)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
event_closer.span = inner_span;
|
event_closer.span = inner_span;
|
||||||
|
@ -581,13 +580,12 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_atom(&mut self, first: &lex::Token) -> Option<()> {
|
fn parse_atom(&mut self, first: &lex::Token) -> Option<()> {
|
||||||
let atom =
|
let atom = match first.kind {
|
||||||
match first.kind {
|
|
||||||
lex::Kind::Newline => Softbreak,
|
lex::Kind::Newline => Softbreak,
|
||||||
lex::Kind::Hardbreak => Hardbreak,
|
lex::Kind::Hardbreak => Hardbreak,
|
||||||
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 => {
|
lex::Kind::Seq(Sequence::Period) if first.len >= 3 => {
|
||||||
while self.span.len() > 3 {
|
while self.span.len() > 3 {
|
||||||
self.push_sp(EventKind::Atom(Ellipsis), self.span.with_len(3));
|
self.push_sp(EventKind::Atom(Ellipsis), self.span.with_len(3));
|
||||||
self.span = self.span.skip(3);
|
self.span = self.span.skip(3);
|
||||||
|
@ -598,7 +596,7 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
return self.push(EventKind::Str);
|
return self.push(EventKind::Str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lex::Kind::Seq(lex::Sequence::Hyphen) if first.len >= 2 => {
|
lex::Kind::Seq(Sequence::Hyphen) if first.len >= 2 => {
|
||||||
let (m, n) = if first.len % 3 == 0 {
|
let (m, n) = if first.len % 3 == 0 {
|
||||||
(first.len / 3, 0)
|
(first.len / 3, 0)
|
||||||
} else if first.len % 2 == 0 {
|
} else if first.len % 2 == 0 {
|
||||||
|
@ -617,21 +615,19 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
|
||||||
});
|
});
|
||||||
return Some(());
|
return Some(());
|
||||||
}
|
}
|
||||||
lex::Kind::Open(lex::Delimiter::BraceQuote1) => Quote {
|
lex::Kind::Open(Delimiter::BraceQuote1) => Quote {
|
||||||
ty: QuoteType::Single,
|
ty: QuoteType::Single,
|
||||||
left: true,
|
left: true,
|
||||||
},
|
},
|
||||||
lex::Kind::Sym(lex::Symbol::Quote1)
|
lex::Kind::Sym(Symbol::Quote1) | lex::Kind::Close(Delimiter::BraceQuote1) => Quote {
|
||||||
| lex::Kind::Close(lex::Delimiter::BraceQuote1) => Quote {
|
|
||||||
ty: QuoteType::Single,
|
ty: QuoteType::Single,
|
||||||
left: false,
|
left: false,
|
||||||
},
|
},
|
||||||
lex::Kind::Open(lex::Delimiter::BraceQuote2) => Quote {
|
lex::Kind::Open(Delimiter::BraceQuote2) => Quote {
|
||||||
ty: QuoteType::Double,
|
ty: QuoteType::Double,
|
||||||
left: true,
|
left: true,
|
||||||
},
|
},
|
||||||
lex::Kind::Sym(lex::Symbol::Quote2)
|
lex::Kind::Sym(Symbol::Quote2) | lex::Kind::Close(Delimiter::BraceQuote2) => Quote {
|
||||||
| lex::Kind::Close(lex::Delimiter::BraceQuote2) => Quote {
|
|
||||||
ty: QuoteType::Double,
|
ty: QuoteType::Double,
|
||||||
left: false,
|
left: false,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue