RESULT_ERROR_FMT -> RESULT_ERROR_HEAP
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
CBUILD_VERSION=2.3.2
|
||||
CBUILD_VERSION=2.3.5
|
||||
|
||||
PROJECT="tlibtoml"
|
||||
CMP_C="gcc"
|
||||
CMP_CPP="g++"
|
||||
STD_C="c99"
|
||||
STD_CPP="c++11"
|
||||
WARN_C="-Wall -Wextra
|
||||
WARN_COMMON="-Wall -Wextra
|
||||
-Wduplicated-branches
|
||||
-Wduplicated-cond
|
||||
-Wformat=2
|
||||
@@ -15,8 +15,10 @@ WARN_C="-Wall -Wextra
|
||||
-Werror=return-type
|
||||
-Werror=pointer-arith
|
||||
-Werror=init-self
|
||||
-Wno-maybe-uninitialized"
|
||||
WARN_C="$WARN_COMMON
|
||||
-Werror=incompatible-pointer-types"
|
||||
WARN_CPP="$WARN_C"
|
||||
WARN_CPP="$WARN_COMMON"
|
||||
SRC_C="$(find src -name '*.c')"
|
||||
SRC_CPP="$(find src -name '*.cpp')"
|
||||
TESTS_C="$(find tests -name '*.c')"
|
||||
@@ -38,20 +40,23 @@ OUTDIR="bin"
|
||||
STATIC_LIB_FILE="$PROJECT.a"
|
||||
|
||||
INCLUDE="-Isrc -Iinclude -I../tlibc/include"
|
||||
DEFINES=""
|
||||
|
||||
# OS-specific options
|
||||
case "$OS" in
|
||||
WINDOWS)
|
||||
EXEC_FILE="test.exe"
|
||||
SHARED_LIB_FILE="$PROJECT.dll"
|
||||
INCLUDE="$INCLUDE "
|
||||
LINKER_LIBS="-luuid"
|
||||
INCLUDE="$INCLUDE "
|
||||
DEFINES="$DEFINES "
|
||||
;;
|
||||
LINUX)
|
||||
EXEC_FILE="test"
|
||||
SHARED_LIB_FILE="$PROJECT.so"
|
||||
INCLUDE="$INCLUDE "
|
||||
LINKER_LIBS=""
|
||||
INCLUDE="$INCLUDE "
|
||||
DEFINES="$DEFINES "
|
||||
;;
|
||||
*)
|
||||
error "operating system $OS has no configuration variants"
|
||||
@@ -70,7 +75,9 @@ case "$TASK" in
|
||||
# -fprofile-use enables compiler to use profiling info files to optimize executable
|
||||
# -fprofile-prefix-path sets path where profiling info about objects are be saved
|
||||
# -fdata-sections -ffunction-sections -Wl,--gc-sections removes unused code
|
||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects -fdata-sections -ffunction-sections -Wl,--gc-sections"
|
||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use
|
||||
-fprofile-prefix-path=$(realpath $OBJDIR)/objects
|
||||
-fdata-sections -ffunction-sections -Wl,--gc-sections $DEFINES"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||
PRE_TASK_SCRIPT=""
|
||||
@@ -81,7 +88,7 @@ case "$TASK" in
|
||||
build_exec_dbg)
|
||||
SRC_C="$SRC_C $TESTS_C"
|
||||
SRC_CPP="$SRC_CPP $TESTS_CPP"
|
||||
C_ARGS="-O0 -g3"
|
||||
C_ARGS="-O0 -g3 $DEFINES"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||
PRE_TASK_SCRIPT=""
|
||||
@@ -90,7 +97,7 @@ case "$TASK" in
|
||||
;;
|
||||
# creates shared library
|
||||
build_shared_lib)
|
||||
C_ARGS="-O2 -fpic -flto -shared"
|
||||
C_ARGS="-O2 -fpic -flto -shared $DEFINES"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -Wl,-soname,$SHARED_LIB_FILE"
|
||||
PRE_TASK_SCRIPT=""
|
||||
@@ -99,7 +106,7 @@ case "$TASK" in
|
||||
;;
|
||||
# creates shared library with debug symbols and no optimizations
|
||||
build_shared_lib_dbg)
|
||||
C_ARGS="-O0 -g3 -fpic -shared"
|
||||
C_ARGS="-O0 -g3 -fpic -shared $DEFINES"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS -Wl,-soname,$SHARED_LIB_FILE"
|
||||
PRE_TASK_SCRIPT=""
|
||||
@@ -108,7 +115,7 @@ case "$TASK" in
|
||||
;;
|
||||
# creates static library
|
||||
build_static_lib)
|
||||
C_ARGS="-O2 -fpic -fdata-sections -ffunction-sections"
|
||||
C_ARGS="-O2 -fpic -fdata-sections -ffunction-sections $DEFINES"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
PRE_TASK_SCRIPT=""
|
||||
TASK_SCRIPT="@cbuild/default_tasks/build_static_lib.sh"
|
||||
@@ -116,7 +123,7 @@ case "$TASK" in
|
||||
;;
|
||||
# creates static library with debug symbols and no optimizations
|
||||
build_static_lib_dbg)
|
||||
C_ARGS="-O0 -g3"
|
||||
C_ARGS="-O0 -g3 $DEFINES"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
PRE_TASK_SCRIPT=""
|
||||
TASK_SCRIPT="@cbuild/default_tasks/build_static_lib.sh"
|
||||
@@ -140,7 +147,8 @@ case "$TASK" in
|
||||
# -pg adds code to executable, that generates file containing function call info (gmon.out)
|
||||
# -fprofile-generate generates executable with profiling code
|
||||
# -fprofile-prefix-path sets path where profiling info about objects will be saved
|
||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-generate -fprofile-prefix-path=$(realpath $OBJDIR)/objects"
|
||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-generate
|
||||
-fprofile-prefix-path=$(realpath $OBJDIR)/objects $DEFINES"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
||||
@@ -156,7 +164,7 @@ case "$TASK" in
|
||||
# https://github.com/msys2/MINGW-packages/issues/8503#issuecomment-1365475205
|
||||
C_ARGS="-O0 -g -pg -no-pie -fno-omit-frame-pointer
|
||||
-fno-inline-functions -fno-inline-functions-called-once
|
||||
-fno-optimize-sibling-calls -fopenmp"
|
||||
-fno-optimize-sibling-calls -fopenmp $DEFINES"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
||||
@@ -170,7 +178,7 @@ case "$TASK" in
|
||||
callgrind)
|
||||
OUTDIR="$OUTDIR/callgrind"
|
||||
# -pg adds code to executable, that generates file containing function call info (gmon.out)
|
||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin"
|
||||
C_ARGS="-O2 -flto=auto -fuse-linker-plugin $DEFINES"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
||||
@@ -180,7 +188,7 @@ case "$TASK" in
|
||||
# compiles executable with sanitizers and executes it to find errors and warnings
|
||||
sanitize)
|
||||
OUTDIR="$OUTDIR/sanitize"
|
||||
C_ARGS="-O0 -g3 -fsanitize=undefined,address"
|
||||
C_ARGS="-O0 -g3 -fsanitize=undefined,address $DEFINES"
|
||||
CPP_ARGS="$C_ARGS"
|
||||
LINKER_ARGS="$CPP_ARGS $LINKER_LIBS"
|
||||
PRE_TASK_SCRIPT="@cbuild/default_tasks/build_exec.sh"
|
||||
|
||||
@@ -22,20 +22,20 @@ void TomlTable_free(TomlTable* self)
|
||||
|
||||
#define try_assert_value_found(VAL, KEY) \
|
||||
if(VAL == NULL){ \
|
||||
Return RESULT_ERROR_CODE_FMT( \
|
||||
TLIBTOML, TLIBTOML_ERR_NOT_FOUND, \
|
||||
char* __err425 = sprintf_malloc(\
|
||||
"can't find '"FMT_str"'", \
|
||||
str_unwrap(KEY)); \
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_NOT_FOUND, __err425);\
|
||||
} \
|
||||
|
||||
#define try_assert_value_type(VAL, KEY, TYPE) \
|
||||
if((VAL)->type != TYPE){ \
|
||||
str t_expected_s = TomlType_toStr(TYPE); \
|
||||
str t_got_s = TomlType_toStr((VAL)->type); \
|
||||
Return RESULT_ERROR_CODE_FMT( \
|
||||
TLIBTOML, TLIBTOML_ERR_UNEXPECTED_TYPE, \
|
||||
char* __err985 = sprintf_malloc(\
|
||||
"expected '"FMT_str"' of type '"FMT_str"', but got '"FMT_str"'", \
|
||||
str_unwrap(KEY), str_unwrap(t_expected_s), str_unwrap(t_got_s)); \
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_UNEXPECTED_TYPE, __err985);\
|
||||
} \
|
||||
|
||||
Result(TomlTable*) TomlTable_get_table(const TomlTable* self, str key)
|
||||
|
||||
@@ -47,9 +47,10 @@ Result(void) toml_parse_basic_string(TomlParser* self, str* out_str)
|
||||
toml_move_next(self);
|
||||
try_void(toml_encode_unicode_scalar(&sb, self, 8));
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: invalid escape character",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
} else {
|
||||
StringBuilder_append_char(&sb, ch1);
|
||||
@@ -58,9 +59,10 @@ Result(void) toml_parse_basic_string(TomlParser* self, str* out_str)
|
||||
}
|
||||
|
||||
if (self->ptr >= self->end ||* self->ptr != '\"' ||* self->ptr == '\n') {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unterminated basic string",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
toml_move_next(self);
|
||||
|
||||
@@ -38,7 +38,8 @@ Result(void) toml_parse_bool(TomlParser* self, TomlValue* out_value)
|
||||
}
|
||||
}
|
||||
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err77 = sprintf_malloc(
|
||||
"%s:%d:%d: value of unknown type",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err77);
|
||||
}
|
||||
|
||||
@@ -31,9 +31,10 @@ Result(void) toml_parse_inline_table(TomlParser* self, TomlValue* out_value)
|
||||
} else if (ch == '}') {
|
||||
break;
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unexpected token",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
ch = *self->ptr;
|
||||
@@ -43,15 +44,17 @@ Result(void) toml_parse_inline_table(TomlParser* self, TomlValue* out_value)
|
||||
}
|
||||
|
||||
if (self->ptr == self->end) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unterminated key value pair",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
if (ch != '=') {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unexpected token",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
toml_move_next(self);
|
||||
@@ -63,9 +66,10 @@ Result(void) toml_parse_inline_table(TomlParser* self, TomlValue* out_value)
|
||||
}
|
||||
|
||||
if (self->ptr == self->end) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unterminated key value pair",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
TomlValue value;
|
||||
|
||||
@@ -70,21 +70,24 @@ Result(void) toml_parse_int_or_float_or_time(TomlParser* self, TomlValue* out_va
|
||||
type = 'f';
|
||||
StringBuilder_append_char(&sb,* self->ptr);
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err10 = sprintf_malloc(
|
||||
"%s:%d:%d: invalid float",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err10);
|
||||
}
|
||||
} else if (*self->ptr == '_') {
|
||||
if (type == 't') {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err20 = sprintf_malloc(
|
||||
"%s:%d:%d: invalid datetime",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err20);
|
||||
}
|
||||
|
||||
if (!isalnum(last_char)) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err30 = sprintf_malloc(
|
||||
"%s:%d:%d: invalid integer or float",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err30);
|
||||
}
|
||||
} else if (*self->ptr == '-') {
|
||||
type = 't';
|
||||
@@ -98,9 +101,10 @@ Result(void) toml_parse_int_or_float_or_time(TomlParser* self, TomlValue* out_va
|
||||
}
|
||||
|
||||
if (last_char == '_') {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err40 = sprintf_malloc(
|
||||
"%s:%d:%d: invalid integer or float or datetime",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err40);
|
||||
}
|
||||
|
||||
if (type == 'i') {
|
||||
@@ -108,9 +112,10 @@ Result(void) toml_parse_int_or_float_or_time(TomlParser* self, TomlValue* out_va
|
||||
char* start = StringBuilder_getStr(&sb).data;
|
||||
i64 n = strtoll(start, &end, base);
|
||||
if (end < start + sb.buffer.len) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err50 = sprintf_malloc(
|
||||
"%s:%d:%d: invalid integer",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err50);
|
||||
}
|
||||
value = TomlValue_new_integer(n);
|
||||
} else if (type == 'f') {
|
||||
@@ -118,9 +123,10 @@ Result(void) toml_parse_int_or_float_or_time(TomlParser* self, TomlValue* out_va
|
||||
char* start = StringBuilder_getStr(&sb).data;
|
||||
f64 n = strtod(start, &end);
|
||||
if (end < start + sb.buffer.len) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err60 = sprintf_malloc(
|
||||
"%s:%d:%d: invalid float",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err60);
|
||||
}
|
||||
value = TomlValue_new_float(n);
|
||||
} else if (type == 't') {
|
||||
|
||||
@@ -38,9 +38,10 @@ Result(void) toml_parse_key_value(TomlParser* self, TomlTable* target_table)
|
||||
toml_move_next(self);
|
||||
continue;
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unexpected token",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
ch = *self->ptr;
|
||||
@@ -50,15 +51,17 @@ Result(void) toml_parse_key_value(TomlParser* self, TomlTable* target_table)
|
||||
}
|
||||
|
||||
if (self->ptr == self->end) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unterminated key value pair",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
if (ch != '=') {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unexpected token",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
toml_move_next(self);
|
||||
@@ -70,9 +73,10 @@ Result(void) toml_parse_key_value(TomlParser* self, TomlTable* target_table)
|
||||
}
|
||||
|
||||
if (self->ptr == self->end) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unterminated key value pair",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
TomlValue value;
|
||||
@@ -101,9 +105,10 @@ Result(void) toml_parse_key_value(TomlParser* self, TomlTable* target_table)
|
||||
if (*self->ptr == '\n') {
|
||||
toml_move_next(self);
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: new line expected",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,10 @@ Result(void) toml_parse_literal_string(TomlParser* self, str* out_str)
|
||||
}
|
||||
|
||||
if (self->ptr >= self->end ||* self->ptr != '\'' ||* self->ptr == '\n') {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unterminated literal string",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
toml_move_next(self);
|
||||
|
||||
@@ -57,9 +57,10 @@ Result(void) toml_parse_multi_line_basic_string(TomlParser* self, TomlValue* out
|
||||
toml_move_next(self);
|
||||
} while (self->ptr + 3 <= self->end && isspace(*self->ptr));
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: invalid escape character",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
} else {
|
||||
StringBuilder_append_char(&sb, ch1);
|
||||
@@ -68,9 +69,10 @@ Result(void) toml_parse_multi_line_basic_string(TomlParser* self, TomlValue* out
|
||||
}
|
||||
|
||||
if (self->ptr + 3 > self->end || strncmp(self->ptr, "\"\"\"", 3) != 0) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unterminated multi-line basic string",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
toml_next_n(self, 3);
|
||||
|
||||
@@ -21,9 +21,10 @@ Result(void) toml_parse_multi_line_literal_string(TomlParser* self, TomlValue* o
|
||||
}
|
||||
|
||||
if (self->ptr + 3 > self->end || strncmp(self->ptr, "\'\'\'", 3) != 0) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unterminated multi-line literal string",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
toml_next_n(self, 3);
|
||||
|
||||
@@ -44,9 +44,10 @@ Result(void) toml_parse_table(TomlParser* self, TomlTable* target_table)
|
||||
toml_move_next(self);
|
||||
try_void(toml_parse_literal_string(self, &key_part));
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unexpected token",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
TomlValue key_part_value = TomlValue_move_str(key_part);
|
||||
@@ -64,9 +65,10 @@ Result(void) toml_parse_table(TomlParser* self, TomlTable* target_table)
|
||||
}
|
||||
|
||||
if (key_path->len == 0) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: empty table name",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
while (self->ptr < self->end &&
|
||||
@@ -75,9 +77,10 @@ Result(void) toml_parse_table(TomlParser* self, TomlTable* target_table)
|
||||
}
|
||||
|
||||
if (self->ptr < self->end &&* self->ptr != '\n') {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: new line expected",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
try(real_table, p, toml_walk_table_path(self, target_table, key_path, is_array, true));
|
||||
|
||||
@@ -34,9 +34,10 @@ Result(void) toml_parse_value(TomlParser* self, TomlValue* out_value)
|
||||
toml_move_next(self);
|
||||
try_void(toml_parse_inline_table(self, &value));
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: unexpected token",
|
||||
self->filename, self->lineno, self->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
*out_value = value;
|
||||
|
||||
@@ -22,9 +22,10 @@ Result(Table*) toml_walk_table_path(TomlParser* parser, TomlTable* table,
|
||||
TomlTable_set(real_table, part, new_table_value);
|
||||
real_table = new_table_value.table;
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: not found key '" FMT_str "'",
|
||||
parser->filename, parser->lineno, parser->colno, part.len, part.data);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
} else {
|
||||
real_table = t->table;
|
||||
@@ -41,15 +42,17 @@ Result(Table*) toml_walk_table_path(TomlParser* parser, TomlTable* table,
|
||||
TomlTable_set(real_table, part, array_value);
|
||||
real_table = new_table_value.table;
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: not found key '" FMT_str "'",
|
||||
parser->filename, parser->lineno, parser->colno, part.len, part.data);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
} else {
|
||||
if (t->type != TLIBTOML_ARRAY) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: this key was not an array",
|
||||
parser->filename, parser->lineno, parser->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
|
||||
TomlValue new_table_value = TomlValue_new_table();
|
||||
@@ -66,9 +69,10 @@ Result(Table*) toml_walk_table_path(TomlParser* parser, TomlTable* table,
|
||||
TomlTable_set(real_table, part, new_table_value);
|
||||
real_table = new_table_value.table;
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: not found key '" FMT_str "'",
|
||||
parser->filename, parser->lineno, parser->colno, part.len, part.data);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_SYNTAX, err);
|
||||
}
|
||||
} else {
|
||||
if (t->type == TLIBTOML_ARRAY) {
|
||||
|
||||
@@ -64,9 +64,10 @@ Result(void) toml_encode_unicode_scalar(StringBuilder* sb_ptr, TomlParser* parse
|
||||
u32 scalar = 0;
|
||||
|
||||
if (parser->ptr + n > parser->end) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_UNICODE,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: invalid unicode scalar",
|
||||
parser->filename, parser->lineno, parser->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_UNICODE, err);
|
||||
}
|
||||
|
||||
for (i32 i = 0; i < n; i++) {
|
||||
@@ -75,18 +76,20 @@ Result(void) toml_encode_unicode_scalar(StringBuilder* sb_ptr, TomlParser* parse
|
||||
scalar = scalar * 16 + toml_hex_char_to_int(ch);
|
||||
toml_move_next(parser);
|
||||
} else {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_UNICODE,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: invalid unicode scalar",
|
||||
parser->filename, parser->lineno, parser->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_UNICODE, err);
|
||||
}
|
||||
}
|
||||
|
||||
if ((scalar >= 0xd800 && scalar <= 0xdfff) ||
|
||||
(scalar >= 0xfffe && scalar <= 0xffff))
|
||||
{
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_UNICODE,
|
||||
char* err = sprintf_malloc(
|
||||
"%s:%d:%d: invalid unicode scalar",
|
||||
parser->filename, parser->lineno, parser->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_UNICODE, err);
|
||||
}
|
||||
|
||||
if (scalar <= 0x7f) {
|
||||
@@ -134,7 +137,8 @@ Result(void) toml_encode_unicode_scalar(StringBuilder* sb_ptr, TomlParser* parse
|
||||
Return RESULT_VOID;
|
||||
}
|
||||
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_UNICODE,
|
||||
char* __err222 = sprintf_malloc(
|
||||
"%s:%d:%d: invalid unicode scalar",
|
||||
parser->filename, parser->lineno, parser->colno);
|
||||
Return RESULT_ERROR_CODE_HEAP(TLIBTOML, TLIBTOML_ERR_UNICODE, __err222);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user