From dc3459de8e7b053cb231384ce71d442c9d90ec21 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Fri, 30 Oct 2020 11:41:25 +0100 Subject: [PATCH] Extract 'extra' nodes and their subtrees --- extractor/src/extractor.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/extractor/src/extractor.rs b/extractor/src/extractor.rs index 597de04b986..12d4509d659 100644 --- a/extractor/src/extractor.rs +++ b/extractor/src/extractor.rs @@ -303,16 +303,12 @@ impl Visitor<'_> { return false; } - if node.is_extra() { - return false; - } - self.stack.push(Vec::new()); return true; } fn leave_node(&mut self, field_name: Option<&'static str>, node: Node) { - if node.is_extra() || node.is_error() || node.is_missing() { + if node.is_error() || node.is_missing() { return; } let child_nodes = self.stack.pop().expect("Vistor: empty stack"); @@ -347,16 +343,20 @@ impl Visitor<'_> { all_args.push(Arg::Label(loc)); self.trap_writer.add_tuple(&table_name, all_args); } - if let Some(parent) = self.stack.last_mut() { - parent.push(( - field_name, - id, - TypeName { - kind: node.kind().to_owned(), - named: node.is_named(), - }, - )) - }; + if !node.is_extra() { + // Extra nodes are independent root nodes and do not belong to the parent node + // Therefore we should not register them in the parent vector + if let Some(parent) = self.stack.last_mut() { + parent.push(( + field_name, + id, + TypeName { + kind: node.kind().to_owned(), + named: node.is_named(), + }, + )) + }; + } } else { error!( "{}:{}: unknown table type: '{}'", @@ -366,6 +366,7 @@ impl Visitor<'_> { ); } } + fn complex_node( &mut self, node: &Node,