58 using TK = tokens__::TYPE;
59 using error_type = error::parser_error::enum_type;
62 std::vector<tokens__> _in;
75 [[nodiscard]]
tokens__ f_peek_at(
const std::size_t off)
const noexcept {
76 return _in[_curs + off];
83 [[nodiscard]]
tokens__ f_previous()
const noexcept {
84 return _in[_curs - 1];
91 [[nodiscard]]
tokens__ f_peek_next()
const noexcept {
92 return _in[_curs + 1];
99 [[nodiscard]]
tokens__ f_peek()
const noexcept {
118 return traits::any_of(f_peek()._token_type, tokens__::TYPE::TK_EOF);
126 bool check(tokens__::TYPE t) {
129 return f_peek()._token_type == t;
139 template <
typename... Args>
140 requires(std::is_same_v<Args, tokens__::TYPE> && ...)
141 bool f_match(Args&&... args) {
142 if ((check(args) || ...)) {
156 template <
typename... Args>
157 [[nodiscard]]
decltype(
auto) to_value(std::variant<Args...> var)
const noexcept {
167 if (f_match(TK::TK_CURL_L)) {
168 std::unordered_map<std::string, circ_variable> obj = f_parse();
169 if (f_match(TK::TK_CURL_R)) {
175 if (f_match(TK::TK_BRACE_L)) {
176 std::vector<circ_variable> arr = f_parse_array();
177 if (!f_match(TK::TK_BRACE_R)) {
183 return to_value(f_advance().literal);
191 std::vector<circ_variable> f_parse_array() {
192 std::vector<circ_variable> ret{};
193 std::size_t index = 0;
194 while (!f_eof() && !check(TK::TK_BRACE_R)) {
196 var.
value = f_parse_primary();
197 var.
key = std::to_string(index++);
198 if (!check(TK::TK_BRACE_R)) {
199 if (!f_match(TK::TK_COMMA)) {
205 if (check(TK::TK_BRACE_R) && f_previous()._token_type == TK::TK_COMMA) {
218 var.
key = f_previous().embedded;
219 if (f_match(TK::TK_COLON)) {
220 var.
value = f_parse_primary();
221 if (!f_eof() && !check(TK::TK_CURL_R)) {
222 if (!f_match(TK::TK_COMMA)) {
237 if (f_match(TK::TK_IDENTIFIER)) {
238 return f_parse_value();
249 if (!f_eof() && f_match(TK::TK_DOLLA)) {
250 return f_parse_identifier();
259 if (!f_eof()) f_advance();
261 if (check(TK::TK_DOLLA))
return;
271 std::unordered_map<std::string, circ_variable> f_parse() {
272 std::unordered_map<std::string, circ_variable> ret{};
273 bool had_error =
false;
276 if (check(TK::TK_CURL_R))
278 auto v = f_parse_decl();
279 ret.insert(std::make_pair(v.key, v));
281 _reporter.report(error.type_of, error.what(), f_previous().location);
286 _reporter.log_errors();
288 throw std::runtime_error(
"halted execution due to parser incomprehension, revise circ source input");
304 std::unordered_map<std::string, circ_variable>
operator()(std::vector<tokens__> toks) {
std::unordered_map< std::string, circ_variable > operator()(std::vector< tokens__ > toks)
Parse tokens into Circus variables.
Definition parser.hpp:304
std::variant< char, std::string, int, float, double, std::vector< circ_variable >, std::unordered_map< std::string, circ_variable > > circ_type_var_t
Variant holding possible Circus variable types.
Definition parser.hpp:28