#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 ¤t() { 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 *tokens, std::vector *events ); } // namespace bed::internal::syntax::c