aboutsummaryrefslogtreecommitdiff
path: root/include/openvic-dataloader
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2024-07-21 03:02:30 +0200
committer Spartan322 <Megacake1234@gmail.com>2024-07-22 02:49:25 +0200
commita07c64148eb60b886f92caa46a9c687240ec420c (patch)
treee43aae271fe5aa75f1b0c918c1428e7f766a14f8 /include/openvic-dataloader
parentba8addc72595607206da654bc79c994121b7a3ae (diff)
Add backslash identifier support to v2scriptadd/backslash-identifier
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
Diffstat (limited to 'include/openvic-dataloader')
-rw-r--r--include/openvic-dataloader/Error.hpp32
-rw-r--r--include/openvic-dataloader/csv/Parser.hpp2
-rw-r--r--include/openvic-dataloader/v2script/Parser.hpp2
3 files changed, 24 insertions, 12 deletions
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 <dryad/abstract_node.hpp>
#include <dryad/node.hpp>
+#include <dryad/symbol.hpp>
namespace ovdl {
template<typename>
@@ -50,6 +51,13 @@ namespace ovdl::error {
LastAnnotation = SecondaryAnnotation,
};
+ struct ErrorSymbolInterner {
+ struct SymbolId;
+ using index_type = std::uint32_t;
+ using symbol_type = dryad::symbol<SymbolId, index_type>;
+ using symbol_interner_type = dryad::symbol_interner<SymbolId, char, index_type>;
+ };
+
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<ErrorKind> {
- 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<typename>
friend struct ovdl::BasicDiagnosticLogger;
@@ -94,7 +102,7 @@ namespace ovdl::error {
};
struct BufferError : dryad::basic_node<ErrorKind::BufferError, Error> {
- 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<Error, ErrorKind::FirstAnnotation, ErrorKind::LastAnnotation> {
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<NodeKind, ParseError> {
using base_node = dryad::basic_node<NodeKind, ParseError>;
- 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<ErrorKind NodeKind>
struct _Annotation_t : dryad::basic_node<NodeKind, Annotation> {
- explicit _Annotation_t(dryad::node_ctor ctor, const char* message)
+ explicit _Annotation_t(dryad::node_ctor ctor, ErrorSymbolInterner::symbol_type message)
: dryad::basic_node<NodeKind, Annotation>(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<error::Root>;
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<char>& 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<error::Root>;
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<char>& stream) const;