Skip to content

Commit

Permalink
Downgrade to tree-sitter 0.18.0
Browse files Browse the repository at this point in the history
0.19.0+ use language version 13, which Atom doesn't support yet
  • Loading branch information
winstliu committed Sep 28, 2021
1 parent e842ffc commit 7e46311
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 100 deletions.
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
try {
module.exports = require("./build/Release/tree_sitter_hclrs_binding");
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND')
throw error
else try {
module.exports = require("./build/Debug/tree_sitter_hclrs_binding");
} catch (error2) {
if (error2.code === 'MODULE_NOT_FOUND')
throw error
throw error2
}
}

try {
module.exports.nodeTypeInfo = require("./src/node-types.json");
} catch (_) {}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"nan": "^2.15.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.0"
"tree-sitter-cli": "^0.18.0"
}
}
28 changes: 28 additions & 0 deletions src/binding.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"

using namespace v8;

extern "C" TSLanguage * tree_sitter_hclrs();

namespace {

NAN_METHOD(New) {}

void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);

Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_hclrs());

Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("hclrs").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}

NODE_MODULE(tree_sitter_hclrs_binding, Init)

} // namespace
46 changes: 22 additions & 24 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif

#define LANGUAGE_VERSION 13
#define LANGUAGE_VERSION 12
#define STATE_COUNT 79
#define LARGE_STATE_COUNT 29
#define SYMBOL_COUNT 115
Expand All @@ -14,7 +14,6 @@
#define EXTERNAL_TOKEN_COUNT 0
#define FIELD_COUNT 0
#define MAX_ALIAS_SEQUENCE_LENGTH 6
#define PRODUCTION_ID_COUNT 1

enum {
anon_sym_SEMI = 1,
Expand Down Expand Up @@ -133,7 +132,7 @@ enum {
aux_sym_in_expression_repeat1 = 114,
};

static const char * const ts_symbol_names[] = {
static const char *ts_symbol_names[] = {
[ts_builtin_sym_end] = "end",
[anon_sym_SEMI] = ";",
[anon_sym_wire] = "wire",
Expand Down Expand Up @@ -251,7 +250,7 @@ static const char * const ts_symbol_names[] = {
[aux_sym_in_expression_repeat1] = "in_expression_repeat1",
};

static const TSSymbol ts_symbol_map[] = {
static TSSymbol ts_symbol_map[] = {
[ts_builtin_sym_end] = ts_builtin_sym_end,
[anon_sym_SEMI] = anon_sym_SEMI,
[anon_sym_wire] = anon_sym_wire,
Expand Down Expand Up @@ -832,11 +831,11 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
},
};

static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = {
static TSSymbol ts_alias_sequences[1][MAX_ALIAS_SEQUENCE_LENGTH] = {
[0] = {0},
};

static const uint16_t ts_non_terminal_alias_map[] = {
static uint16_t ts_non_terminal_alias_map[] = {
0,
};

Expand Down Expand Up @@ -2164,7 +2163,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
}
}

static const TSLexMode ts_lex_modes[STATE_COUNT] = {
static TSLexMode ts_lex_modes[STATE_COUNT] = {
[0] = {.lex_state = 0},
[1] = {.lex_state = 16},
[2] = {.lex_state = 16},
Expand Down Expand Up @@ -2246,7 +2245,7 @@ static const TSLexMode ts_lex_modes[STATE_COUNT] = {
[78] = {.lex_state = 4},
};

static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
static uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[0] = {
[ts_builtin_sym_end] = ACTIONS(1),
[anon_sym_SEMI] = ACTIONS(1),
Expand Down Expand Up @@ -4367,7 +4366,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
},
};

static const uint16_t ts_small_parse_table[] = {
static uint16_t ts_small_parse_table[] = {
[0] = 4,
ACTIONS(3), 1,
sym_comment,
Expand Down Expand Up @@ -5513,7 +5512,7 @@ static const uint16_t ts_small_parse_table[] = {
sym_register_name,
};

static const uint32_t ts_small_parse_table_map[] = {
static uint32_t ts_small_parse_table_map[] = {
[SMALL_STATE(29)] = 0,
[SMALL_STATE(30)] = 38,
[SMALL_STATE(31)] = 73,
Expand Down Expand Up @@ -5566,7 +5565,7 @@ static const uint32_t ts_small_parse_table_map[] = {
[SMALL_STATE(78)] = 1423,
};

static const TSParseActionEntry ts_parse_actions[] = {
static TSParseActionEntry ts_parse_actions[] = {
[0] = {.entry = {.count = 0, .reusable = false}},
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(),
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT_EXTRA(),
Expand Down Expand Up @@ -5720,28 +5719,27 @@ extern "C" {
#endif

extern const TSLanguage *tree_sitter_hclrs(void) {
static const TSLanguage language = {
static TSLanguage language = {
.version = LANGUAGE_VERSION,
.symbol_count = SYMBOL_COUNT,
.alias_count = ALIAS_COUNT,
.token_count = TOKEN_COUNT,
.external_token_count = EXTERNAL_TOKEN_COUNT,
.state_count = STATE_COUNT,
.large_state_count = LARGE_STATE_COUNT,
.production_id_count = PRODUCTION_ID_COUNT,
.field_count = FIELD_COUNT,
.max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
.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 = &ts_alias_sequences[0][0],
.parse_table = (const uint16_t *)ts_parse_table,
.parse_actions = ts_parse_actions,
.lex_modes = ts_lex_modes,
.alias_sequences = (const TSSymbol *)ts_alias_sequences,
.max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
.lex_fn = ts_lex,
.field_count = FIELD_COUNT,
.large_state_count = LARGE_STATE_COUNT,
.small_parse_table = (const uint16_t *)ts_small_parse_table,
.small_parse_table_map = (const uint32_t *)ts_small_parse_table_map,
.public_symbol_map = ts_symbol_map,
.alias_map = ts_non_terminal_alias_map,
.state_count = STATE_COUNT,
};
return &language;
}
Expand Down
Loading

0 comments on commit 7e46311

Please sign in to comment.