aboutsummaryrefslogtreecommitdiff
path: root/include/openvic-dataloader/v2script/Parser.hpp
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-11-28 11:09:26 +0100
committer Spartan322 <Megacake1234@gmail.com>2024-05-09 22:11:26 +0200
commit757114a3c5b748567b42f273c7b78ca039ae983c (patch)
treee07390b682052129c91f4b157068bcdd84ceecb4 /include/openvic-dataloader/v2script/Parser.hpp
parent7211a228e68c8a6b1ad1c1c5ec68c8d720b6d2ba (diff)
Add `deps/dryad` -> https://github.com/Spartan322/dryadadd/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`
Diffstat (limited to 'include/openvic-dataloader/v2script/Parser.hpp')
-rw-r--r--include/openvic-dataloader/v2script/Parser.hpp46
1 files changed, 30 insertions, 16 deletions
diff --git a/include/openvic-dataloader/v2script/Parser.hpp b/include/openvic-dataloader/v2script/Parser.hpp
index 885946d..cef1faf 100644
--- a/include/openvic-dataloader/v2script/Parser.hpp
+++ b/include/openvic-dataloader/v2script/Parser.hpp
@@ -3,21 +3,26 @@
#include <cstddef>
#include <filesystem>
#include <memory>
+#include <ostream>
+#include <string>
#include <string_view>
-#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/Error.hpp>
+#include <openvic-dataloader/NodeLocation.hpp>
+#include <openvic-dataloader/Parser.hpp>
+#include <openvic-dataloader/detail/utility/Concepts.hpp>
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
-namespace ovdl::v2script {
+#include <dryad/node.hpp>
- using FileNode = ast::FileNode;
+namespace ovdl::v2script {
+ using FileTree = ast::FileTree;
+ using FilePosition = ovdl::FilePosition;
class Parser final : public detail::BasicParser {
public:
Parser();
+ Parser(std::basic_ostream<char>& error_stream);
static Parser from_buffer(const char* data, std::size_t size);
static Parser from_buffer(const char* start, const char* end);
@@ -31,19 +36,30 @@ namespace ovdl::v2script {
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);
+ constexpr Parser& load_from_file(const detail::HasCstr auto& path) {
+ return load_from_file(path.c_str());
+ }
bool simple_parse();
bool event_parse();
bool decision_parse();
bool lua_defines_parse();
- const FileNode* get_file_node() const;
+ const FileTree* get_file_node() const;
+
+ std::string_view value(const ovdl::v2script::ast::FlatValue& node) const;
+
+ std::string make_native_string() const;
+ std::string make_list_string() const;
+
+ const FilePosition get_position(const ast::Node* node) const;
+
+ using error_range = ovdl::detail::error_range;
+ Parser::error_range get_errors() const;
- void generate_node_location_map();
+ const FilePosition get_error_position(const error::Error* error) const;
- const ast::Node::line_col get_node_begin(const ast::NodeCPtr node) const;
- const ast::Node::line_col get_node_end(const ast::NodeCPtr node) const;
+ void print_errors_to(std::basic_ostream<char>& stream) const;
Parser(Parser&&);
Parser& operator=(Parser&&);
@@ -51,12 +67,10 @@ namespace ovdl::v2script {
~Parser();
private:
- friend class ::ovdl::v2script::ast::Node;
- class BufferHandler;
- std::unique_ptr<BufferHandler> _buffer_handler;
- std::unique_ptr<FileNode> _file_node;
+ class ParseHandler;
+ std::unique_ptr<ParseHandler> _parse_handler;
template<typename... Args>
- constexpr void _run_load_func(detail::LoadCallback<BufferHandler, Args...> auto func, Args... args);
+ constexpr void _run_load_func(detail::LoadCallback<Parser::ParseHandler*, Args...> auto func, Args... args);
};
} \ No newline at end of file