aboutsummaryrefslogtreecommitdiff
path: root/include/openvic-dataloader/v2script/Parser.hpp
blob: 1c524b2cb5451bc9714208d61664a31691dfb399 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once

#include <cstddef>
#include <filesystem>
#include <functional>
#include <memory>
#include <optional>
#include <ostream>
#include <string_view>
#include <vector>

#include <openvic-dataloader/ParseError.hpp>
#include <openvic-dataloader/ParseWarning.hpp>
#include <openvic-dataloader/detail/BasicParser.hpp>
#include <openvic-dataloader/detail/Concepts.hpp>
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>

namespace ovdl::v2script {

   using FileNode = ast::FileNode;

   class Parser final : public detail::BasicParser {
   public:
      Parser();

      static Parser from_buffer(const char* data, std::size_t size);
      static Parser from_buffer(const char* start, const char* end);
      static Parser from_string(const std::string_view string);
      static Parser from_file(const char* path);
      static Parser from_file(const std::filesystem::path& path);

      constexpr Parser& load_from_buffer(const char* data, std::size_t size);
      constexpr Parser& load_from_buffer(const char* start, const char* end);
      constexpr Parser& load_from_string(const std::string_view string);
      constexpr Parser& load_from_file(const char* path);
      Parser& load_from_file(const std::filesystem::path& path);

      constexpr Parser& load_from_file(const detail::Has_c_str auto& path);

      bool simple_parse();
      bool event_parse();
      bool decision_parse();

      const FileNode* get_file_node() const;

      Parser(Parser&&);
      Parser& operator=(Parser&&);

      ~Parser();

   private:
      class BufferHandler;
      std::unique_ptr<BufferHandler> _buffer_handler;
      std::unique_ptr<FileNode> _file_node;

      template<typename... Args>
      constexpr void _run_load_func(detail::LoadCallback<BufferHandler, Args...> auto func, Args... args);
   };
}