Implement single-char state transitions using a static array and for loop

This reduces compile time, compared to generating many individual if statements.
This commit is contained in:
Max Brunsfeld 2024-04-12 14:34:03 -07:00
parent 3210c7e21f
commit 7ec40b0ab4
2 changed files with 51 additions and 3 deletions

View file

@ -177,6 +177,17 @@ static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t
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; \