aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-dataloader/v2script/TriggerGrammar.hpp
blob: 290fb70afbeb241a3520a1c7c79c1143ba162391 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 {};
         });
   };
}