Fix logic for generating unique symbol map
Previously, this didn't correctly handle the case where *multiple* symbols were all simply-aliased to the same *other* symbol. Refs #500
This commit is contained in:
parent
9ffcb16392
commit
8dd68c360a
1 changed files with 7 additions and 11 deletions
|
|
@ -325,22 +325,18 @@ impl Generator {
|
|||
add_line!(self, "static TSSymbol ts_symbol_map[] = {{");
|
||||
indent!(self);
|
||||
for symbol in &self.parse_table.symbols {
|
||||
// There can be multiple symbols in the grammar that have the same name and kind,
|
||||
// due to simple aliases. When that happens, ensure that they map to the same
|
||||
// public-facing symbol. If one of the symbols is not aliased, choose that one
|
||||
// to be the public-facing symbol. Otherwise, pick the symbol with the lowest
|
||||
// numeric value.
|
||||
let mut mapping = symbol;
|
||||
|
||||
// If this symbol has a simple alias, then check if its alias has the same
|
||||
// name and kind (e.g. named vs anonymous) as some other symbol in the grammar.
|
||||
// If so, add an entry to the symbol map that deduplicates these two symbols,
|
||||
// so that only one of them will ever be returned via the public API.
|
||||
if let Some(alias) = self.simple_aliases.get(symbol) {
|
||||
let kind = alias.kind();
|
||||
for other_symbol in &self.parse_table.symbols {
|
||||
if other_symbol == symbol {
|
||||
continue;
|
||||
}
|
||||
if let Some(other_alias) = self.simple_aliases.get(other_symbol) {
|
||||
if other_symbol < symbol && other_alias == alias {
|
||||
if other_symbol < mapping && other_alias == alias {
|
||||
mapping = other_symbol;
|
||||
break;
|
||||
}
|
||||
} else if self.metadata_for_symbol(*other_symbol) == (&alias.value, kind) {
|
||||
mapping = other_symbol;
|
||||
|
|
@ -353,7 +349,7 @@ impl Generator {
|
|||
self,
|
||||
"[{}] = {},",
|
||||
self.symbol_ids[&symbol],
|
||||
self.symbol_ids[&mapping],
|
||||
self.symbol_ids[mapping],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue