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
+17 -11
View File
@@ -10,7 +10,7 @@ struct BashFullState {
bool line_cont = false;
struct Lit {
std::string delim = ""; // Only 1 wide for strings
std::string delim = "";
bool allow_interp = false;
bool operator==(const BashFullState::Lit &other) const {
@@ -24,7 +24,7 @@ struct BashFullState {
}
};
struct BashState {
struct BashState : StateBase {
using full_state_type = BashFullState;
int interp_level = 0;
@@ -37,26 +37,32 @@ struct BashState {
((full_state && other.full_state &&
*full_state == *other.full_state));
}
std::unique_ptr<StateBase> clone() const override {
return std::make_unique<BashState>(*this);
}
};
bool bash_state_match(std::shared_ptr<void> state_1,
std::shared_ptr<void> state_2) {
bool bash_state_match(StateBase *state_1, StateBase *state_2) {
if (!state_1 || !state_2)
return false;
return *std::static_pointer_cast<BashState>(state_1) ==
*std::static_pointer_cast<BashState>(state_2);
return *static_cast<BashState *>(state_1) ==
*static_cast<BashState *>(state_2);
}
std::shared_ptr<void> bash_parse(std::vector<Token> *tokens,
std::shared_ptr<void> in_state,
const char *text, uint32_t len,
uint32_t line_num) {
std::unique_ptr<StateBase> bash_parse(std::vector<Token> *tokens,
StateBase *in_state, const char *text,
uint32_t len, uint32_t line_num) {
static bool keywords_trie_init = false;
if (!keywords_trie_init) {
keywords_trie_init = true;
}
tokens->clear();
auto state = ensure_state(std::static_pointer_cast<BashState>(in_state));
std::unique_ptr<BashState> state;
if (in_state)
state = static_unique_ptr_cast<BashState>(in_state->clone());
else
state = std::make_unique<BashState>();
uint32_t i = 0;
while (len > 0 && (text[len - 1] == '\n' || text[len - 1] == '\r' ||
text[len - 1] == '\t' || text[len - 1] == ' '))