binding: Restore handling of multiple symbols w/ same name

Even though normal aliases don't cause this, simple (single-use) aliases still do cause it.
This commit is contained in:
Max Brunsfeld 2019-03-05 09:44:43 -08:00
parent f52271352b
commit 445dfda53e
2 changed files with 73 additions and 39 deletions

View file

@ -3,7 +3,7 @@ mod escape;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_derive::*;
use std::cmp;
use std::fmt::Write;
use std::fmt::{self, Write};
use std::mem::transmute;
use std::str;
use std::usize;
@ -572,8 +572,9 @@ where
}
}
impl<'a, T: Fn(&str) -> Option<(Language, &'a PropertySheet<Properties>)>> Iterator
for Highlighter<'a, T>
impl<'a, T> Iterator for Highlighter<'a, T>
where
T: Fn(&str) -> Option<(Language, &'a PropertySheet<Properties>)>,
{
type Item = HighlightEvent<'a>;
@ -653,6 +654,31 @@ impl<'a, T: Fn(&str) -> Option<(Language, &'a PropertySheet<Properties>)>> Itera
}
}
impl<'a, T> fmt::Debug for Highlighter<'a, T>
where
T: Fn(&str) -> Option<(Language, &'a PropertySheet<Properties>)>,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(layer) = self.layers.first() {
let node = layer.cursor.node();
let position = if layer.at_node_end {
node.end_position()
} else {
node.start_position()
};
write!(
f,
"{{Highlighter position: {:?}, kind: {}, at_end: {}, props: {:?}}}",
position,
node.kind(),
layer.at_node_end,
layer.cursor.node_properties()
)?;
}
Ok(())
}
}
impl<'a> Layer<'a> {
fn new(
source: &'a [u8],

View file

@ -907,53 +907,61 @@ impl<P> PropertySheet<P> {
None
};
let kind_id = transition.kind.as_ref().and_then(|kind| {
let named = transition.named.unwrap();
for i in 0..(node_kind_count as u16) {
if kind == language.node_kind_for_id(i)
&& named == language.node_kind_is_named(i)
{
return Some(i);
}
}
None
});
let state_id = transition.state_id as u16;
let child_index = transition.index.map(|i| i as u16);
let field_id = transition
.field
.as_ref()
.and_then(|field| language.field_id_for_name(&field));
if let Some(field_id) = field_id {
if let Some(kind) = transition.kind.as_ref() {
for kind_id in 0..(node_kind_count as u16) {
if kind != language.node_kind_for_id(kind_id)
|| transition.named != Some(language.node_kind_is_named(kind_id))
{
continue;
}
if let Some(field_id) = field_id {
field_transitions
.entry(field_id)
.or_insert(Vec::new())
.push(PropertyTransition {
node_kind_id: Some(kind_id),
state_id,
child_index,
text_regex_index,
});
} else {
for (_, entries) in field_transitions.iter_mut() {
entries.push(PropertyTransition {
node_kind_id: Some(kind_id),
state_id,
child_index,
text_regex_index,
});
}
kind_transitions.entry(kind_id).or_insert(Vec::new()).push(
PropertyTransition {
node_kind_id: None,
state_id,
child_index,
text_regex_index,
},
);
}
}
} else if let Some(field_id) = field_id {
field_transitions
.entry(field_id)
.or_insert(Vec::new())
.push(PropertyTransition {
node_kind_id: kind_id,
child_index: transition.index.map(|i| i as u16),
state_id: transition.state_id as u16,
node_kind_id: None,
state_id,
child_index,
text_regex_index,
});
} else {
for (_, entries) in field_transitions.iter_mut() {
entries.push(PropertyTransition {
node_kind_id: kind_id,
child_index: transition.index.map(|i| i as u16),
state_id: transition.state_id as u16,
text_regex_index,
});
}
if let Some(kind_id) = kind_id {
kind_transitions.entry(kind_id).or_insert(Vec::new()).push(
PropertyTransition {
node_kind_id: None,
child_index: transition.index.map(|i| i as u16),
state_id: transition.state_id as u16,
text_regex_index,
},
);
}
}
}
states.push(PropertyState {