⬆️ tree-sitter

This commit is contained in:
Max Brunsfeld 2019-07-17 15:54:34 -07:00
parent c9d3a2fd09
commit 62903d8915
8 changed files with 7670 additions and 11049 deletions

View File

@ -7,3 +7,7 @@ try {
throw error
}
}
try {
module.exports.nodeTypeInfo = require("./src/node-types.json");
} catch (_) {}

View File

@ -13,7 +13,7 @@
"nan": "^2.11.1"
},
"devDependencies": {
"tree-sitter-cli": "^0.14.5"
"tree-sitter-cli": "^0.15.6"
},
"scripts": {
"test": "tree-sitter test && tree-sitter parse examples/*.css --quiet --time",

8
src/binding.cc vendored
View File

@ -10,17 +10,17 @@ namespace {
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);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = tpl->GetFunction();
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_css());
instance->Set(Nan::New("name").ToLocalChecked(), Nan::New("css").ToLocalChecked());
module->Set(Nan::New("exports").ToLocalChecked(), instance);
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("css").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_css_binding, Init)

3
src/grammar.json vendored
View File

@ -1738,6 +1738,7 @@
"inline": [
"_top_level_item",
"_block_item"
]
],
"supertypes": []
}

4577
src/highlights.json vendored

File diff suppressed because it is too large Load Diff

1746
src/node-types.json vendored Normal file

File diff suppressed because it is too large Load Diff

12335
src/parser.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -15,9 +15,21 @@ extern "C" {
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId;
typedef struct TSLanguage TSLanguage;
#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 struct {
@ -54,7 +66,7 @@ typedef struct {
TSSymbol symbol;
int16_t dynamic_precedence;
uint8_t child_count;
uint8_t alias_sequence_id;
uint8_t production_id;
};
} params;
TSParseActionType type : 4;
@ -92,12 +104,16 @@ struct TSLanguage {
struct {
const bool *states;
const TSSymbol *symbol_map;
void *(*create)();
void *(*create)(void);
void (*destroy)(void *);
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} 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() \
bool result = false; \
bool skip = false; \
int32_t lookahead; \
goto start; \
next_state: \
lexer->advance(lexer, skip); \
start: \
skip = false; \
lookahead = lexer->lookahead;
#define ADVANCE(state_value) \
{ \
lexer->advance(lexer, false); \
state = state_value; \
goto next_state; \
}
#define SKIP(state_value) \
{ \
lexer->advance(lexer, true); \
skip = true; \
state = state_value; \
goto next_state; \
}