38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
#include "internal/syntax/c/parser.h"
|
|
|
|
namespace bed::internal::syntax::c {
|
|
Language lang_c() {
|
|
return Language{
|
|
.none_state = []() {
|
|
CState *st = (CState *)malloc(
|
|
sizeof(CState)
|
|
+ sizeof(CState::CInternalState)
|
|
);
|
|
st->top = 1;
|
|
st->stack()[0] = {
|
|
.brace_level = 1,
|
|
.state = CState::CInternalState::NONE,
|
|
.flags = 0
|
|
};
|
|
return st; },
|
|
.parse = c_parse,
|
|
.copy = [](void *v_i_st) {
|
|
CState *i_st = (CState *)v_i_st;
|
|
uint32_t bytes = sizeof(CState)
|
|
+ sizeof(CState::CInternalState) * i_st->top;
|
|
CState *o_st = (CState *)malloc(bytes);
|
|
memcpy(o_st, i_st, bytes);
|
|
return o_st; },
|
|
.equal = [](void *v_a_st, void *v_b_st) {
|
|
CState *a_st = (CState *)v_a_st;
|
|
uint32_t a_bytes = sizeof(CState)
|
|
+ sizeof(CState::CInternalState) * a_st->top;
|
|
CState *b_st = (CState *)v_b_st;
|
|
uint32_t b_bytes = sizeof(CState)
|
|
+ sizeof(CState::CInternalState) * b_st->top;
|
|
return a_bytes == b_bytes && memcmp(a_st, b_st, a_bytes) == 0; },
|
|
.destroy = [](void *v_st) { free(v_st); },
|
|
};
|
|
}
|
|
} // namespace bed::internal::syntax::c
|