diff options
author | George L. Albany <Megacake1234@gmail.com> | 2023-09-02 14:31:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-02 14:31:44 +0200 |
commit | f990117e56060811ddd2a850ec712485aea79649 (patch) | |
tree | 2bb062c320fa2227b18956617b94d0e8800420d8 /src/openvic-dataloader/v2script/TriggerGrammar.hpp | |
parent | e941573f47fb867ff75c8a2cf78302b754ffbeee (diff) | |
parent | 7440a5d1433eec4bf87e3723022db187e7f61b1a (diff) |
Merge pull request #7 from OpenVicProject/dataloading-event-and-functions
Diffstat (limited to 'src/openvic-dataloader/v2script/TriggerGrammar.hpp')
-rw-r--r-- | src/openvic-dataloader/v2script/TriggerGrammar.hpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/openvic-dataloader/v2script/TriggerGrammar.hpp b/src/openvic-dataloader/v2script/TriggerGrammar.hpp new file mode 100644 index 0000000..290fb70 --- /dev/null +++ b/src/openvic-dataloader/v2script/TriggerGrammar.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp> + +#include <lexy/callback.hpp> +#include <lexy/dsl.hpp> + +#include "SimpleGrammar.hpp" + +namespace ovdl::v2script::grammar { + struct TriggerStatement { + static constexpr auto rule = lexy::dsl::inline_<SimpleAssignmentStatement>; + + static constexpr auto value = lexy::callback<ast::NodePtr>( + [](auto name, auto&& initalizer) { + return ast::make_node_ptr<ast::ExecutionNode>(ast::ExecutionNode::Type::Trigger, LEXY_MOV(name), LEXY_MOV(initalizer)); + }); + }; + + struct TriggerList { + static constexpr auto rule = lexy::dsl::list(lexy::dsl::p<SimpleAssignmentStatement>); + + static constexpr auto value = + lexy::as_list<std::vector<ast::NodePtr>> >> + lexy::callback<ast::NodePtr>( + [](auto&& list) { + return ast::make_node_ptr<ast::ExecutionListNode>(ast::ExecutionNode::Type::Trigger, LEXY_MOV(list)); + }); + }; + + struct TriggerBlock { + static constexpr auto rule = lexy::dsl::curly_bracketed.opt(lexy::dsl::p<TriggerList>); + + static constexpr auto value = lexy::callback<ast::NodePtr>( + [](auto&& list) { + return LEXY_MOV(list); + }, + [](lexy::nullopt = {}) { + return lexy::nullopt {}; + }); + }; +}
\ No newline at end of file |