From 757114a3c5b748567b42f273c7b78ca039ae983c Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Tue, 28 Nov 2023 05:09:26 -0500 Subject: Add `deps/dryad` -> https://github.com/Spartan322/dryad Add `deps/fmt` -> https://github.com/fmtlib/fmt Add `deps/range-v3` -> https://github.com/ericniebler/range-v3 Improve parser error and warning support Update .clang-format Update `deps/SCsub` --- .../v2script/ModifierGrammar.hpp | 49 ++++++++++++++++------ 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'src/openvic-dataloader/v2script/ModifierGrammar.hpp') diff --git a/src/openvic-dataloader/v2script/ModifierGrammar.hpp b/src/openvic-dataloader/v2script/ModifierGrammar.hpp index 96e928c..5b937d5 100644 --- a/src/openvic-dataloader/v2script/ModifierGrammar.hpp +++ b/src/openvic-dataloader/v2script/ModifierGrammar.hpp @@ -2,32 +2,55 @@ #include +#include #include +#include +#include + +#include "openvic-dataloader/NodeLocation.hpp" + #include "SimpleGrammar.hpp" #include "TriggerGrammar.hpp" +#include "detail/dsl.hpp" namespace ovdl::v2script::grammar { constexpr auto modifier_keyword = LEXY_KEYWORD("modifier", lexy::dsl::inline_>); constexpr auto factor_keyword = LEXY_KEYWORD("factor", lexy::dsl::inline_>); struct FactorStatement { - static constexpr auto rule = factor_keyword >> lexy::dsl::equal_sign + lexy::dsl::inline_>; - static constexpr auto value = lexy::as_string | lexy::new_; + static constexpr auto rule = lexy::dsl::position(factor_keyword) >> (lexy::dsl::equal_sign + lexy::dsl::p>); + static constexpr auto value = dsl::callback( + [](ast::ParseState& state, NodeLocation loc, ast::IdentifierValue* value) { + auto* factor = state.ast().create(loc, state.ast().intern("factor")); + return state.ast().create(loc, factor, value); + }); + }; + + struct ModifierList { + struct expected_factor { + static constexpr auto name = "expected factor in modifier"; + }; + + static constexpr auto rule = [] { + auto factor_flag = lexy::dsl::context_flag; + + auto element = (lexy::dsl::p >> factor_flag.set()) | lexy::dsl::p; + + return dsl::curly_bracketed.list(factor_flag.create() + element) >> lexy::dsl::must(factor_flag.is_reset()).error; + }(); + + static constexpr auto value = lexy::as_list >> construct_list; }; struct ModifierStatement { static constexpr auto rule = - modifier_keyword >> - lexy::dsl::curly_bracketed.list( - lexy::dsl::p | - lexy::dsl::p); - - static constexpr auto value = - lexy::as_list> >> - lexy::callback( - [](auto&& list) { - return ast::make_node_ptr(LEXY_MOV(list)); - }); + lexy::dsl::position(modifier_keyword) >> lexy::dsl::equal_sign >> lexy::dsl::p; + + static constexpr auto value = dsl::callback( + [](ast::ParseState& state, NodeLocation loc, ast::ListValue* list) { + auto* factor = state.ast().create(loc, state.ast().intern("modifier")); + return state.ast().create(loc, factor, list); + }); }; } \ No newline at end of file -- cgit v1.2.3-56-ga3b1