inline fixup

This commit is contained in:
Noah Hellman 2023-01-26 21:39:48 +01:00
parent 8339befe2f
commit 7ee1c7514d

View file

@ -391,19 +391,20 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
}
fn parse_container(&mut self, first: &lex::Token) -> Option<Event> {
Delim::from_token(first.kind).map(|(delim, dir)| {
Delim::from_token(first.kind).and_then(|(delim, dir)| {
self.openers
.iter()
.rposition(|(d, _)| {
*d == delim || matches!((d, delim), (Delim::Span(..), Delim::Span(..)))
})
.and_then(|o| {
if matches!(dir, Dir::Close | Dir::Both) {
if !dir.can_close() {
return None;
}
let (d, e) = self.openers[o];
let e_attr = e;
let e_opener = e + 1;
let inner_span =
Span::new(self.events[e_opener].span.end(), self.span.start());
let inner_span = Span::new(self.events[e_opener].span.end(), self.span.start());
let mut event_closer = match Container::try_from(d) {
Ok(cont) => {
self.events[e_opener].kind = EventKind::Enter(cont);
@ -466,11 +467,11 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
}
}
event_closer
} else {
None
}
})
.unwrap_or_else(|| {
.or_else(|| {
if !dir.can_open() {
return None;
}
self.openers.push((delim, self.events.len()));
// push dummy event in case attributes are encountered after closing delimiter
self.events.push_back(Event {
@ -478,10 +479,10 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
span: Span::empty_at(self.span.start()),
});
// use str for now, replace if closed later
Event {
Some(Event {
kind: EventKind::Str,
span: self.span,
}
})
})
})
}
@ -572,12 +573,23 @@ enum Delim {
Insert,
}
#[derive(Clone, Copy)]
enum Dir {
Open,
Close,
Both,
}
impl Dir {
fn can_open(self) -> bool {
matches!(self, Dir::Open | Dir::Both)
}
fn can_close(self) -> bool {
matches!(self, Dir::Close | Dir::Both)
}
}
impl Delim {
fn from_token(kind: lex::Kind) -> Option<(Self, Dir)> {
use Delim::*;