build: generate parser

pull/874/head
Christian Clason 2024-04-27 17:34:50 +07:00
parent 83ae738bed
commit bf2a65b1c1
4 changed files with 3357 additions and 3733 deletions

@ -133,8 +133,7 @@ module.exports = grammar(clojure, {
[$.with_clause, $.package_lit],
[$.with_clause],
[$.for_clause],
[$.accumulation_clause],
[$.loop_macro, $.defun_keyword, $.package_lit]],
[$.accumulation_clause]],
rules: {

5
src/grammar.json generated

@ -4461,11 +4461,6 @@
],
[
"accumulation_clause"
],
[
"loop_macro",
"defun_keyword",
"package_lit"
]
],
"precedences": [],

7033
src/parser.c generated

File diff suppressed because it is too large Load Diff

@ -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,12 +237,15 @@ struct TSLanguage {
} \
}}
#define REDUCE(...) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
__VA_ARGS__ \
}, \
#define REDUCE(symbol_name, children, precedence, prod_id) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_name, \
.child_count = children, \
.dynamic_precedence = precedence, \
.production_id = prod_id \
}, \
}}
#define RECOVER() \