highlight: don't include scope in ScopeEnd events

When there are embedded documents, multiple scopes can start or
end at the same position. Previously, there was no guarantee that
the ScopeEnd events would always occur in the reverse order of the
ScopeStart events. The easiest way to avoid exposing inconsistency
is to not surface the scopes being ended.
This commit is contained in:
Max Brunsfeld 2019-02-20 16:45:51 -08:00
parent d2264d597f
commit e239aa8229
3 changed files with 17 additions and 12 deletions

View file

@ -209,7 +209,7 @@ pub fn ansi(
HighlightEvent::ScopeStart(s) => {
scope_stack.push(s);
}
HighlightEvent::ScopeEnd(_) => {
HighlightEvent::ScopeEnd => {
scope_stack.pop();
}
}

View file

@ -162,8 +162,7 @@ fn to_token_vector<'a>(
)? {
match event {
HighlightEvent::ScopeStart(s) => scopes.push(s),
HighlightEvent::ScopeEnd(s) => {
assert_eq!(*scopes.last().unwrap(), s);
HighlightEvent::ScopeEnd => {
scopes.pop();
}
HighlightEvent::Source(s) => {