Improve highlighting structure

- switched to a sparse delta based map
- true lazy-loading to avoid any unneccessary allocations
- fixed windows management api
This commit is contained in:
2026-02-11 18:18:28 +00:00
parent d79ea4e75a
commit 5b66f503e4
24 changed files with 481 additions and 549 deletions

View File

@@ -4,29 +4,19 @@
#include "syntax/decl.h"
#define DEF_LANG(name) \
std::shared_ptr<void> name##_parse( \
std::vector<Token> *tokens, std::shared_ptr<void> in_state, \
const char *text, uint32_t len, uint32_t line_num); \
bool name##_state_match(std::shared_ptr<void> state_1, \
std::shared_ptr<void> state_2);
std::unique_ptr<StateBase> name##_parse( \
std::vector<Token> *tokens, StateBase *in_state, const char *text, \
uint32_t len, uint32_t line_num); \
bool name##_state_match(StateBase *state_1, StateBase *state_2);
#define LANG_A(name) \
{ \
#name, { name##_parse, name##_state_match } \
}
template <typename T>
inline std::shared_ptr<T> ensure_state(std::shared_ptr<T> state) {
using U = typename T::full_state_type;
if (!state)
state = std::make_shared<T>();
if (!state.unique())
state = std::make_shared<T>(*state);
if (!state->full_state)
state->full_state = std::make_shared<U>();
else if (!state->full_state.unique())
state->full_state = std::make_shared<U>(*state->full_state);
return state;
template <typename B, typename A>
std::unique_ptr<B> static_unique_ptr_cast(std::unique_ptr<A> &&p) {
return std::unique_ptr<B>(static_cast<B *>(p.release()));
}
DEF_LANG(ruby);
@@ -34,11 +24,10 @@ DEF_LANG(bash);
inline static const std::unordered_map<
std::string,
std::tuple<std::shared_ptr<void> (*)(
std::vector<Token> *tokens, std::shared_ptr<void> in_state,
std::tuple<std::unique_ptr<StateBase> (*)(
std::vector<Token> *tokens, StateBase *in_state,
const char *text, uint32_t len, uint32_t line_num),
bool (*)(std::shared_ptr<void> state_1,
std::shared_ptr<void> state_2)>>
bool (*)(StateBase *state_1, StateBase *state_2)>>
parsers = {
LANG_A(ruby),
LANG_A(bash),