From b2aec6be00863da7e48ea8152e4226f4fcb323f3 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Sat, 8 Mar 2025 02:30:23 -0700 Subject: [PATCH] basic tests for chemical parsing, still need to write create and destroy functions for passed back data --- src/std/chemical.c | 88 +++++++++++++++++++++++++------------------- tests/std/chemical.c | 4 +- 2 files changed, 53 insertions(+), 39 deletions(-) diff --git a/src/std/chemical.c b/src/std/chemical.c index 4e8a801..5561c62 100644 --- a/src/std/chemical.c +++ b/src/std/chemical.c @@ -70,23 +70,25 @@ static const uint32_t ARC_CHEMICAL_CLOSE_CURLY_BRACE = 0x25; static const uint32_t ARC_CHEMICAL_TILDE = 0x26; static const uint32_t ARC_CHEMICAL_LANGUAGE = 0x27; -static const uint32_t ARC_CHEMICAL_VARIABLE_LINES = 0x28; -static const uint32_t ARC_CHEMICAL_VARIABLE_LINE = 0x29; -static const uint32_t ARC_CHEMICAL_ALLOW_SPACE = 0x2A; -static const uint32_t ARC_CHEMICAL_GROUP_NAME = 0x2B; -static const uint32_t ARC_CHEMICAL_TYPE = 0x2C; -static const uint32_t ARC_CHEMICAL_VALUE = 0x2D; -static const uint32_t ARC_CHEMICAL_NESTED_VALUE = 0x2E; -static const uint32_t ARC_CHEMICAL_VALUE_ARGS = 0x2F; -static const uint32_t ARC_CHEMICAL_VARIABLE = 0x30; -static const uint32_t ARC_CHEMICAL_VARIABLE_NAME = 0x31; -static const uint32_t ARC_CHEMICAL_VARIABLE_CHAR = 0x32; -static const uint32_t ARC_CHEMICAL_STRING = 0x33; -static const uint32_t ARC_CHEMICAL_STRING_CHARS = 0x34; -static const uint32_t ARC_CHEMICAL_STRING_CHAR = 0x35; -static const uint32_t ARC_CHEMICAL_ESCAPE_CHAR = 0x36; -static const uint32_t ARC_CHEMICAL_WHITESPACE = 0x37; -static const uint32_t ARC_CHEMICAL_NUMBER_TAG = 0x38; +static const uint32_t ARC_CHEMICAL_GROUP = 0x28; +static const uint32_t ARC_CHEMICAL_GROUP_NAME = 0x29; +static const uint32_t ARC_CHEMICAL_GROUP_ARGS = 0x2A; +static const uint32_t ARC_CHEMICAL_VARIABLE_LINES = 0x2B; +static const uint32_t ARC_CHEMICAL_VARIABLE_LINE = 0x2C; +static const uint32_t ARC_CHEMICAL_ALLOW_SPACE = 0x2D; +static const uint32_t ARC_CHEMICAL_TYPE = 0x2E; +static const uint32_t ARC_CHEMICAL_VALUE = 0x2F; +static const uint32_t ARC_CHEMICAL_NESTED_VALUE = 0x30; +static const uint32_t ARC_CHEMICAL_VALUE_ARGS = 0x31; +static const uint32_t ARC_CHEMICAL_VARIABLE = 0x32; +static const uint32_t ARC_CHEMICAL_VARIABLE_NAME = 0x33; +static const uint32_t ARC_CHEMICAL_VARIABLE_CHAR = 0x34; +static const uint32_t ARC_CHEMICAL_STRING = 0x35; +static const uint32_t ARC_CHEMICAL_STRING_CHARS = 0x36; +static const uint32_t ARC_CHEMICAL_STRING_CHAR = 0x37; +static const uint32_t ARC_CHEMICAL_ESCAPE_CHAR = 0x38; +static const uint32_t ARC_CHEMICAL_WHITESPACE = 0x39; +static const uint32_t ARC_CHEMICAL_NUMBER_TAG = 0x3A; void ARC_Chemical_InitLexerRulesFn(ARC_Lexer *lexer){ ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_CHEMICAL_TAB , '\t')); @@ -262,6 +264,15 @@ uint32_t ARC_Chemical_GetStringIdFn(ARC_String *string){ if(ARC_String_EqualsCStringWithStrlen(string, "")){ return ARC_CHEMICAL_LANGUAGE; } + if(ARC_String_EqualsCStringWithStrlen(string, "")){ + return ARC_CHEMICAL_GROUP; + } + if(ARC_String_EqualsCStringWithStrlen(string, "")){ + return ARC_CHEMICAL_GROUP_NAME; + } + if(ARC_String_EqualsCStringWithStrlen(string, "")){ + return ARC_CHEMICAL_GROUP_ARGS; + } if(ARC_String_EqualsCStringWithStrlen(string, "")){ return ARC_CHEMICAL_VARIABLE_LINES; } @@ -271,9 +282,6 @@ uint32_t ARC_Chemical_GetStringIdFn(ARC_String *string){ if(ARC_String_EqualsCStringWithStrlen(string, "")){ return ARC_CHEMICAL_ALLOW_SPACE; } - if(ARC_String_EqualsCStringWithStrlen(string, "")){ - return ARC_CHEMICAL_GROUP_NAME; - } if(ARC_String_EqualsCStringWithStrlen(string, "")){ return ARC_CHEMICAL_TYPE; } @@ -321,6 +329,7 @@ void ARC_ChemicalData_CreateFn(void **data, ARC_ParserTagToken *parsedData, void printf("HERE??\n"); *data = NULL; if(parsedData == NULL || userData == NULL){ + printf("Parsed Data was NULL\n"); //TODO: error here? *data = NULL; return; @@ -364,30 +373,33 @@ void ARC_Chemical_Create(ARC_Chemical **chemical){ /* ~ define the language as a string ~ */ char *languageCString = - " -> | | LAMBDA\n" + " -> | | LAMBDA\n" - " -> EQUAL SEMICOLON \n" - " -> SPACE | TAB | LAMBDA\n" + " -> OPEN_CURLY_BRACE CLOSE_CURLY_BRACE\n" + " -> \n" + " -> | LAMBDA\n" - " -> \n" - " -> \n" - " -> | \n" - //" -> | | | \n" - //" -> OPEN_CURLY_BRACE CLOSE_CURLY_BRACE\n" - //" -> COMMA | \n" + " -> | \n" + " -> EQUAL SEMICOLON\n" + " -> SPACE | TAB | LAMBDA\n" - " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE \n" - " -> | LAMBDA\n" - " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n" + " -> \n" + " -> | | | \n" + " -> OPEN_CURLY_BRACE CLOSE_CURLY_BRACE\n" + " -> COMMA | \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" + " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE \n" + " -> | LAMBDA\n" + " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n" - " -> NUMBER | 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" - " -> SPACE | TAB | NEWLINE | LAMBDA\n"; + " -> NUMBER | NUMBER\n" + + " -> SPACE | TAB | NEWLINE | LAMBDA\n"; /* ~ define the language as a string ~ */ ARC_String *languageString; diff --git a/tests/std/chemical.c b/tests/std/chemical.c index edbdf56..228574f 100644 --- a/tests/std/chemical.c +++ b/tests/std/chemical.c @@ -10,7 +10,9 @@ ARC_TEST(Chemical_BasicTest){ ARC_CHECK(arc_errno == 0); - char *tempCString = "int32 test = 5; "; + //char *tempCString = "int32 test = 5;"; + char *tempCString = "group test { int32 test = 5; }"; + //char *tempCString = "group test { }"; ARC_String *tempString; ARC_String_CreateWithStrlen(&tempString, tempCString); ARC_Chemical_LoadFromString(chemical, &tempString);