From 18fc05d3d4269c47530358eeed2e0decff4ca006 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Fri, 7 Mar 2025 14:44:04 -0700 Subject: [PATCH] working on debuging chemical language string --- CMakeLists.txt | 4 ++-- include/arc/std/hashtable.h | 3 +-- src/std/chemical.c | 45 +++++++++++++++++++++---------------- tests/std/chemical.c | 5 +++++ 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e67ae7..db60061 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,8 +128,8 @@ if(ARCHEUS_TESTS) add_executable(tests tests/test.c - #tests/std/chemical.c - tests/std/hashtable.c + tests/std/chemical.c + #tests/std/hashtable.c #tests/std/lexer.c #tests/std/parser.c #tests/std/parser/csv.c diff --git a/include/arc/std/hashtable.h b/include/arc/std/hashtable.h index f68bfd8..16b3648 100644 --- a/include/arc/std/hashtable.h +++ b/include/arc/std/hashtable.h @@ -53,12 +53,11 @@ typedef struct ARC_Hashtable ARC_Hashtable; * @brief cteates ARC_Hashtable type * * @note if the default hashing function is used (CRC32), then the key value needs to be a string or end in '\0' - * @note an error will be thrown if the key is NULL * * @param[out] hashtable ARC_Hashtable to initialize * @param[in] hashFn a callback for a hashing function to be used, if set to NULL, CRC32 will be used * @param[in] compareFn a callback for checking keys, if set to NULL, addresses will be compared - * @param[in] destroyKeyValueFn a callback to free the key and value + * @param[in] destroyKeyValueFn a callback to free the key and value, if set to NULL, it will not free anything */ void ARC_Hashtable_Create(ARC_Hashtable **hashtable, ARC_Hashtable_HashFn *hashFn, ARC_Hashtable_KeyCompareFn *keyCompareFn, ARC_Hashtable_DestroyKeyValueFn *destroyKeyValueFn); diff --git a/src/std/chemical.c b/src/std/chemical.c index a610c7d..4e8a801 100644 --- a/src/std/chemical.c +++ b/src/std/chemical.c @@ -318,6 +318,7 @@ uint32_t ARC_Chemical_GetStringIdFn(ARC_String *string){ } void ARC_ChemicalData_CreateFn(void **data, ARC_ParserTagToken *parsedData, void *userData){ + printf("HERE??\n"); *data = NULL; if(parsedData == NULL || userData == NULL){ //TODO: error here? @@ -363,30 +364,30 @@ void ARC_Chemical_Create(ARC_Chemical **chemical){ /* ~ define the language as a string ~ */ char *languageCString = - " -> | | LAMBDA\n" + " -> | | LAMBDA\n" - " -> NEWLINE | \n" - " -> EQUAL SEMICOLON \n" - " -> SPACE | TAB | LAMBDA\n" + " -> EQUAL SEMICOLON \n" + " -> SPACE | TAB | LAMBDA\n" - " -> \n" - " -> \n" - " -> | | | \n" - " -> OPEN_CURLY_BRACE CLOSE_CURLY_BRACE\n" - " -> COMMA | \n" + " -> \n" + " -> \n" + " -> | \n" + //" -> | | | \n" + //" -> OPEN_CURLY_BRACE CLOSE_CURLY_BRACE\n" + //" -> COMMA | \n" - " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE \n" - " -> | LAMBDA\n" - " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n" + " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE \n" + " -> | LAMBDA\n" + " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n" - " -> QUOTE QUOTE\n" - " -> | | LAMBDA\n" - " -> TAB | SPACE | BANG | HASH | DOLLAR | PERCENT | AMPERSAND | SINGLE_QUOTE | OPEN_PAREN | CLOSE_PAREN | ASTERISK | PLUS | COMMA | MINUS | PERIOD | SLASH | NUMBER | COLON | SEMICOLON | LESS_THAN | GREATER_THAN | EQUAL | QUESTION_MARK | AT | ALPHA_UPPER_CHAR | OPEN_BRACKET | CLOSE_BRACKET | CARET | UNDERSCORE | GRAVE | ALPHA_LOWER_CHAR | OPEN_CURLY_BRACE | VERTICAL_LINE | CLOSE_CURLY_BRACE | TILDE\n" - " -> BACKSLASH BACKSLASH | BACKSLASH QUOTE | BACKSLASH ALPHA_UPPER_CHAR | BACKSLASH ALPHA_LOWER_CHAR\n" + //" -> QUOTE QUOTE\n" + //" -> | | LAMBDA\n" + //" -> TAB | SPACE | BANG | HASH | DOLLAR | PERCENT | AMPERSAND | SINGLE_QUOTE | OPEN_PAREN | CLOSE_PAREN | ASTERISK | PLUS | COMMA | MINUS | PERIOD | SLASH | NUMBER | COLON | SEMICOLON | LESS_THAN | GREATER_THAN | EQUAL | QUESTION_MARK | AT | ALPHA_UPPER_CHAR | OPEN_BRACKET | CLOSE_BRACKET | CARET | UNDERSCORE | GRAVE | ALPHA_LOWER_CHAR | OPEN_CURLY_BRACE | VERTICAL_LINE | CLOSE_CURLY_BRACE | TILDE\n" + //" -> BACKSLASH BACKSLASH | BACKSLASH QUOTE | BACKSLASH ALPHA_UPPER_CHAR | BACKSLASH ALPHA_LOWER_CHAR\n" - " -> NUMBER | NUMBER\n" + " -> NUMBER | NUMBER\n" - " -> SPACE | TAB | SPACE | TAB\n"; + " -> SPACE | TAB | NEWLINE | LAMBDA\n"; /* ~ define the language as a string ~ */ ARC_String *languageString; @@ -411,8 +412,14 @@ void ARC_Chemical_Create(ARC_Chemical **chemical){ //add the default/empty group into the groups ARC_Hashtable_DestroyKeyValueFn groupDataDestroyKeyValueFn = ARC_Chemical_GroupDataHashtableDestroyKeyValueFn; + + //copy empty group cstring (to be freed by hashtable on cleanup, passing directly would cause a segfault) + char *emptyCStr = (char *)malloc(sizeof(char) * (strlen(ARC_CHEMICAL_DEFAULT_GROUP) + 1)); + strcpy(emptyCStr, ARC_CHEMICAL_DEFAULT_GROUP); + + //set the current group as empty, then add that into the groups hashtable ARC_Hashtable_Create(&((*chemical)->currentGroup), NULL, &keyCompareFn, &groupDataDestroyKeyValueFn); - ARC_Hashtable_Add((*chemical)->groups, (void *)ARC_CHEMICAL_DEFAULT_GROUP, (*chemical)->currentGroup); + ARC_Hashtable_Add((*chemical)->groups, (void *)emptyCStr, (*chemical)->currentGroup); //cleanup ARC_String_Destroy(languageString); diff --git a/tests/std/chemical.c b/tests/std/chemical.c index ee82415..edbdf56 100644 --- a/tests/std/chemical.c +++ b/tests/std/chemical.c @@ -10,6 +10,11 @@ ARC_TEST(Chemical_BasicTest){ ARC_CHECK(arc_errno == 0); + char *tempCString = "int32 test = 5; "; + ARC_String *tempString; + ARC_String_CreateWithStrlen(&tempString, tempCString); + ARC_Chemical_LoadFromString(chemical, &tempString); + //cleanup ARC_Chemical_Destroy(chemical); }