Remove magic number from generated symbols enums
The symbol numbers 0 and 1 are reserved for 'error' and 'eof', so the grammar's start symbol is always 2.
This commit is contained in:
parent
013572671f
commit
0a21eee3f0
6 changed files with 190 additions and 184 deletions
|
|
@ -204,10 +204,15 @@ namespace tree_sitter {
|
|||
|
||||
string symbol_enum() {
|
||||
string result = "enum {\n";
|
||||
size_t index = 2;
|
||||
bool at_start = true;
|
||||
for (auto symbol : parse_table.symbols)
|
||||
if (!symbol.is_built_in())
|
||||
result += indent(symbol_id(symbol)) + " = " + to_string(index++) + ",\n";
|
||||
if (!symbol.is_built_in()) {
|
||||
if (at_start)
|
||||
result += indent(symbol_id(symbol)) + " = ts_start_sym,\n";
|
||||
else
|
||||
result += indent(symbol_id(symbol)) + ",\n";
|
||||
at_start = false;
|
||||
}
|
||||
return result + "};";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue