From a07c64148eb60b886f92caa46a9c687240ec420c Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sat, 20 Jul 2024 21:02:30 -0400 Subject: Add backslash identifier support to v2script Add buffer::char_type size multiplier to max file size of string intern buffer Fix list grammar segfaults Fix diagnostic logger intern segfaults from buffer reallocation Fix non-string-supported CSV parser not supporting Victoria 2 CSV escaping behavior --- include/openvic-dataloader/Error.hpp | 32 ++++++++++++++++---------- include/openvic-dataloader/csv/Parser.hpp | 2 ++ include/openvic-dataloader/v2script/Parser.hpp | 2 ++ 3 files changed, 24 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/openvic-dataloader/Error.hpp b/include/openvic-dataloader/Error.hpp index 343abd9..8e182b6 100644 --- a/include/openvic-dataloader/Error.hpp +++ b/include/openvic-dataloader/Error.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace ovdl { template @@ -50,6 +51,13 @@ namespace ovdl::error { LastAnnotation = SecondaryAnnotation, }; + struct ErrorSymbolInterner { + struct SymbolId; + using index_type = std::uint32_t; + using symbol_type = dryad::symbol; + using symbol_interner_type = dryad::symbol_interner; + }; + static constexpr std::string_view get_kind_name(ErrorKind kind) { switch (kind) { using enum ErrorKind; @@ -62,13 +70,13 @@ namespace ovdl::error { } struct Error : dryad::abstract_node_all { - const char* message() const { return _message; } + const char* message(const ErrorSymbolInterner::symbol_interner_type& symbols) const { return _message.c_str(symbols); } protected: DRYAD_ABSTRACT_NODE_CTOR(Error); - void _set_message(const char* message) { _message = message; } - const char* _message = ""; + void _set_message(ErrorSymbolInterner::symbol_type message) { _message = message; } + ErrorSymbolInterner::symbol_type _message; template friend struct ovdl::BasicDiagnosticLogger; @@ -94,7 +102,7 @@ namespace ovdl::error { }; struct BufferError : dryad::basic_node { - explicit BufferError(dryad::node_ctor ctor, const char* message) : node_base(ctor) { + explicit BufferError(dryad::node_ctor ctor, ErrorSymbolInterner::symbol_type message) : node_base(ctor) { _set_message(message); } @@ -103,7 +111,7 @@ namespace ovdl::error { struct Annotation : dryad::abstract_node_range { protected: - explicit Annotation(dryad::node_ctor ctor, ErrorKind kind, const char* message) : node_base(ctor, kind) { + explicit Annotation(dryad::node_ctor ctor, ErrorKind kind, ErrorSymbolInterner::symbol_type message) : node_base(ctor, kind) { _set_message(message); } }; @@ -129,7 +137,7 @@ namespace ovdl::error { protected: explicit ParseError(dryad::node_ctor ctor, ErrorKind kind, - const char* message, + ErrorSymbolInterner::symbol_type message, const char* production_name) : node_base(ctor, kind), _production_name(production_name) { @@ -143,7 +151,7 @@ namespace ovdl::error { struct _ParseError_t : dryad::basic_node { using base_node = dryad::basic_node; - explicit _ParseError_t(dryad::node_ctor ctor, const char* message, const char* production_name) + explicit _ParseError_t(dryad::node_ctor ctor, ErrorSymbolInterner::symbol_type message, const char* production_name) : base_node(ctor, message, production_name) {} }; @@ -157,12 +165,12 @@ namespace ovdl::error { explicit Semantic(dryad::node_ctor ctor, ErrorKind kind) : node_base(ctor, kind) {}; - explicit Semantic(dryad::node_ctor ctor, ErrorKind kind, const char* message) + explicit Semantic(dryad::node_ctor ctor, ErrorKind kind, ErrorSymbolInterner::symbol_type message) : node_base(ctor, kind) { _set_message(message); }; - explicit Semantic(dryad::node_ctor ctor, ErrorKind kind, const char* message, AnnotationList annotations) + explicit Semantic(dryad::node_ctor ctor, ErrorKind kind, ErrorSymbolInterner::symbol_type message, AnnotationList annotations) : node_base(ctor, kind) { push_back(annotations); _set_message(message); @@ -176,10 +184,10 @@ namespace ovdl::error { explicit _SemanticError_t(dryad::node_ctor ctor) : base_node(ctor) {} - explicit _SemanticError_t(dryad::node_ctor ctor, const char* message) + explicit _SemanticError_t(dryad::node_ctor ctor, ErrorSymbolInterner::symbol_type message) : base_node(ctor, message) {} - explicit _SemanticError_t(dryad::node_ctor ctor, const char* message, AnnotationList annotations) + explicit _SemanticError_t(dryad::node_ctor ctor, ErrorSymbolInterner::symbol_type message, AnnotationList annotations) : base_node(ctor, message, annotations) {} }; @@ -192,7 +200,7 @@ namespace ovdl::error { template struct _Annotation_t : dryad::basic_node { - explicit _Annotation_t(dryad::node_ctor ctor, const char* message) + explicit _Annotation_t(dryad::node_ctor ctor, ErrorSymbolInterner::symbol_type message) : dryad::basic_node(ctor, message) {} }; diff --git a/include/openvic-dataloader/csv/Parser.hpp b/include/openvic-dataloader/csv/Parser.hpp index 1c363c8..e3ae84d 100644 --- a/include/openvic-dataloader/csv/Parser.hpp +++ b/include/openvic-dataloader/csv/Parser.hpp @@ -42,6 +42,8 @@ namespace ovdl::csv { using error_range = ovdl::detail::error_range; Parser::error_range get_errors() const; + std::string_view error(const ovdl::error::Error* error) const; + const FilePosition get_error_position(const error::Error* error) const; void print_errors_to(std::basic_ostream& stream) const; diff --git a/include/openvic-dataloader/v2script/Parser.hpp b/include/openvic-dataloader/v2script/Parser.hpp index c5f37be..e575dfc 100644 --- a/include/openvic-dataloader/v2script/Parser.hpp +++ b/include/openvic-dataloader/v2script/Parser.hpp @@ -61,6 +61,8 @@ namespace ovdl::v2script { using error_range = ovdl::detail::error_range; Parser::error_range get_errors() const; + std::string_view error(const ovdl::error::Error* error) const; + const FilePosition get_error_position(const error::Error* error) const; void print_errors_to(std::basic_ostream& stream) const; -- cgit v1.2.3-56-ga3b1