diff options
author | Spartan322 <Megacake1234@gmail.com> | 2023-11-28 11:09:26 +0100 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2024-05-09 22:11:26 +0200 |
commit | 757114a3c5b748567b42f273c7b78ca039ae983c (patch) | |
tree | e07390b682052129c91f4b157068bcdd84ceecb4 /include/openvic-dataloader/csv | |
parent | 7211a228e68c8a6b1ad1c1c5ec68c8d720b6d2ba (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/csv')
-rw-r--r-- | include/openvic-dataloader/csv/LineObject.hpp | 2 | ||||
-rw-r--r-- | include/openvic-dataloader/csv/Parser.hpp | 25 |
2 files changed, 21 insertions, 6 deletions
diff --git a/include/openvic-dataloader/csv/LineObject.hpp b/include/openvic-dataloader/csv/LineObject.hpp index 87b4d31..ca632cd 100644 --- a/include/openvic-dataloader/csv/LineObject.hpp +++ b/include/openvic-dataloader/csv/LineObject.hpp @@ -13,7 +13,7 @@ #include <utility> #include <vector> -#include <openvic-dataloader/detail/VectorConstexpr.hpp> +#include <openvic-dataloader/detail/utility/Constexpr.hpp> namespace ovdl::csv { /// LineObject should be able to recognize the differences between: diff --git a/include/openvic-dataloader/csv/Parser.hpp b/include/openvic-dataloader/csv/Parser.hpp index aa2a0fe..ccf732a 100644 --- a/include/openvic-dataloader/csv/Parser.hpp +++ b/include/openvic-dataloader/csv/Parser.hpp @@ -2,8 +2,13 @@ #include <filesystem> +#include <openvic-dataloader/Error.hpp> +#include <openvic-dataloader/Parser.hpp> #include <openvic-dataloader/csv/LineObject.hpp> -#include <openvic-dataloader/detail/BasicParser.hpp> +#include <openvic-dataloader/detail/utility/Concepts.hpp> +#include <openvic-dataloader/detail/utility/ErrorRange.hpp> + +#include <dryad/node.hpp> namespace ovdl::csv { enum class EncodingType { @@ -15,6 +20,7 @@ namespace ovdl::csv { 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); @@ -28,24 +34,33 @@ namespace ovdl::csv { 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 parse_csv(bool handle_strings = false); const std::vector<csv::LineObject>& get_lines() const; + using error_range = ovdl::detail::error_range; + Parser::error_range get_errors() const; + + const FilePosition get_error_position(const error::Error* error) const; + + void print_errors_to(std::basic_ostream<char>& stream) const; + Parser(Parser&&); Parser& operator=(Parser&&); ~Parser(); private: - class BufferHandler; - std::unique_ptr<BufferHandler> _buffer_handler; + class ParseHandler; + std::unique_ptr<ParseHandler> _parse_handler; std::vector<csv::LineObject> _lines; template<typename... Args> - constexpr void _run_load_func(detail::LoadCallback<BufferHandler, Args...> auto func, Args... args); + constexpr void _run_load_func(detail::LoadCallback<ParseHandler, Args...> auto func, Args... args); }; using Windows1252Parser = Parser<EncodingType::Windows1252>; |