build: regenerate parser

This commit is contained in:
ObserverOfTime 2024-04-30 12:06:12 +03:00
parent 49db816e6a
commit 49b7f874e6
No known key found for this signature in database
GPG key ID: 8A2DEA1DBAEBCA9E
9 changed files with 125 additions and 49 deletions

View file

@ -89,17 +89,19 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
switch (state) {
case 0:
if (eof) ADVANCE(34);
if (lookahead == '+' ||
lookahead == '-') ADVANCE(1);
if (lookahead == '.') ADVANCE(6);
if (lookahead == '0') ADVANCE(37);
if (lookahead == 'F') ADVANCE(2);
if (lookahead == 'N') ADVANCE(16);
if (lookahead == 'T') ADVANCE(13);
if (lookahead == 'f') ADVANCE(17);
if (lookahead == 'n') ADVANCE(29);
if (lookahead == 't') ADVANCE(26);
if (lookahead == '~') ADVANCE(35);
ADVANCE_MAP(
'.', 6,
'0', 37,
'F', 2,
'N', 16,
'T', 13,
'f', 17,
'n', 29,
't', 26,
'~', 35,
'+', 1,
'-', 1,
);
if (('1' <= lookahead && lookahead <= '9')) ADVANCE(38);
END_STATE();
case 1:
@ -313,7 +315,7 @@ static const TSParseActionEntry ts_parse_actions[] = {
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(),
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2),
[5] = {.entry = {.count = 1, .reusable = false}}, SHIFT(2),
[7] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_scalar, 1),
[7] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_scalar, 1, 0, 0),
[9] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(),
};
@ -328,7 +330,7 @@ extern "C" {
#define TS_PUBLIC __attribute__((visibility("default")))
#endif
TS_PUBLIC const TSLanguage *tree_sitter_core_schema() {
TS_PUBLIC const TSLanguage *tree_sitter_core_schema(void) {
static const TSLanguage language = {
.version = LANGUAGE_VERSION,
.symbol_count = SYMBOL_COUNT,

View file

@ -86,6 +86,11 @@ typedef union {
} entry;
} TSParseActionEntry;
typedef struct {
int32_t start;
int32_t end;
} TSCharacterRange;
struct TSLanguage {
uint32_t version;
uint32_t symbol_count;
@ -125,6 +130,24 @@ struct TSLanguage {
const TSStateId *primary_state_ids;
};
static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
uint32_t index = 0;
uint32_t size = len - index;
while (size > 1) {
uint32_t half_size = size / 2;
uint32_t mid_index = index + half_size;
TSCharacterRange *range = &ranges[mid_index];
if (lookahead >= range->start && lookahead <= range->end) {
return true;
} else if (lookahead > range->end) {
index = mid_index;
}
size -= half_size;
}
TSCharacterRange *range = &ranges[index];
return (lookahead >= range->start && lookahead <= range->end);
}
/*
* Lexer Macros
*/
@ -154,6 +177,17 @@ struct TSLanguage {
goto next_state; \
}
#define ADVANCE_MAP(...) \
{ \
static const uint16_t map[] = { __VA_ARGS__ }; \
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
if (map[i] == lookahead) { \
state = map[i + 1]; \
goto next_state; \
} \
} \
}
#define SKIP(state_value) \
{ \
skip = true; \
@ -203,13 +237,14 @@ struct TSLanguage {
} \
}}
#define REDUCE(symbol_val, child_count_val, ...) \
#define REDUCE(symbol_name, children, precedence, prod_id) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_val, \
.child_count = child_count_val, \
__VA_ARGS__ \
.symbol = symbol_name, \
.child_count = children, \
.dynamic_precedence = precedence, \
.production_id = prod_id \
}, \
}}

View file

@ -215,7 +215,7 @@ static const TSParseActionEntry ts_parse_actions[] = {
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(),
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2),
[5] = {.entry = {.count = 1, .reusable = false}}, SHIFT(2),
[7] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_scalar, 1),
[7] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_scalar, 1, 0, 0),
[9] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(),
};
@ -230,7 +230,7 @@ extern "C" {
#define TS_PUBLIC __attribute__((visibility("default")))
#endif
TS_PUBLIC const TSLanguage *tree_sitter_json_schema() {
TS_PUBLIC const TSLanguage *tree_sitter_json_schema(void) {
static const TSLanguage language = {
.version = LANGUAGE_VERSION,
.symbol_count = SYMBOL_COUNT,

View file

@ -86,6 +86,11 @@ typedef union {
} entry;
} TSParseActionEntry;
typedef struct {
int32_t start;
int32_t end;
} TSCharacterRange;
struct TSLanguage {
uint32_t version;
uint32_t symbol_count;
@ -125,6 +130,24 @@ struct TSLanguage {
const TSStateId *primary_state_ids;
};
static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
uint32_t index = 0;
uint32_t size = len - index;
while (size > 1) {
uint32_t half_size = size / 2;
uint32_t mid_index = index + half_size;
TSCharacterRange *range = &ranges[mid_index];
if (lookahead >= range->start && lookahead <= range->end) {
return true;
} else if (lookahead > range->end) {
index = mid_index;
}
size -= half_size;
}
TSCharacterRange *range = &ranges[index];
return (lookahead >= range->start && lookahead <= range->end);
}
/*
* Lexer Macros
*/
@ -154,6 +177,17 @@ struct TSLanguage {
goto next_state; \
}
#define ADVANCE_MAP(...) \
{ \
static const uint16_t map[] = { __VA_ARGS__ }; \
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
if (map[i] == lookahead) { \
state = map[i + 1]; \
goto next_state; \
} \
} \
}
#define SKIP(state_value) \
{ \
skip = true; \
@ -203,13 +237,14 @@ struct TSLanguage {
} \
}}
#define REDUCE(symbol_val, child_count_val, ...) \
#define REDUCE(symbol_name, children, precedence, prod_id) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_val, \
.child_count = child_count_val, \
__VA_ARGS__ \
.symbol = symbol_name, \
.child_count = children, \
.dynamic_precedence = precedence, \
.production_id = prod_id \
}, \
}}

