Use new alias API

This commit is contained in:
Max Brunsfeld 2017-08-01 10:12:23 -07:00
parent 4340002e38
commit ccc07eab4b
5 changed files with 15508 additions and 15524 deletions

View File

@ -299,7 +299,7 @@ module.exports = grammar({
), ),
_variable_name: $ => choice( _variable_name: $ => choice(
rename($.simple_variable_name, 'variable_name'), alias($.simple_variable_name, $.variable_name),
$.special_variable_name $.special_variable_name
), ),

View File

@ -13,7 +13,7 @@
"nan": "^2.4.0" "nan": "^2.4.0"
}, },
"devDependencies": { "devDependencies": {
"tree-sitter-cli": "^0.6.0" "tree-sitter-cli": "^0.6.6-0"
}, },
"scripts": { "scripts": {
"build": "tree-sitter generate && node-gyp build", "build": "tree-sitter generate && node-gyp build",

3
src/grammar.json vendored
View File

@ -1067,11 +1067,12 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "RENAME", "type": "ALIAS",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "simple_variable_name" "name": "simple_variable_name"
}, },
"named": true,
"value": "variable_name" "value": "variable_name"
}, },
{ {

30946
src/parser.c vendored

File diff suppressed because it is too large Load Diff

View File

@ -11,10 +11,10 @@ extern "C" {
typedef uint16_t TSSymbol; typedef uint16_t TSSymbol;
typedef uint16_t TSStateId; typedef uint16_t TSStateId;
typedef uint8_t TSExternalTokenState[16];
#define ts_builtin_sym_error ((TSSymbol)-1) #define ts_builtin_sym_error ((TSSymbol)-1)
#define ts_builtin_sym_end 0 #define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
typedef struct { typedef struct {
bool visible : 1; bool visible : 1;
@ -40,17 +40,17 @@ typedef enum {
typedef struct { typedef struct {
union { union {
struct { struct {
TSStateId to_state; TSStateId state;
bool extra : 1; bool extra : 1;
}; };
struct { struct {
TSSymbol symbol; TSSymbol symbol;
int16_t dynamic_precedence; int16_t dynamic_precedence;
uint8_t child_count; uint8_t child_count;
uint8_t rename_sequence_id : 7; uint8_t alias_sequence_id : 7;
bool fragile : 1; bool fragile : 1;
}; };
}; } params;
TSParseActionType type : 4; TSParseActionType type : 4;
} TSParseAction; } TSParseAction;
@ -71,6 +71,7 @@ typedef union {
typedef struct TSLanguage { typedef struct TSLanguage {
uint32_t version; uint32_t version;
uint32_t symbol_count; uint32_t symbol_count;
uint32_t alias_count;
uint32_t token_count; uint32_t token_count;
uint32_t external_token_count; uint32_t external_token_count;
const char **symbol_names; const char **symbol_names;
@ -78,18 +79,17 @@ typedef struct TSLanguage {
const uint16_t *parse_table; const uint16_t *parse_table;
const TSParseActionEntry *parse_actions; const TSParseActionEntry *parse_actions;
const TSLexMode *lex_modes; const TSLexMode *lex_modes;
const TSSymbol *rename_sequences; const TSSymbol *alias_sequences;
uint16_t max_rename_sequence_length; uint16_t max_alias_sequence_length;
bool (*lex_fn)(TSLexer *, TSStateId); bool (*lex_fn)(TSLexer *, TSStateId);
struct { struct {
const bool *states; const bool *states;
const TSSymbol *symbol_map; const TSSymbol *symbol_map;
void *(*create)(); void *(*create)();
void (*destroy)(void *); void (*destroy)(void *);
void (*reset)(void *);
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
bool (*serialize)(void *, TSExternalTokenState); unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const TSExternalTokenState); void (*deserialize)(void *, const char *, unsigned);
} external_scanner; } external_scanner;
} TSLanguage; } TSLanguage;
@ -131,19 +131,19 @@ typedef struct TSLanguage {
#define STATE(id) id #define STATE(id) id
#define ACTIONS(id) id #define ACTIONS(id) id
#define SHIFT(to_state_value) \ #define SHIFT(state_value) \
{ \ { \
{ \ { \
.type = TSParseActionTypeShift, \ .type = TSParseActionTypeShift, \
.to_state = to_state_value, \ .params = {.state = state_value}, \
} \ } \
} }
#define RECOVER(to_state_value) \ #define RECOVER(state_value) \
{ \ { \
{ \ { \
.type = TSParseActionTypeRecover, \ .type = TSParseActionTypeRecover, \
.to_state = to_state_value \ .params = {.state = state_value} \
} \ } \
} }
@ -151,7 +151,7 @@ typedef struct TSLanguage {
{ \ { \
{ \ { \
.type = TSParseActionTypeShift, \ .type = TSParseActionTypeShift, \
.extra = true \ .params = {.extra = true} \
} \ } \
} }
@ -159,9 +159,11 @@ typedef struct TSLanguage {
{ \ { \
{ \ { \
.type = TSParseActionTypeReduce, \ .type = TSParseActionTypeReduce, \
.symbol = symbol_val, \ .params = { \
.child_count = child_count_val, \ .symbol = symbol_val, \
__VA_ARGS__ \ .child_count = child_count_val, \
__VA_ARGS__ \
} \
} \ } \
} }
@ -170,23 +172,24 @@ typedef struct TSLanguage {
{ .type = TSParseActionTypeAccept } \ { .type = TSParseActionTypeAccept } \
} }
#define GET_LANGUAGE(...) \ #define GET_LANGUAGE(...) \
static TSLanguage language = { \ static TSLanguage language = { \
.version = LANGUAGE_VERSION, \ .version = LANGUAGE_VERSION, \
.symbol_count = SYMBOL_COUNT, \ .symbol_count = SYMBOL_COUNT, \
.token_count = TOKEN_COUNT, \ .alias_count = ALIAS_COUNT, \
.symbol_metadata = ts_symbol_metadata, \ .token_count = TOKEN_COUNT, \
.parse_table = (const unsigned short *)ts_parse_table, \ .symbol_metadata = ts_symbol_metadata, \
.parse_actions = ts_parse_actions, \ .parse_table = (const unsigned short *)ts_parse_table, \
.lex_modes = ts_lex_modes, \ .parse_actions = ts_parse_actions, \
.symbol_names = ts_symbol_names, \ .lex_modes = ts_lex_modes, \
.rename_sequences = (const TSSymbol *)ts_rename_sequences, \ .symbol_names = ts_symbol_names, \
.max_rename_sequence_length = MAX_RENAME_SEQUENCE_LENGTH, \ .alias_sequences = (const TSSymbol *)ts_alias_sequences, \
.lex_fn = ts_lex, \ .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH, \
.external_token_count = EXTERNAL_TOKEN_COUNT, \ .lex_fn = ts_lex, \
.external_scanner = {__VA_ARGS__} \ .external_token_count = EXTERNAL_TOKEN_COUNT, \
}; \ .external_scanner = {__VA_ARGS__} \
return &language \ }; \
return &language \
#ifdef __cplusplus #ifdef __cplusplus
} }