diff options
author | Spartan322 <Megacake1234@gmail.com> | 2023-08-24 23:29:52 +0200 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2023-08-24 23:29:52 +0200 |
commit | 6add5bd2298c7ce7e27144b7db28aecec60fd1dd (patch) | |
tree | 1f04f10be2c588ecafa764ccd4ce893b035b4450 /src/openvic-dataloader/v2script | |
parent | 9d530253ee944228d5d19e6ae41d93e3e2b8cfbc (diff) |
Cleanup and streamlineevent-and-decisions
Diffstat (limited to 'src/openvic-dataloader/v2script')
6 files changed, 28 insertions, 16 deletions
diff --git a/src/openvic-dataloader/v2script/AiBehaviorGrammar.hpp b/src/openvic-dataloader/v2script/AiBehaviorGrammar.hpp index a772a7c..bbdc67d 100644 --- a/src/openvic-dataloader/v2script/AiBehaviorGrammar.hpp +++ b/src/openvic-dataloader/v2script/AiBehaviorGrammar.hpp @@ -26,7 +26,7 @@ namespace ovdl::v2script::grammar { return LEXY_MOV(list); }, [](lexy::nullopt = {}) { - return nullptr; + return lexy::nullopt {}; }); }; }
\ No newline at end of file diff --git a/src/openvic-dataloader/v2script/DecisionGrammar.hpp b/src/openvic-dataloader/v2script/DecisionGrammar.hpp index 3e77616..e6e3b57 100644 --- a/src/openvic-dataloader/v2script/DecisionGrammar.hpp +++ b/src/openvic-dataloader/v2script/DecisionGrammar.hpp @@ -103,7 +103,7 @@ namespace ovdl::v2script::grammar { return ast::make_node_ptr<ast::DecisionListNode>(LEXY_MOV(list)); }, [](lexy::nullopt = {}) { - return nullptr; + return lexy::nullopt {}; }); }; diff --git a/src/openvic-dataloader/v2script/EffectGrammar.hpp b/src/openvic-dataloader/v2script/EffectGrammar.hpp index 71697c4..db35f02 100644 --- a/src/openvic-dataloader/v2script/EffectGrammar.hpp +++ b/src/openvic-dataloader/v2script/EffectGrammar.hpp @@ -34,7 +34,7 @@ namespace ovdl::v2script::grammar { return LEXY_MOV(list); }, [](lexy::nullopt = {}) { - return nullptr; + return lexy::nullopt {}; }); }; }
\ No newline at end of file diff --git a/src/openvic-dataloader/v2script/EventGrammar.hpp b/src/openvic-dataloader/v2script/EventGrammar.hpp index 216d645..4a64ce4 100644 --- a/src/openvic-dataloader/v2script/EventGrammar.hpp +++ b/src/openvic-dataloader/v2script/EventGrammar.hpp @@ -49,8 +49,13 @@ namespace ovdl::v2script::grammar { struct EventMtthStatement { OVDL_GRAMMAR_KEYWORD_DEFINE(months); + struct MonthValue { + static constexpr auto rule = lexy::dsl::inline_<Identifier>; + static constexpr auto value = lexy::as_string<std::string> | lexy::new_<ast::MonthNode, ast::NodePtr>; + }; + static constexpr auto rule = lexy::dsl::list( - (months_p >> lexy::dsl::p<Identifier>) | + (months_p >> lexy::dsl::p<MonthValue>) | lexy::dsl::p<ModifierStatement>); static constexpr auto value = @@ -61,6 +66,20 @@ namespace ovdl::v2script::grammar { }); }; + template<auto Production, typename AstNode> + struct _StringStatement { + static constexpr auto rule = Production >> (lexy::dsl::p<StringExpression> | lexy::dsl::p<Identifier>); + static constexpr auto value = + lexy::callback<ast::NodePtr>( + [](auto&& value) { + auto result = ast::make_node_ptr<AstNode>(std::move(static_cast<ast::AbstractStringNode*>(value)->_name)); + delete value; + return result; + }); + }; + template<auto Production, typename AstNode> + static constexpr auto StringStatement = lexy::dsl::p<_StringStatement<Production, AstNode>>; + struct EventOptionList { OVDL_GRAMMAR_KEYWORD_FLAG_DEFINE(name); OVDL_GRAMMAR_KEYWORD_FLAG_DEFINE(ai_chance); @@ -68,7 +87,7 @@ namespace ovdl::v2script::grammar { static constexpr auto rule = [] { constexpr auto create_flags = name_rule::flag.create() + ai_chance_rule::flag.create(); - constexpr auto name_statement = name_p >> (lexy::dsl::p<StringExpression> | lexy::dsl::p<Identifier>); + constexpr auto name_statement = StringStatement<name_p, ast::NameNode>; constexpr auto ai_chance_statement = ai_chance_p >> lexy::dsl::curly_bracketed(lexy::dsl::p<AiBehaviorList>); return create_flags + lexy::dsl::list(name_statement | ai_chance_statement | lexy::dsl::p<EffectList>); @@ -83,14 +102,6 @@ namespace ovdl::v2script::grammar { }; struct EventStatement { - template<auto Production, typename AstNode> - struct _StringStatement { - static constexpr auto rule = Production >> (lexy::dsl::p<StringExpression> | lexy::dsl::p<Identifier>); - static constexpr auto value = lexy::forward<ast::NodePtr>; - }; - template<auto Production, typename AstNode> - static constexpr auto StringStatement = lexy::dsl::p<_StringStatement<Production, AstNode>>; - OVDL_GRAMMAR_KEYWORD_FLAG_DEFINE(id); OVDL_GRAMMAR_KEYWORD_FLAG_DEFINE(title); OVDL_GRAMMAR_KEYWORD_FLAG_DEFINE(desc); diff --git a/src/openvic-dataloader/v2script/ModifierGrammar.hpp b/src/openvic-dataloader/v2script/ModifierGrammar.hpp index 2b28712..74deef7 100644 --- a/src/openvic-dataloader/v2script/ModifierGrammar.hpp +++ b/src/openvic-dataloader/v2script/ModifierGrammar.hpp @@ -3,14 +3,15 @@ #include "SimpleGrammar.hpp" #include "TriggerGrammar.hpp" #include <lexy/dsl.hpp> +#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp> namespace ovdl::v2script::grammar { constexpr auto modifier_keyword = LEXY_KEYWORD("modifier", lexy::dsl::inline_<Identifier>); constexpr auto factor_keyword = LEXY_KEYWORD("factor", lexy::dsl::inline_<Identifier>); struct FactorStatement { - static constexpr auto rule = factor_keyword >> lexy::dsl::equal_sign + lexy::dsl::p<Identifier>; - static constexpr auto value = lexy::forward<ast::NodePtr>; + static constexpr auto rule = factor_keyword >> lexy::dsl::equal_sign + lexy::dsl::inline_<Identifier>; + static constexpr auto value = lexy::as_string<std::string> | lexy::new_<ast::FactorNode, ast::NodePtr>; }; struct ModifierStatement { diff --git a/src/openvic-dataloader/v2script/TriggerGrammar.hpp b/src/openvic-dataloader/v2script/TriggerGrammar.hpp index 514da49..ffed1d3 100644 --- a/src/openvic-dataloader/v2script/TriggerGrammar.hpp +++ b/src/openvic-dataloader/v2script/TriggerGrammar.hpp @@ -34,7 +34,7 @@ namespace ovdl::v2script::grammar { return LEXY_MOV(list); }, [](lexy::nullopt = {}) { - return nullptr; + return lexy::nullopt {}; }); }; }
\ No newline at end of file |