update to newer syntax
This commit is contained in:
parent
99b2e4c19a
commit
ba3ec6277d
10 changed files with 2696 additions and 2359 deletions
21
binding.gyp
21
binding.gyp
|
@ -2,18 +2,29 @@
|
|||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_spl_binding",
|
||||
"dependencies": [
|
||||
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
|
||||
],
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"src"
|
||||
"src",
|
||||
],
|
||||
"sources": [
|
||||
"bindings/node/binding.cc",
|
||||
"src/parser.c",
|
||||
# If your language uses an external scanner, add it here.
|
||||
# NOTE: if your language has an external scanner, add it here.
|
||||
],
|
||||
"conditions": [
|
||||
["OS!='win'", {
|
||||
"cflags_c": [
|
||||
"-std=c99",
|
||||
]
|
||||
"-std=c11",
|
||||
],
|
||||
}, { # OS == "win"
|
||||
"cflags_c": [
|
||||
"/std:c11",
|
||||
"/utf-8",
|
||||
],
|
||||
}],
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,28 +1,20 @@
|
|||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
#include <napi.h>
|
||||
|
||||
using namespace v8;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_spl();
|
||||
extern "C" TSLanguage *tree_sitter_spl();
|
||||
|
||||
namespace {
|
||||
// "tree-sitter", "language" hashed with BLAKE2
|
||||
const napi_type_tag LANGUAGE_TYPE_TAG = {
|
||||
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
|
||||
};
|
||||
|
||||
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_spl());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("spl").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
||||
exports["name"] = Napi::String::New(env, "spl");
|
||||
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_spl());
|
||||
language.TypeTag(&LANGUAGE_TYPE_TAG);
|
||||
exports["language"] = language;
|
||||
return exports;
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_spl_binding, Init)
|
||||
|
||||
} // namespace
|
||||
NODE_API_MODULE(tree_sitter_spl_binding, Init)
|
||||
|
|
|
@ -1,18 +1,6 @@
|
|||
try {
|
||||
module.exports = require("../../build/Release/tree_sitter_spl_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_spl_binding");
|
||||
} catch (error2) {
|
||||
if (error2.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error2;
|
||||
}
|
||||
throw error1
|
||||
}
|
||||
}
|
||||
const root = require("path").join(__dirname, "..", "..");
|
||||
|
||||
module.exports = require("node-gyp-build")(root);
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
|
|
|
@ -7,6 +7,9 @@ fn main() {
|
|||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable")
|
||||
.flag_if_supported("-Wno-trigraphs");
|
||||
#[cfg(target_env = "msvc")]
|
||||
c_config.flag("-utf-8");
|
||||
|
||||
let parser_path = src_dir.join("parser.c");
|
||||
c_config.file(&parser_path);
|
||||
|
||||
|
|
12
grammar.js
12
grammar.js
|
@ -3,7 +3,7 @@ module.exports = grammar({
|
|||
|
||||
rules: {
|
||||
source_file: $ => repeat($._statement),
|
||||
_statement: $ => seq(
|
||||
_unspaced_statement: $ => seq(
|
||||
choice(
|
||||
$.string,
|
||||
$.function_definition,
|
||||
|
@ -17,13 +17,17 @@ module.exports = grammar({
|
|||
$.include,
|
||||
$.def,
|
||||
$.number,
|
||||
$.expression,
|
||||
$.call_expr,
|
||||
seq(
|
||||
repeat('&'),
|
||||
$.call
|
||||
),
|
||||
),
|
||||
optional(';'),
|
||||
optional($.call_expr),
|
||||
),
|
||||
_statement: $ => seq(
|
||||
$._unspaced_statement,
|
||||
$._spacing,
|
||||
),
|
||||
function_definition: $ => choice($.func, $.block),
|
||||
|
@ -37,7 +41,7 @@ module.exports = grammar({
|
|||
repeat($._statement),
|
||||
'}',
|
||||
),
|
||||
identifier: $ => /[^ \n\r\t:;&{}"']+/,
|
||||
identifier: $ => /[^ \n\r\t<>:;&{}"']+/,
|
||||
call: $ => seq(
|
||||
choice(
|
||||
seq(
|
||||
|
@ -50,7 +54,7 @@ module.exports = grammar({
|
|||
),
|
||||
number: $ => /\d+(\.\d+)?/,
|
||||
string: $ => seq('"', repeat(choice(/\\./, /./)), '"'),
|
||||
expression: $ => seq('<{', $._spacing, repeat($._statement), '}'),
|
||||
call_expr: $ => seq('<', optional($._spacing), repeat($._statement), $._unspaced_statement, '>'),
|
||||
with_expr: $ => seq(
|
||||
'with', $._spacing,
|
||||
repeat($.identifier),
|
||||
|
|
27
package.json
27
package.json
|
@ -3,8 +3,11 @@
|
|||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "bindings/node",
|
||||
"types": "bindings/node",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"install": "node-gyp-build",
|
||||
"prebuildify": "prebuildify --napi --strip"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -17,10 +20,20 @@
|
|||
},
|
||||
"homepage": "https://github.com/tudbut/tree-sitter-spl#readme",
|
||||
"dependencies": {
|
||||
"nan": "^2.17.0"
|
||||
"node-addon-api": "^7.1.0",
|
||||
"node-gyp-build": "^4.8.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"tree-sitter": "^0.21.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"tree_sitter": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.20.8"
|
||||
"tree-sitter-cli": "^0.20.8",
|
||||
"prebuildify": "^6.0.0"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
|
@ -31,5 +44,13 @@
|
|||
"sbl"
|
||||
]
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
"grammar.js",
|
||||
"binding.gyp",
|
||||
"prebuilds/**",
|
||||
"bindings/node/*",
|
||||
"queries/*",
|
||||
"src/**"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"name": "_statement"
|
||||
}
|
||||
},
|
||||
"_statement": {
|
||||
"_unspaced_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
|
@ -64,7 +64,7 @@
|
|||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
"name": "call_expr"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
|
@ -96,6 +96,27 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "call_expr"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_unspaced_statement"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_spacing"
|
||||
|
@ -241,7 +262,7 @@
|
|||
},
|
||||
"identifier": {
|
||||
"type": "PATTERN",
|
||||
"value": "[^ \\n\\r\\t:;&{}\"']+"
|
||||
"value": "[^ \\n\\r\\t<>:;&{}\"']+"
|
||||
},
|
||||
"call": {
|
||||
"type": "SEQ",
|
||||
|
@ -315,17 +336,25 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"expression": {
|
||||
"call_expr": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "<{"
|
||||
"value": "<"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_spacing"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
|
@ -333,9 +362,13 @@
|
|||
"name": "_statement"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_unspaced_statement"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
"value": ">"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -751,4 +784,3 @@
|
|||
"inline": [],
|
||||
"supertypes": []
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call_expr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "catch",
|
||||
"named": true
|
||||
|
@ -23,10 +27,6 @@
|
|||
"type": "def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true
|
||||
|
@ -82,6 +82,10 @@
|
|||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call_expr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "catch",
|
||||
"named": true
|
||||
|
@ -90,10 +94,6 @@
|
|||
"type": "def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true
|
||||
|
@ -167,6 +167,73 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "call_expr",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call_expr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "catch",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "include",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "type_definition",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "use",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "while",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "with_expr",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "catch",
|
||||
"named": true,
|
||||
|
@ -183,6 +250,10 @@
|
|||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call_expr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "catch",
|
||||
"named": true
|
||||
|
@ -191,10 +262,6 @@
|
|||
"type": "def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true
|
||||
|
@ -249,73 +316,6 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "catch",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "include",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "type_definition",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "use",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "while",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "with_expr",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "func",
|
||||
"named": true,
|
||||
|
@ -374,6 +374,10 @@
|
|||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call_expr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "catch",
|
||||
"named": true
|
||||
|
@ -382,10 +386,6 @@
|
|||
"type": "def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true
|
||||
|
@ -456,6 +456,10 @@
|
|||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call_expr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "catch",
|
||||
"named": true
|
||||
|
@ -464,10 +468,6 @@
|
|||
"type": "def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true
|
||||
|
@ -566,6 +566,10 @@
|
|||
"type": "call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "call_expr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "catch",
|
||||
"named": true
|
||||
|
@ -574,10 +578,6 @@
|
|||
"type": "def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true
|
||||
|
@ -653,13 +653,17 @@
|
|||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "<{",
|
||||
"type": "<",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ">",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "@",
|
||||
"named": false
|
||||
|
|
4631
src/parser.c
4631
src/parser.c
File diff suppressed because it is too large
Load diff
|
@ -13,9 +13,8 @@ extern "C" {
|
|||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
typedef uint16_t TSStateId;
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef uint16_t TSStateId;
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef uint16_t TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
|
@ -87,6 +86,11 @@ typedef union {
|
|||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
typedef struct {
|
||||
int32_t start;
|
||||
int32_t end;
|
||||
} TSCharacterRange;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t version;
|
||||
uint32_t symbol_count;
|
||||
|
@ -126,13 +130,38 @@ struct TSLanguage {
|
|||
const TSStateId *primary_state_ids;
|
||||
};
|
||||
|
||||
static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
|
||||
uint32_t index = 0;
|
||||
uint32_t size = len - index;
|
||||
while (size > 1) {
|
||||
uint32_t half_size = size / 2;
|
||||
uint32_t mid_index = index + half_size;
|
||||
TSCharacterRange *range = &ranges[mid_index];
|
||||
if (lookahead >= range->start && lookahead <= range->end) {
|
||||
return true;
|
||||
} else if (lookahead > range->end) {
|
||||
index = mid_index;
|
||||
}
|
||||
size -= half_size;
|
||||
}
|
||||
TSCharacterRange *range = &ranges[index];
|
||||
return (lookahead >= range->start && lookahead <= range->end);
|
||||
}
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define UNUSED __pragma(warning(suppress : 4101))
|
||||
#else
|
||||
#define UNUSED __attribute__((unused))
|
||||
#endif
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
UNUSED \
|
||||
bool eof = false; \
|
||||
int32_t lookahead; \
|
||||
goto start; \
|
||||
|
@ -148,6 +177,17 @@ struct TSLanguage {
|
|||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ADVANCE_MAP(...) \
|
||||
{ \
|
||||
static const uint16_t map[] = { __VA_ARGS__ }; \
|
||||
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
|
||||
if (map[i] == lookahead) { \
|
||||
state = map[i + 1]; \
|
||||
goto next_state; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
skip = true; \
|
||||
|
@ -166,7 +206,7 @@ struct TSLanguage {
|
|||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
|
||||
#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
|
@ -176,7 +216,7 @@ struct TSLanguage {
|
|||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value \
|
||||
.state = (state_value) \
|
||||
} \
|
||||
}}
|
||||
|
||||
|
@ -184,7 +224,7 @@ struct TSLanguage {
|
|||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value, \
|
||||
.state = (state_value), \
|
||||
.repetition = true \
|
||||
} \
|
||||
}}
|
||||
|
@ -197,13 +237,14 @@ struct TSLanguage {
|
|||
} \
|
||||
}}
|
||||
|
||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
||||
#define REDUCE(symbol_name, children, precedence, prod_id) \
|
||||
{{ \
|
||||
.reduce = { \
|
||||
.type = TSParseActionTypeReduce, \
|
||||
.symbol = symbol_val, \
|
||||
.child_count = child_count_val, \
|
||||
__VA_ARGS__ \
|
||||
.symbol = symbol_name, \
|
||||
.child_count = children, \
|
||||
.dynamic_precedence = precedence, \
|
||||
.production_id = prod_id \
|
||||
}, \
|
||||
}}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue