Improve ts_language_symbol_for_name function
This commit is contained in:
parent
660efd8c0f
commit
ce633a85c6
4 changed files with 27 additions and 31 deletions
|
|
@ -322,22 +322,6 @@ static uint16_t symbol_table_insert_name(
|
|||
* Query
|
||||
*********/
|
||||
|
||||
static TSSymbol ts_query_intern_node_name(
|
||||
const TSQuery *self,
|
||||
const char *name,
|
||||
uint32_t length,
|
||||
TSSymbolType symbol_type
|
||||
) {
|
||||
if (!strncmp(name, "ERROR", length)) return ts_builtin_sym_error;
|
||||
uint32_t symbol_count = ts_language_symbol_count(self->language);
|
||||
for (TSSymbol i = 0; i < symbol_count; i++) {
|
||||
if (ts_language_symbol_type(self->language, i) != symbol_type) continue;
|
||||
const char *symbol_name = ts_language_symbol_name(self->language, i);
|
||||
if (!strncmp(symbol_name, name, length) && !symbol_name[length]) return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The `pattern_map` contains a mapping from TSSymbol values to indices in the
|
||||
// `steps` array. For a given syntax node, the `pattern_map` makes it possible
|
||||
// to quickly find the starting steps of all of the patterns whose root matches
|
||||
|
|
@ -592,11 +576,11 @@ static TSQueryError ts_query_parse_pattern(
|
|||
const char *node_name = stream->input;
|
||||
stream_scan_identifier(stream);
|
||||
uint32_t length = stream->input - node_name;
|
||||
symbol = ts_query_intern_node_name(
|
||||
self,
|
||||
symbol = ts_language_symbol_for_name(
|
||||
self->language,
|
||||
node_name,
|
||||
length,
|
||||
TSSymbolTypeRegular
|
||||
true
|
||||
);
|
||||
if (!symbol) {
|
||||
stream_reset(stream, node_name);
|
||||
|
|
@ -643,11 +627,11 @@ static TSQueryError ts_query_parse_pattern(
|
|||
uint32_t length = stream->input - string_content;
|
||||
|
||||
// Add a step for the node
|
||||
TSSymbol symbol = ts_query_intern_node_name(
|
||||
self,
|
||||
TSSymbol symbol = ts_language_symbol_for_name(
|
||||
self->language,
|
||||
string_content,
|
||||
length,
|
||||
TSSymbolTypeAnonymous
|
||||
false
|
||||
);
|
||||
if (!symbol) {
|
||||
stream_reset(stream, string_content);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue