Do not recurse into 'extra' nodes for now

This commit is contained in:
Arthur Baars
2020-10-26 15:00:00 +01:00
parent fd39524c5e
commit 1d36b5085a

View File

@@ -75,14 +75,14 @@ struct Visitor<'a> {
}
impl Visitor<'_> {
fn enter_node(&mut self, node: Node) {
fn enter_node(&mut self, node: Node) -> bool {
if node.is_error() {
println!(
"error: {}:{}: parse error",
&self.path,
node.start_position().row,
);
return;
return false;
}
if node.is_missing() {
println!(
@@ -91,14 +91,15 @@ impl Visitor<'_> {
node.start_position().row,
node.kind()
);
return;
return false;
}
if node.is_extra() {
return;
return false;
}
self.stack.push(Vec::new());
return true;
}
fn leave_node(&mut self, field_name: Option<&'static str>, node: Node) {
@@ -281,13 +282,12 @@ fn traverse(tree: &Tree, visitor: &mut Visitor) {
let mut recurse = true;
loop {
if recurse && cursor.goto_first_child() {
visitor.enter_node(cursor.node());
recurse = visitor.enter_node(cursor.node());
} else {
visitor.leave_node(cursor.field_name(), cursor.node());
if cursor.goto_next_sibling() {
recurse = true;
visitor.enter_node(cursor.node());
recurse = visitor.enter_node(cursor.node());
} else if cursor.goto_parent() {
recurse = false;
} else {