From 24fd8d6b25604450b7a93c35e6b87d54a1f864cb Mon Sep 17 00:00:00 2001 From: herbglitch Date: Wed, 16 Oct 2024 23:46:16 -0600 Subject: [PATCH] working on parsing recursively --- include/arc/std/parser.h | 2 +- src/std/parser.c | 29 +++++++++++++++++++++++++++-- tests/std/parser.c | 6 +++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/include/arc/std/parser.h b/include/arc/std/parser.h index 8a4dd8f..0768d54 100644 --- a/include/arc/std/parser.h +++ b/include/arc/std/parser.h @@ -7,7 +7,7 @@ extern "C" { #include "arc/std/array.h" //#include "arc/std/bool.h" -//#include "arc/std/lexer.h" +#include "arc/std/lexer.h" #include /** diff --git a/src/std/parser.c b/src/std/parser.c index 26054cb..d34583b 100644 --- a/src/std/parser.c +++ b/src/std/parser.c @@ -1,4 +1,5 @@ #include "arc/std/parser.h" +#include "arc/std/errno.h" #include "arc/std/lexer.h" #include #include @@ -43,6 +44,30 @@ void ARC_Parser_Destroy(ARC_Parser *parser){ free(parser); } -void ARC_Parser_Parse(ARC_Parser *parser, ARC_String *data); +//private recusive function to parse a tag +void ARC_Parser_ParseTag(ARC_Parser *parser, ARC_String *subdata, uint32_t tagId){ + //get the current tag + ARC_ParserLanguageTag *tag = NULL; + for(uint32_t index = 0; index < parser->language.size; index++){ + ARC_ParserLanguageTag *foundTag = ((ARC_ParserLanguageTag *)parser->language.data) + index; + if(foundTag->tagId == tagId){ + tag = foundTag; + break; + } + } -void ARC_Parser_ParseFile(ARC_Parser *parser, ARC_String *path); + //if the tag was not found can't do much, so throw an error + if(tag == NULL){ + arc_errno = ARC_ERRNO_NULL; + ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_Parser_ParseTag(parser, subdata, tagId), could not find tag with id: %u", tagId); + return; + } +} + +void ARC_Parser_Parse(ARC_Parser *parser, ARC_String *data){ + +} + +void ARC_Parser_ParseFile(ARC_Parser *parser, ARC_String *path){ + +} diff --git a/tests/std/parser.c b/tests/std/parser.c index 8a67599..cf1d773 100644 --- a/tests/std/parser.c +++ b/tests/std/parser.c @@ -8,6 +8,10 @@ #define VARIABLE_NAME 4 #define VARIABLE 5 +void TEST_Parser_InitLexerRulesFn(ARC_Lexer *lexer){ + ARC_Lexer_InitBasicTokenRules(lexer); +} + ARC_TEST(Lexer_Char_Match){ ARC_Parser *parser; @@ -37,7 +41,7 @@ ARC_TEST(Lexer_Char_Match){ testTags //data }; - ARC_Parser_Create(&parser, &languageArray); + ARC_Parser_Create(&parser, &languageArray, TEST_Parser_InitLexerRulesFn); ARC_Parser_Destroy(parser);