Add basic c syntax highlighting.

This commit is contained in:
2026-09-14 11:25:29 +01:00
parent 8f67be87ee
commit 6711ecbaee
8 changed files with 448 additions and 1 deletions
+65
View File
@@ -0,0 +1,65 @@
#pragma once
#include "decl.h"
#include "pch.h"
namespace bed::internal::syntax::c {
struct CParser {
void **v_state;
CState *state;
std::string_view line;
bool still_empty = true;
uint32_t i = 0;
CParser(void **v_state, std::string_view line)
: v_state(v_state), state((CState *)*v_state), line(line) {}
uint32_t len() const {
return line.size();
}
CState::CInternalState &current() {
return state->stack()[state->top - 1];
}
char peek(int32_t offset = 0) {
uint32_t pos = i + offset;
return pos < line.size() ? line[pos] : '\0';
}
std::string_view peek_str(uint32_t len) {
return line.substr(i, len);
}
void advance() {
++i;
}
void advance(uint32_t n) {
i += n;
}
void push_state() {
state->top++;
state = (CState *)realloc(
state,
sizeof(CState)
+ sizeof(CState::CInternalState) * state->top
);
current() = {
.brace_level = 1,
.state = CState::CInternalState::NONE,
.flags = 0
};
}
void pop_state() {
state->top--;
}
};
void c_parse(
void **v_state, std::string_view line, bool first_line,
std::vector<io::Token> *tokens, std::vector<ParseEvent> *events
);
} // namespace bed::internal::syntax::c