View file

@ -16,6 +16,9 @@ readFile(join(__dirname, schema, "src", "parser.c"), "utf8").then(input => {
cases
.map(([key, { content }]) => `${(key === "default" ? "default:" : `case ${key}:`)}\n${indent(content)}`)
.join("\n END_STATE();\n")
.replace(/\s+ADVANCE_MAP\(([^]+?)\);\n/, (_, map) => {
return map.replace(/'(.)', (\d+),/g, "if (lookahead == '$1') ADVANCE($2);");
})
.replace(/ADVANCE\((\d+)\);/g, (_, state) => {
const stateCase = cases.find(([key]) => key === state);
if (stateCase) {

2
src/parser.c generated
View file

@ -40504,7 +40504,7 @@ void tree_sitter_yaml_external_scanner_deserialize(void *, const char *, unsigne
#define TS_PUBLIC __attribute__((visibility("default")))
#endif
TS_PUBLIC const TSLanguage *tree_sitter_yaml() {
TS_PUBLIC const TSLanguage *tree_sitter_yaml(void) {
static const TSLanguage language = {
.version = LANGUAGE_VERSION,
.symbol_count = SYMBOL_COUNT,

6
src/schema.core.c generated
View file

@ -15,8 +15,6 @@ static int8_t adv_sch_stt(int8_t sch_stt, int32_t cur_chr, ResultSchema *rlt_sch
case SCH_STT_FRZ:
break;
case 0:
if (cur_chr == '+' ||
cur_chr == '-') {*rlt_sch = RS_STR; return 1;}
if (cur_chr == '.') {*rlt_sch = RS_STR; return 6;}
if (cur_chr == '0') {*rlt_sch = RS_INT; return 37;}
if (cur_chr == 'F') {*rlt_sch = RS_STR; return 2;}
@ -26,6 +24,8 @@ static int8_t adv_sch_stt(int8_t sch_stt, int32_t cur_chr, ResultSchema *rlt_sch
if (cur_chr == 'n') {*rlt_sch = RS_STR; return 29;}
if (cur_chr == 't') {*rlt_sch = RS_STR; return 26;}
if (cur_chr == '~') {*rlt_sch = RS_NULL; return 35;}
if (cur_chr == '+') {*rlt_sch = RS_STR; return 1;}
if (cur_chr == '-') {*rlt_sch = RS_STR; return 1;}
if (('1' <= cur_chr && cur_chr <= '9')) {*rlt_sch = RS_INT; return 38;}
break;
case 1:
@ -195,6 +195,6 @@ static int8_t adv_sch_stt(int8_t sch_stt, int32_t cur_chr, ResultSchema *rlt_sch
*rlt_sch = RS_STR;
return SCH_STT_FRZ;
}
if (cur_chr != '\r' && cur_chr != '\n' && cur_chr != ' ' && cur_chr != 0) {*rlt_sch = RS_STR;}
if (cur_chr != '\r' && cur_chr != '\n' && cur_chr != ' ' && cur_chr != 0) *rlt_sch = RS_STR;
return SCH_STT_FRZ;
}

2
src/schema.json.c generated
View file

@ -97,6 +97,6 @@ static int8_t adv_sch_stt(int8_t sch_stt, int32_t cur_chr, ResultSchema *rlt_sch
*rlt_sch = RS_STR;
return SCH_STT_FRZ;
}
if (cur_chr != '\r' && cur_chr != '\n' && cur_chr != ' ' && cur_chr != 0) {*rlt_sch = RS_STR;}
if (cur_chr != '\r' && cur_chr != '\n' && cur_chr != ' ' && cur_chr != 0) *rlt_sch = RS_STR;
return SCH_STT_FRZ;
}

View file

@ -161,8 +161,9 @@ static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t
#define START_LEXER() \
bool result = false; \
bool skip = false; \
UNUSED bool eof = false; \
UNUSED int32_t lookahead; \
UNUSED \
bool eof = false; \
int32_t lookahead; \
goto start; \
next_state: \
lexer->advance(lexer, skip); \
@ -244,7 +245,7 @@ static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t
.child_count = children, \
.dynamic_precedence = precedence, \
.production_id = prod_id \
} \
}, \
}}
#define RECOVER() \