diff --git a/Cargo.toml b/Cargo.toml index 216fc37ab..d7ba965ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ tree-sitter-typescript = "=0.20.1" tree-sitter-javascript = "=0.20.0" tree-sitter-python = "=0.20.2" tree-sitter-rust = "=0.20.3" -tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.0" } +tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.1" } tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.0" } tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.1" } tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.0" } diff --git a/enums/Cargo.toml b/enums/Cargo.toml index 815e8c2e6..06a89a72e 100644 --- a/enums/Cargo.toml +++ b/enums/Cargo.toml @@ -14,7 +14,7 @@ tree-sitter-typescript = "=0.20.1" tree-sitter-javascript = "=0.20.0" tree-sitter-python = "=0.20.2" tree-sitter-rust = "=0.20.3" -tree-sitter-preproc = { path = "../tree-sitter-preproc", version = "=0.20.0" } +tree-sitter-preproc = { path = "../tree-sitter-preproc", version = "=0.20.1" } tree-sitter-ccomment = { path = "../tree-sitter-ccomment", version = "=0.20.0" } tree-sitter-mozcpp = { path = "../tree-sitter-mozcpp", version = "=0.20.1" } tree-sitter-mozjs = { path = "../tree-sitter-mozjs", version = "=0.20.0" } diff --git a/tests/repositories/rca-output b/tests/repositories/rca-output index 0977615a6..96d3766fb 160000 --- a/tests/repositories/rca-output +++ b/tests/repositories/rca-output @@ -1 +1 @@ -Subproject commit 0977615a6617737229db2d0a63a927bc87ad4f36 +Subproject commit 96d3766fba14efe9af8d0bdcf597f0f5fe01ba9e diff --git a/tree-sitter-preproc/Cargo.toml b/tree-sitter-preproc/Cargo.toml index 311e2bf8f..96a27d51e 100644 --- a/tree-sitter-preproc/Cargo.toml +++ b/tree-sitter-preproc/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tree-sitter-preproc" description = "Preproc grammar for the tree-sitter parsing library" -version = "0.20.0" +version = "0.20.1" authors = ["Calixte Denizet "] license = "MIT" readme = "bindings/rust/README.md" @@ -21,7 +21,7 @@ include = [ path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = "0.20.0" +tree-sitter = "0.20.9" [build-dependencies] cc = "^1.0" diff --git a/tree-sitter-preproc/binding.gyp b/tree-sitter-preproc/binding.gyp index d676a9cbc..3aa8cadad 100644 --- a/tree-sitter-preproc/binding.gyp +++ b/tree-sitter-preproc/binding.gyp @@ -8,7 +8,7 @@ ], "sources": [ "src/parser.c", - "src/binding.cc" + "bindings/node/binding.cc" ], "cflags_c": [ "-std=c99", diff --git a/tree-sitter-preproc/bindings/node/binding.cc b/tree-sitter-preproc/bindings/node/binding.cc new file mode 100644 index 000000000..fb68fc7d4 --- /dev/null +++ b/tree-sitter-preproc/bindings/node/binding.cc @@ -0,0 +1,28 @@ +#include "tree_sitter/parser.h" +#include +#include "nan.h" + +using namespace v8; + +extern "C" TSLanguage * tree_sitter_preproc(); + +namespace { + +NAN_METHOD(New) {} + +void Init(Local exports, Local module) { + Local tpl = Nan::New(New); + tpl->SetClassName(Nan::New("Language").ToLocalChecked()); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + + Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); + Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); + Nan::SetInternalFieldPointer(instance, 0, tree_sitter_preproc()); + + Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("preproc").ToLocalChecked()); + Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); +} + +NODE_MODULE(tree_sitter_preproc_binding, Init) + +} // namespace diff --git a/tree-sitter-preproc/bindings/node/index.js b/tree-sitter-preproc/bindings/node/index.js new file mode 100644 index 000000000..b3864cd4a --- /dev/null +++ b/tree-sitter-preproc/bindings/node/index.js @@ -0,0 +1,19 @@ +try { + module.exports = require("../../build/Release/tree_sitter_preproc_binding"); +} catch (error1) { + if (error1.code !== 'MODULE_NOT_FOUND') { + throw error1; + } + try { + module.exports = require("../../build/Debug/tree_sitter_preproc_binding"); + } catch (error2) { + if (error2.code !== 'MODULE_NOT_FOUND') { + throw error2; + } + throw error1 + } +} + +try { + module.exports.nodeTypeInfo = require("../../src/node-types.json"); +} catch (_) {} diff --git a/tree-sitter-preproc/index.js b/tree-sitter-preproc/index.js deleted file mode 100644 index 7e1c99f19..000000000 --- a/tree-sitter-preproc/index.js +++ /dev/null @@ -1,13 +0,0 @@ -try { - module.exports = require("./build/Release/tree_sitter_preproc_binding"); -} catch (error) { - try { - module.exports = require("./build/Debug/tree_sitter_preproc_binding"); - } catch (_) { - throw error - } -} - -try { - module.exports.nodeTypeInfo = require("./src/node-types.json"); -} catch (_) {} diff --git a/tree-sitter-preproc/package.json b/tree-sitter-preproc/package.json index 99de973ba..60b8ec670 100644 --- a/tree-sitter-preproc/package.json +++ b/tree-sitter-preproc/package.json @@ -1,8 +1,8 @@ { "name": "tree-sitter-preproc", - "version": "0.19.0", + "version": "0.20.0", "description": "Preproc grammar for node-tree-sitter", - "main": "index.js", + "main": "bindings/node", "keywords": [ "parser", "lexer" @@ -13,7 +13,7 @@ "nan": "^2.14.2" }, "devDependencies": { - "tree-sitter-cli": "^0.19.3" + "tree-sitter-cli": "^0.20.7" }, "scripts": { "build": "tree-sitter generate && node-gyp build", diff --git a/tree-sitter-preproc/src/binding.cc b/tree-sitter-preproc/src/binding.cc deleted file mode 100644 index 8891ff773..000000000 --- a/tree-sitter-preproc/src/binding.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include "tree_sitter/parser.h" -#include -#include "nan.h" - -using namespace v8; - -extern "C" TSLanguage * tree_sitter_c(); - -namespace { - -NAN_METHOD(New) {} - -void Init(Handle exports, Handle module) { - Local tpl = Nan::New(New); - tpl->SetClassName(Nan::New("Language").ToLocalChecked()); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - - Local constructor = tpl->GetFunction(); - Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); - Nan::SetInternalFieldPointer(instance, 0, tree_sitter_c()); - - instance->Set(Nan::New("name").ToLocalChecked(), Nan::New("c").ToLocalChecked()); - module->Set(Nan::New("exports").ToLocalChecked(), instance); -} - -NODE_MODULE(tree_sitter_c_binding, Init) - -} // namespace diff --git a/tree-sitter-preproc/src/parser.c b/tree-sitter-preproc/src/parser.c index 174a47d49..37ac3c086 100644 --- a/tree-sitter-preproc/src/parser.c +++ b/tree-sitter-preproc/src/parser.c @@ -5,7 +5,7 @@ #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif -#define LANGUAGE_VERSION 13 +#define LANGUAGE_VERSION 14 #define STATE_COUNT 121 #define LARGE_STATE_COUNT 16 #define SYMBOL_COUNT 36 @@ -54,7 +54,7 @@ enum { aux_sym_preproc_if_repeat1 = 35, }; -static const char *ts_symbol_names[] = { +static const char * const ts_symbol_names[] = { [ts_builtin_sym_end] = "end", [sym_identifier] = "identifier", [sym_nothing] = "nothing", @@ -93,7 +93,7 @@ static const char *ts_symbol_names[] = { [aux_sym_preproc_if_repeat1] = "preproc_if_repeat1", }; -static TSSymbol ts_symbol_map[] = { +static const TSSymbol ts_symbol_map[] = { [ts_builtin_sym_end] = ts_builtin_sym_end, [sym_identifier] = sym_identifier, [sym_nothing] = sym_nothing, @@ -279,14 +279,138 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { }, }; -static TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = { +static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = { [0] = {0}, }; -static uint16_t ts_non_terminal_alias_map[] = { +static const uint16_t ts_non_terminal_alias_map[] = { 0, }; +static const TSStateId ts_primary_state_ids[STATE_COUNT] = { + [0] = 0, + [1] = 1, + [2] = 2, + [3] = 3, + [4] = 3, + [5] = 2, + [6] = 3, + [7] = 2, + [8] = 8, + [9] = 9, + [10] = 10, + [11] = 11, + [12] = 8, + [13] = 13, + [14] = 8, + [15] = 15, + [16] = 16, + [17] = 17, + [18] = 18, + [19] = 19, + [20] = 20, + [21] = 21, + [22] = 22, + [23] = 23, + [24] = 24, + [25] = 25, + [26] = 26, + [27] = 27, + [28] = 28, + [29] = 29, + [30] = 21, + [31] = 22, + [32] = 24, + [33] = 25, + [34] = 26, + [35] = 21, + [36] = 27, + [37] = 20, + [38] = 19, + [39] = 25, + [40] = 18, + [41] = 23, + [42] = 28, + [43] = 27, + [44] = 16, + [45] = 29, + [46] = 17, + [47] = 22, + [48] = 17, + [49] = 20, + [50] = 23, + [51] = 19, + [52] = 26, + [53] = 18, + [54] = 28, + [55] = 24, + [56] = 16, + [57] = 29, + [58] = 58, + [59] = 59, + [60] = 59, + [61] = 58, + [62] = 58, + [63] = 59, + [64] = 64, + [65] = 65, + [66] = 65, + [67] = 65, + [68] = 68, + [69] = 69, + [70] = 70, + [71] = 71, + [72] = 70, + [73] = 73, + [74] = 74, + [75] = 68, + [76] = 70, + [77] = 68, + [78] = 71, + [79] = 79, + [80] = 69, + [81] = 79, + [82] = 74, + [83] = 71, + [84] = 79, + [85] = 69, + [86] = 74, + [87] = 87, + [88] = 87, + [89] = 89, + [90] = 90, + [91] = 89, + [92] = 92, + [93] = 93, + [94] = 94, + [95] = 95, + [96] = 96, + [97] = 97, + [98] = 95, + [99] = 97, + [100] = 94, + [101] = 92, + [102] = 102, + [103] = 103, + [104] = 103, + [105] = 90, + [106] = 89, + [107] = 107, + [108] = 107, + [109] = 95, + [110] = 97, + [111] = 94, + [112] = 107, + [113] = 92, + [114] = 103, + [115] = 87, + [116] = 90, + [117] = 96, + [118] = 93, + [119] = 96, + [120] = 93, +}; + static bool ts_lex(TSLexer *lexer, TSStateId state) { START_LEXER(); eof = lexer->eof(lexer); @@ -949,7 +1073,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { } } -static TSLexMode ts_lex_modes[STATE_COUNT] = { +static const TSLexMode ts_lex_modes[STATE_COUNT] = { [0] = {.lex_state = 0, .external_lex_state = 1}, [1] = {.lex_state = 71, .external_lex_state = 1}, [2] = {.lex_state = 10, .external_lex_state = 1}, @@ -1077,17 +1201,17 @@ enum { ts_external_token_raw_string_literal = 0, }; -static TSSymbol ts_external_scanner_symbol_map[EXTERNAL_TOKEN_COUNT] = { +static const TSSymbol ts_external_scanner_symbol_map[EXTERNAL_TOKEN_COUNT] = { [ts_external_token_raw_string_literal] = sym_raw_string_literal, }; -static bool ts_external_scanner_states[2][EXTERNAL_TOKEN_COUNT] = { +static const bool ts_external_scanner_states[2][EXTERNAL_TOKEN_COUNT] = { [1] = { [ts_external_token_raw_string_literal] = true, }, }; -static uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { +static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [0] = { [ts_builtin_sym_end] = ACTIONS(1), [sym_identifier] = ACTIONS(1), @@ -1491,7 +1615,7 @@ static uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { }, }; -static uint16_t ts_small_parse_table[] = { +static const uint16_t ts_small_parse_table[] = { [0] = 2, ACTIONS(196), 2, sym_raw_string_literal, @@ -2495,7 +2619,7 @@ static uint16_t ts_small_parse_table[] = { sym_identifier, }; -static uint32_t ts_small_parse_table_map[] = { +static const uint32_t ts_small_parse_table_map[] = { [SMALL_STATE(16)] = 0, [SMALL_STATE(17)] = 19, [SMALL_STATE(18)] = 38, @@ -2603,7 +2727,7 @@ static uint32_t ts_small_parse_table_map[] = { [SMALL_STATE(120)] = 1217, }; -static TSParseActionEntry ts_parse_actions[] = { +static const TSParseActionEntry ts_parse_actions[] = { [0] = {.entry = {.count = 0, .reusable = false}}, [1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(), [3] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_translation_unit, 0), @@ -2809,7 +2933,7 @@ void tree_sitter_preproc_external_scanner_deserialize(void *, const char *, unsi #endif extern const TSLanguage *tree_sitter_preproc(void) { - static TSLanguage language = { + static const TSLanguage language = { .version = LANGUAGE_VERSION, .symbol_count = SYMBOL_COUNT, .alias_count = ALIAS_COUNT, @@ -2820,19 +2944,19 @@ extern const TSLanguage *tree_sitter_preproc(void) { .production_id_count = PRODUCTION_ID_COUNT, .field_count = FIELD_COUNT, .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH, - .parse_table = (const uint16_t *)ts_parse_table, - .small_parse_table = (const uint16_t *)ts_small_parse_table, - .small_parse_table_map = (const uint32_t *)ts_small_parse_table_map, + .parse_table = &ts_parse_table[0][0], + .small_parse_table = ts_small_parse_table, + .small_parse_table_map = ts_small_parse_table_map, .parse_actions = ts_parse_actions, .symbol_names = ts_symbol_names, .symbol_metadata = ts_symbol_metadata, .public_symbol_map = ts_symbol_map, .alias_map = ts_non_terminal_alias_map, - .alias_sequences = (const TSSymbol *)ts_alias_sequences, + .alias_sequences = &ts_alias_sequences[0][0], .lex_modes = ts_lex_modes, .lex_fn = ts_lex, .external_scanner = { - (const bool *)ts_external_scanner_states, + &ts_external_scanner_states[0][0], ts_external_scanner_symbol_map, tree_sitter_preproc_external_scanner_create, tree_sitter_preproc_external_scanner_destroy, @@ -2840,6 +2964,7 @@ extern const TSLanguage *tree_sitter_preproc(void) { tree_sitter_preproc_external_scanner_serialize, tree_sitter_preproc_external_scanner_deserialize, }, + .primary_state_ids = ts_primary_state_ids, }; return &language; } diff --git a/tree-sitter-preproc/src/tree_sitter/parser.h b/tree-sitter-preproc/src/tree_sitter/parser.h index a3a87bd1d..2b14ac104 100644 --- a/tree-sitter-preproc/src/tree_sitter/parser.h +++ b/tree-sitter-preproc/src/tree_sitter/parser.h @@ -102,8 +102,8 @@ struct TSLanguage { const uint16_t *small_parse_table; const uint32_t *small_parse_table_map; const TSParseActionEntry *parse_actions; - const char **symbol_names; - const char **field_names; + const char * const *symbol_names; + const char * const *field_names; const TSFieldMapSlice *field_map_slices; const TSFieldMapEntry *field_map_entries; const TSSymbolMetadata *symbol_metadata; @@ -123,6 +123,7 @@ struct TSLanguage { unsigned (*serialize)(void *, char *); void (*deserialize)(void *, const char *, unsigned); } external_scanner; + const TSStateId *primary_state_ids; }; /*