diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index 361bbbef..3c50c3f2 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -142,6 +142,7 @@ TSNode ts_tree_cursor_current_node(const TSTreeCursor *); uint32_t ts_language_symbol_count(const TSLanguage *); const char *ts_language_symbol_name(const TSLanguage *, TSSymbol); +TSSymbol ts_language_symbol_for_name(const TSLanguage *, const char *); TSSymbolType ts_language_symbol_type(const TSLanguage *, TSSymbol); uint32_t ts_language_version(const TSLanguage *); diff --git a/src/runtime/language.c b/src/runtime/language.c index 75e7da8b..c8e0bfc1 100644 --- a/src/runtime/language.c +++ b/src/runtime/language.c @@ -1,6 +1,7 @@ #include "runtime/language.h" #include "runtime/subtree.h" #include "runtime/error_costs.h" +#include void ts_language_table_entry(const TSLanguage *self, TSStateId state, TSSymbol symbol, TableEntry *result) { @@ -46,6 +47,15 @@ const char *ts_language_symbol_name(const TSLanguage *language, TSSymbol symbol) } } +TSSymbol ts_language_symbol_for_name(const TSLanguage *self, const char *name) { + for (TSSymbol i = 0; i < self->symbol_count; i++) { + if (!strcmp(self->symbol_names[i], name)) { + return i; + } + } + return 0; +} + TSSymbolType ts_language_symbol_type(const TSLanguage *language, TSSymbol symbol) { TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol); if (metadata.named) {