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