Address comments

This commit is contained in:
Arthur Baars
2020-11-04 14:49:47 +01:00
parent c3e8d85f0b
commit 86aa05e3cb
2 changed files with 51 additions and 48 deletions

View File

@@ -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,

View File

@@ -235,7 +235,7 @@ fn convert_nodes(nodes: &Vec<node_types::Entry>) -> Vec<dbscheme::Entry> {
}
// 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<node_types::Entry>) -> Vec<dbscheme::Entry> {
entries
}
fn add_tokeninf_table(entries: &mut Vec<dbscheme::Entry>, token_kinds: Map<String, usize>) {
fn add_tokeninfo_table(entries: &mut Vec<dbscheme::Entry>, token_kinds: Map<String, usize>) {
entries.push(dbscheme::Entry::Table(dbscheme::Table {
name: "tokeninfo".to_owned(),
keysets: None,