⬆️ tree-sitter-cli

This commit is contained in:
Max Brunsfeld 2019-12-02 17:10:24 -08:00
parent 47841b3f8e
commit 2af852d7b8
5 changed files with 746 additions and 710 deletions

View File

@ -16,7 +16,7 @@
"nan": "^2.10.0" "nan": "^2.10.0"
}, },
"devDependencies": { "devDependencies": {
"tree-sitter-cli": "^0.15.6" "tree-sitter-cli": "^0.15.14"
}, },
"scripts": { "scripts": {
"build": "tree-sitter generate && node-gyp build", "build": "tree-sitter generate && node-gyp build",

View File

@ -10,17 +10,17 @@ namespace {
NAN_METHOD(New) {} NAN_METHOD(New) {}
void Init(Handle<Object> exports, Handle<Object> module) { void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New); Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked()); tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = tpl->GetFunction(); Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_html()); Nan::SetInternalFieldPointer(instance, 0, tree_sitter_html());
instance->Set(Nan::New("name").ToLocalChecked(), Nan::New("html").ToLocalChecked()); Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("html").ToLocalChecked());
module->Set(Nan::New("exports").ToLocalChecked(), instance); Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
} }
NODE_MODULE(tree_sitter_html_binding, Init) NODE_MODULE(tree_sitter_html_binding, Init)

View File

@ -5,7 +5,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "attribute_name", "type": "attribute_name",
@ -33,7 +33,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "doctype", "type": "doctype",
@ -77,15 +77,25 @@
{ {
"type": "end_tag", "type": "end_tag",
"named": true, "named": true,
"fields": {} "fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "tag_name",
"named": true
}
]
}
}, },
{ {
"type": "erroneous_end_tag", "type": "erroneous_end_tag",
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": false,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "erroneous_end_tag_name", "type": "erroneous_end_tag_name",
@ -132,7 +142,17 @@
{ {
"type": "quoted_attribute_value", "type": "quoted_attribute_value",
"named": true, "named": true,
"fields": {} "fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "attribute_value",
"named": true
}
]
}
}, },
{ {
"type": "script_element", "type": "script_element",
@ -140,7 +160,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "end_tag", "type": "end_tag",
@ -163,11 +183,15 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "attribute", "type": "attribute",
"named": true "named": true
},
{
"type": "tag_name",
"named": true
} }
] ]
} }
@ -178,11 +202,15 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "attribute", "type": "attribute",
"named": true "named": true
},
{
"type": "tag_name",
"named": true
} }
] ]
} }
@ -193,7 +221,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "end_tag", "type": "end_tag",
@ -211,11 +239,15 @@
} }
}, },
{ {
"type": "<!", "type": "\"",
"named": false "named": false
}, },
{ {
"type": ">", "type": "'",
"named": false
},
{
"type": "/>",
"named": false "named": false
}, },
{ {
@ -223,7 +255,7 @@
"named": false "named": false
}, },
{ {
"type": "/>", "type": "<!",
"named": false "named": false
}, },
{ {
@ -234,6 +266,10 @@
"type": "=", "type": "=",
"named": false "named": false
}, },
{
"type": ">",
"named": false
},
{ {
"type": "attribute_name", "type": "attribute_name",
"named": true "named": true
@ -242,14 +278,6 @@
"type": "attribute_value", "type": "attribute_value",
"named": true "named": true
}, },
{
"type": "'",
"named": false
},
{
"type": "\"",
"named": false
},
{ {
"type": "text", "type": "text",
"named": true "named": true

1372
src/parser.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,8 @@ struct TSLexer {
void (*advance)(TSLexer *, bool); void (*advance)(TSLexer *, bool);
void (*mark_end)(TSLexer *); void (*mark_end)(TSLexer *);
uint32_t (*get_column)(TSLexer *); uint32_t (*get_column)(TSLexer *);
bool (*is_at_included_range_start)(TSLexer *); bool (*is_at_included_range_start)(const TSLexer *);
bool (*eof)(const TSLexer *);
}; };
typedef enum { typedef enum {
@ -123,6 +124,7 @@ struct TSLanguage {
#define START_LEXER() \ #define START_LEXER() \
bool result = false; \ bool result = false; \
bool skip = false; \ bool skip = false; \
bool eof = false; \
int32_t lookahead; \ int32_t lookahead; \
goto start; \ goto start; \
next_state: \ next_state: \