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(
rename($.simple_variable_name, 'variable_name'),
alias($.simple_variable_name, $.variable_name),
$.special_variable_name
),

View File

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

3
src/grammar.json vendored
View File

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