diff --git a/extractor/src/extractor.rs b/extractor/src/extractor.rs index 275098457f4..f05fa36a784 100644 --- a/extractor/src/extractor.rs +++ b/extractor/src/extractor.rs @@ -328,44 +328,20 @@ impl Visitor<'_> { kind: node.kind().to_owned(), named: node.is_named(), }); - if let Some(Entry::Token { kind_id, .. }) = table { - self.trap_writer.add_tuple( - "tokeninfo", - vec![ - Arg::Label(id), - Arg::Int(*kind_id), - Arg::Label(self.file_label), - Arg::Int(self.token_counter), - sliced_source_arg(self.source, node), - Arg::Label(loc), - ], - ); - self.token_counter += 1; - if let Some(parent) = self.stack.last_mut() { - parent.push(( - field_name, - id, - TypeName { - kind: node.kind().to_owned(), - named: node.is_named(), - }, - )) - }; - } else if let Some(Entry::Table { fields, .. }) = table { - let table_name = escape_name(&format!( - "{}_def", - node_type_name(node.kind(), node.is_named()) - )); - if let Some(args) = self.complex_node(&node, fields, child_nodes, id) { - let mut all_args = Vec::new(); - all_args.push(Arg::Label(id)); - all_args.extend(args); - all_args.push(Arg::Label(loc)); - self.trap_writer.add_tuple(&table_name, all_args); - } - 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 + match table { + Some(Entry::Token { kind_id, .. }) => { + self.trap_writer.add_tuple( + "tokeninfo", + vec![ + Arg::Label(id), + Arg::Int(*kind_id), + Arg::Label(self.file_label), + Arg::Int(self.token_counter), + sliced_source_arg(self.source, node), + Arg::Label(loc), + ], + ); + self.token_counter += 1; if let Some(parent) = self.stack.last_mut() { parent.push(( field_name, @@ -377,16 +353,43 @@ impl Visitor<'_> { )) }; } - } else { - error!( - "{}:{}: unknown table type: '{}'", - &self.path, - node.start_position().row, - node.kind() - ); + Some(Entry::Table { fields, .. }) => { + let table_name = escape_name(&format!( + "{}_def", + node_type_name(node.kind(), node.is_named()) + )); + if let Some(args) = self.complex_node(&node, fields, child_nodes, id) { + let mut all_args = Vec::new(); + all_args.push(Arg::Label(id)); + all_args.extend(args); + all_args.push(Arg::Label(loc)); + self.trap_writer.add_tuple(&table_name, all_args); + } + 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(), + }, + )) + }; + } + } + _ => { + error!( + "{}:{}: unknown table type: '{}'", + &self.path, + node.start_position().row, + node.kind() + ); + } } } - fn complex_node( &mut self, node: &Node, diff --git a/generator/src/main.rs b/generator/src/main.rs index f16962382df..42b660af89e 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -235,7 +235,7 @@ fn convert_nodes(nodes: &Vec) -> Vec { } // Add the tokeninfo table - add_tokeninf_table(&mut entries, token_kinds); + add_tokeninfo_table(&mut entries, token_kinds); // Create a union of all database types. entries.push(dbscheme::Entry::Union(dbscheme::Union { @@ -246,7 +246,7 @@ fn convert_nodes(nodes: &Vec) -> Vec { entries } -fn add_tokeninf_table(entries: &mut Vec, token_kinds: Map) { +fn add_tokeninfo_table(entries: &mut Vec, token_kinds: Map) { entries.push(dbscheme::Entry::Table(dbscheme::Table { name: "tokeninfo".to_owned(), keysets: None,