⬆️ tree-sitter
This commit is contained in:
parent
c9d3a2fd09
commit
62903d8915
4
index.js
4
index.js
|
@ -7,3 +7,7 @@ try {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
module.exports.nodeTypeInfo = require("./src/node-types.json");
|
||||||
|
} catch (_) {}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
"nan": "^2.11.1"
|
"nan": "^2.11.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tree-sitter-cli": "^0.14.5"
|
"tree-sitter-cli": "^0.15.6"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tree-sitter test && tree-sitter parse examples/*.css --quiet --time",
|
"test": "tree-sitter test && tree-sitter parse examples/*.css --quiet --time",
|
||||||
|
|
|
@ -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_css());
|
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_css());
|
||||||
|
|
||||||
instance->Set(Nan::New("name").ToLocalChecked(), Nan::New("css").ToLocalChecked());
|
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("css").ToLocalChecked());
|
||||||
module->Set(Nan::New("exports").ToLocalChecked(), instance);
|
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(tree_sitter_css_binding, Init)
|
NODE_MODULE(tree_sitter_css_binding, Init)
|
||||||
|
|
|
@ -1738,6 +1738,7 @@
|
||||||
"inline": [
|
"inline": [
|
||||||
"_top_level_item",
|
"_top_level_item",
|
||||||
"_block_item"
|
"_block_item"
|
||||||
]
|
],
|
||||||
|
"supertypes": []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -15,9 +15,21 @@ extern "C" {
|
||||||
|
|
||||||
#ifndef TREE_SITTER_API_H_
|
#ifndef TREE_SITTER_API_H_
|
||||||
typedef uint16_t TSSymbol;
|
typedef uint16_t TSSymbol;
|
||||||
|
typedef uint16_t TSFieldId;
|
||||||
typedef struct TSLanguage TSLanguage;
|
typedef struct TSLanguage TSLanguage;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
TSFieldId field_id;
|
||||||
|
uint8_t child_index;
|
||||||
|
bool inherited;
|
||||||
|
} TSFieldMapEntry;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t index;
|
||||||
|
uint16_t length;
|
||||||
|
} TSFieldMapSlice;
|
||||||
|
|
||||||
typedef uint16_t TSStateId;
|
typedef uint16_t TSStateId;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -54,7 +66,7 @@ typedef struct {
|
||||||
TSSymbol symbol;
|
TSSymbol symbol;
|
||||||
int16_t dynamic_precedence;
|
int16_t dynamic_precedence;
|
||||||
uint8_t child_count;
|
uint8_t child_count;
|
||||||
uint8_t alias_sequence_id;
|
uint8_t production_id;
|
||||||
};
|
};
|
||||||
} params;
|
} params;
|
||||||
TSParseActionType type : 4;
|
TSParseActionType type : 4;
|
||||||
|
@ -92,12 +104,16 @@ struct TSLanguage {
|
||||||
struct {
|
struct {
|
||||||
const bool *states;
|
const bool *states;
|
||||||
const TSSymbol *symbol_map;
|
const TSSymbol *symbol_map;
|
||||||
void *(*create)();
|
void *(*create)(void);
|
||||||
void (*destroy)(void *);
|
void (*destroy)(void *);
|
||||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||||
unsigned (*serialize)(void *, char *);
|
unsigned (*serialize)(void *, char *);
|
||||||
void (*deserialize)(void *, const char *, unsigned);
|
void (*deserialize)(void *, const char *, unsigned);
|
||||||
} external_scanner;
|
} external_scanner;
|
||||||
|
uint32_t field_count;
|
||||||
|
const TSFieldMapSlice *field_map_slices;
|
||||||
|
const TSFieldMapEntry *field_map_entries;
|
||||||
|
const char **field_names;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -106,20 +122,24 @@ struct TSLanguage {
|
||||||
|
|
||||||
#define START_LEXER() \
|
#define START_LEXER() \
|
||||||
bool result = false; \
|
bool result = false; \
|
||||||
|
bool skip = false; \
|
||||||
int32_t lookahead; \
|
int32_t lookahead; \
|
||||||
|
goto start; \
|
||||||
next_state: \
|
next_state: \
|
||||||
|
lexer->advance(lexer, skip); \
|
||||||
|
start: \
|
||||||
|
skip = false; \
|
||||||
lookahead = lexer->lookahead;
|
lookahead = lexer->lookahead;
|
||||||
|
|
||||||
#define ADVANCE(state_value) \
|
#define ADVANCE(state_value) \
|
||||||
{ \
|
{ \
|
||||||
lexer->advance(lexer, false); \
|
|
||||||
state = state_value; \
|
state = state_value; \
|
||||||
goto next_state; \
|
goto next_state; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SKIP(state_value) \
|
#define SKIP(state_value) \
|
||||||
{ \
|
{ \
|
||||||
lexer->advance(lexer, true); \
|
skip = true; \
|
||||||
state = state_value; \
|
state = state_value; \
|
||||||
goto next_state; \
|
goto next_state; \
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue