diff options
author | Spartan322 <Megacake1234@gmail.com> | 2023-07-28 06:52:00 +0200 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2023-08-17 09:04:56 +0200 |
commit | 90f15b582788a9aab0dfe6c81fc4cbbe1d4d3308 (patch) | |
tree | db58100ed696c992addee1a9113b5415f55615ad /include/openvic-dataloader/v2script/Parser.hpp | |
parent | e941573f47fb867ff75c8a2cf78302b754ffbeee (diff) |
Rework Grammar and Parser
Properly construct headless binary with basic validation and print functionality
Add Error and Warning structs to Parser
Add FileNode pointer getter to Parser
Change all `char8_t*` and `const char8_t` to `const char*` in Parser
Add Parser move operators and Parser deconstructor
Add BufferHandler PIMPL object to Parser
Add UTF-8 file Warning
Add proper Grammar value retrieval
Simplify AST node resolution for Grammar
Add AbstractSyntaxTree for v2script data parser:
Has compile-time embedded type information accessible at compile-time and runtime
Optionally compiled AST print functionality
Add detail/TypeName.hpp
Add detail/SelfType.hpp
Add detail/DetectUtf8.hpp
Add detail/Errors.hpp
Add detail/Warnings.hpp
Add `OPENVIC_DATALOADER_PRINT_NODES` for headless construction
Fix wrong environment reference for headless construction in SConstruct
Diffstat (limited to 'include/openvic-dataloader/v2script/Parser.hpp')
-rw-r--r-- | include/openvic-dataloader/v2script/Parser.hpp | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/include/openvic-dataloader/v2script/Parser.hpp b/include/openvic-dataloader/v2script/Parser.hpp index 53aab90..dbbec73 100644 --- a/include/openvic-dataloader/v2script/Parser.hpp +++ b/include/openvic-dataloader/v2script/Parser.hpp @@ -1,27 +1,79 @@ #pragma once #include <cstddef> -#include <cstdio> +#include <functional> +#include <memory> +#include <optional> #include <ostream> +#include <string> +#include <vector> + +#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp> namespace ovdl::v2script { + + using FileNode = ast::FileNode; + class Parser { public: - static Parser from_buffer(char8_t* data, std::size_t size); - static Parser from_buffer(char8_t* start, char8_t* end); - static Parser from_file(const char8_t* path); + struct Error { + const enum class Type : unsigned char { + Recoverable, + Fatal + } type; + const std::string message; + const int error_value; + }; + + struct Warning { + const std::string message; + const int warning_value; + }; + + 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_file(const char* path); + + Parser& load_from_buffer(const char* data, std::size_t size); + Parser& load_from_buffer(const char* start, const char* end); + Parser& load_from_file(const char* path); + void set_error_log_to_null(); void set_error_log_to_stderr(); - void set_error_log_path(const char8_t* path); - void set_error_log_to(std::basic_ostream<char8_t> stream); - void set_error_log_to(std::FILE* file); + void set_error_log_to_stdout(); + void set_error_log_to(std::basic_ostream<char>& stream); - bool parse(); + bool simple_parse(); - bool has_error(); - bool has_warning(); + bool has_error() const; + bool has_fatal_error() const; + bool has_warning() const; + + const std::vector<Error>& get_errors() const; + const std::vector<Warning>& get_warnings() const; + + const FileNode* get_file_node() const; + + Parser(Parser&&); + Parser& operator=(Parser&&); + + ~Parser(); private: - Parser(); + std::vector<Error> _errors; + std::vector<Warning> _warnings; + + class BufferHandler; + friend class BufferHandler; + std::unique_ptr<BufferHandler> _buffer_handler; + std::unique_ptr<FileNode> _file_node; + std::reference_wrapper<std::ostream> _error_stream; + const char* _file_path; + bool _has_fatal_error = false; + + template<typename... Args> + inline void _run_load_func(std::optional<Error> (BufferHandler::*func)(Args...), Args... args); }; }
\ No newline at end of file |