From 0ba59d376790da6947ab3f59e33287c5fcaaf6d4 Mon Sep 17 00:00:00 2001 From: PS Date: Sat, 10 Oct 2020 17:46:50 -0700 Subject: [PATCH] added error reporting to the parser --- src/app/engine/foldhaus_serializer.h | 60 ++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/app/engine/foldhaus_serializer.h b/src/app/engine/foldhaus_serializer.h index 3a1849e..a55ea2e 100644 --- a/src/app/engine/foldhaus_serializer.h +++ b/src/app/engine/foldhaus_serializer.h @@ -131,6 +131,12 @@ Serializer_WriteV3Value(serializer* Serializer, u32 IdentIndex, v3 Value) // Parsing +struct parser_error +{ + gs_string Message; + parser_error* Next; +}; + struct parser { gs_string String; @@ -144,8 +150,26 @@ struct parser char* At; gs_memory_arena* Arena; + gs_memory_arena* Transient; + + parser_error* ErrorsRoot; + parser_error* ErrorsHead; }; +internal void +Parser_PushErrorF(parser* Parser, char* Format, ...) +{ + parser_error* Error = PushStruct(Parser->Transient, parser_error); + Error->Message = PushString(Parser->Transient, 1024); + + va_list Args; + va_start(Args, Format); + PrintFArgsList(&Error->Message, Format, Args); + va_end(Args); + + SLLPushOrInit(Parser->ErrorsRoot, Parser->ErrorsHead, Error); +} + internal gs_const_string Parser_GetIdent(parser Parser, u32 Index) { @@ -278,9 +302,13 @@ Parser_ReadStringValue(parser* P, gs_const_string Ident, bool ShouldNullTerminat } else { - // TODO(pjs): Error + Parser_PushErrorF(P, "String doesn't have a closing quote, or line doesn't end with a semicolon"); } } + else + { + Parser_PushErrorF(P, "String doesn't begin correctly"); + } return Result; } @@ -346,9 +374,13 @@ Parser_ReadU32Value(parser* P, gs_const_string Ident) } else { - // TODO(pjs): Error + Parser_PushErrorF(P, "U32 Value doesn't end with semicolon"); } } + else + { + Parser_PushErrorF(P, "U32 value doesn't begin properly"); + } return Result; } @@ -384,10 +416,14 @@ Parser_ReadR32Value(parser* P, gs_const_string Ident) } else { - // TODO(pjs): Error + Parser_PushErrorF(P, "R32 Value doesn't end with semicolon"); } - } + else + { + Parser_PushErrorF(P, "R32 value doesn't begin properly"); + } + return Result; } @@ -407,10 +443,16 @@ Parser_ReadV3Value(parser* P, gs_const_string Ident) Parser_AdvanceIfTokenEquals(P, ConstString("("))) { r32 X = Parser_ReadR32(P); - Parser_AdvanceIfTokenEquals(P, ConstString(",")); + if (!Parser_AdvanceIfTokenEquals(P, ConstString(","))) + { + Parser_PushErrorF(P, "V3 Value doesn't have comma separated values"); + } r32 Y = Parser_ReadR32(P); - Parser_AdvanceIfTokenEquals(P, ConstString(",")); + if (!Parser_AdvanceIfTokenEquals(P, ConstString(","))) + { + Parser_PushErrorF(P, "V3 Value doesn't have comma separated values"); + } r32 Z = Parser_ReadR32(P); if (Parser_AdvanceIfTokenEquals(P, ConstString(")")) && @@ -422,9 +464,13 @@ Parser_ReadV3Value(parser* P, gs_const_string Ident) } else { - // TODO(pjs): error + Parser_PushErrorF(P, "V3 Value doesn't end correctly"); } } + else + { + Parser_PushErrorF(P, "V3 Value doesn't begin correctly"); + } return Result; }