Add version number to TSLanguage structs
This commit is contained in:
parent
672d491775
commit
d853b6504d
6 changed files with 24 additions and 1 deletions
|
|
@ -11,6 +11,7 @@
|
|||
#include "compiler/lexical_grammar.h"
|
||||
#include "compiler/rules/built_in_symbols.h"
|
||||
#include "compiler/util/string_helpers.h"
|
||||
#include "tree_sitter/runtime.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace generate_code {
|
||||
|
|
@ -134,6 +135,7 @@ class CCodeGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
line("#define LANGUAGE_VERSION " + to_string(TREE_SITTER_LANGUAGE_VERSION));
|
||||
line("#define STATE_COUNT " + to_string(parse_table.states.size()));
|
||||
line("#define SYMBOL_COUNT " + to_string(parse_table.symbols.size()));
|
||||
line("#define TOKEN_COUNT " + to_string(token_count));
|
||||
|
|
@ -227,7 +229,7 @@ class CCodeGenerator {
|
|||
for (size_t i = 0, n = lexical_grammar.variables.size(); i < n; i++) {
|
||||
for (size_t j = 0; j < syntax_grammar.external_tokens.size(); j++) {
|
||||
const ExternalToken &external_token = syntax_grammar.external_tokens[j];
|
||||
if (external_token.corresponding_internal_token.index == i) {
|
||||
if (external_token.corresponding_internal_token.index == Symbol::Index(i)) {
|
||||
external_tokens_by_corresponding_internal_token.insert({i, j});
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ const TSLanguage *ts_document_language(TSDocument *self) {
|
|||
}
|
||||
|
||||
void ts_document_set_language(TSDocument *self, const TSLanguage *language) {
|
||||
if (language->version != TREE_SITTER_LANGUAGE_VERSION) return;
|
||||
ts_document_invalidate(self);
|
||||
parser_set_language(&self->parser, language);
|
||||
if (self->tree) {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ uint32_t ts_language_symbol_count(const TSLanguage *language) {
|
|||
return language->symbol_count;
|
||||
}
|
||||
|
||||
uint32_t ts_language_version(const TSLanguage *language) {
|
||||
return language->version;
|
||||
}
|
||||
|
||||
TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *language,
|
||||
TSSymbol symbol) {
|
||||
if (symbol == ts_builtin_sym_error)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue