basic tests for chemical parsing, still need to write create and destroy functions for passed back data

This commit is contained in:
herbglitch 2025-03-08 02:30:23 -07:00
parent 18fc05d3d4
commit b2aec6be00
2 changed files with 53 additions and 39 deletions

View file

@ -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_TILDE = 0x26;
static const uint32_t ARC_CHEMICAL_LANGUAGE = 0x27; static const uint32_t ARC_CHEMICAL_LANGUAGE = 0x27;
static const uint32_t ARC_CHEMICAL_VARIABLE_LINES = 0x28; static const uint32_t ARC_CHEMICAL_GROUP = 0x28;
static const uint32_t ARC_CHEMICAL_VARIABLE_LINE = 0x29; static const uint32_t ARC_CHEMICAL_GROUP_NAME = 0x29;
static const uint32_t ARC_CHEMICAL_ALLOW_SPACE = 0x2A; static const uint32_t ARC_CHEMICAL_GROUP_ARGS = 0x2A;
static const uint32_t ARC_CHEMICAL_GROUP_NAME = 0x2B; static const uint32_t ARC_CHEMICAL_VARIABLE_LINES = 0x2B;
static const uint32_t ARC_CHEMICAL_TYPE = 0x2C; static const uint32_t ARC_CHEMICAL_VARIABLE_LINE = 0x2C;
static const uint32_t ARC_CHEMICAL_VALUE = 0x2D; static const uint32_t ARC_CHEMICAL_ALLOW_SPACE = 0x2D;
static const uint32_t ARC_CHEMICAL_NESTED_VALUE = 0x2E; static const uint32_t ARC_CHEMICAL_TYPE = 0x2E;
static const uint32_t ARC_CHEMICAL_VALUE_ARGS = 0x2F; static const uint32_t ARC_CHEMICAL_VALUE = 0x2F;
static const uint32_t ARC_CHEMICAL_VARIABLE = 0x30; static const uint32_t ARC_CHEMICAL_NESTED_VALUE = 0x30;
static const uint32_t ARC_CHEMICAL_VARIABLE_NAME = 0x31; static const uint32_t ARC_CHEMICAL_VALUE_ARGS = 0x31;
static const uint32_t ARC_CHEMICAL_VARIABLE_CHAR = 0x32; static const uint32_t ARC_CHEMICAL_VARIABLE = 0x32;
static const uint32_t ARC_CHEMICAL_STRING = 0x33; static const uint32_t ARC_CHEMICAL_VARIABLE_NAME = 0x33;
static const uint32_t ARC_CHEMICAL_STRING_CHARS = 0x34; static const uint32_t ARC_CHEMICAL_VARIABLE_CHAR = 0x34;
static const uint32_t ARC_CHEMICAL_STRING_CHAR = 0x35; static const uint32_t ARC_CHEMICAL_STRING = 0x35;
static const uint32_t ARC_CHEMICAL_ESCAPE_CHAR = 0x36; static const uint32_t ARC_CHEMICAL_STRING_CHARS = 0x36;
static const uint32_t ARC_CHEMICAL_WHITESPACE = 0x37; static const uint32_t ARC_CHEMICAL_STRING_CHAR = 0x37;
static const uint32_t ARC_CHEMICAL_NUMBER_TAG = 0x38; 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){ void ARC_Chemical_InitLexerRulesFn(ARC_Lexer *lexer){
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_CHEMICAL_TAB , '\t')); 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, "<language>")){ if(ARC_String_EqualsCStringWithStrlen(string, "<language>")){
return ARC_CHEMICAL_LANGUAGE; return ARC_CHEMICAL_LANGUAGE;
} }
if(ARC_String_EqualsCStringWithStrlen(string, "<group>")){
return ARC_CHEMICAL_GROUP;
}
if(ARC_String_EqualsCStringWithStrlen(string, "<groupName>")){
return ARC_CHEMICAL_GROUP_NAME;
}
if(ARC_String_EqualsCStringWithStrlen(string, "<groupArgs>")){
return ARC_CHEMICAL_GROUP_ARGS;
}
if(ARC_String_EqualsCStringWithStrlen(string, "<variableLines>")){ if(ARC_String_EqualsCStringWithStrlen(string, "<variableLines>")){
return ARC_CHEMICAL_VARIABLE_LINES; return ARC_CHEMICAL_VARIABLE_LINES;
} }
@ -271,9 +282,6 @@ uint32_t ARC_Chemical_GetStringIdFn(ARC_String *string){
if(ARC_String_EqualsCStringWithStrlen(string, "<allowSpace>")){ if(ARC_String_EqualsCStringWithStrlen(string, "<allowSpace>")){
return ARC_CHEMICAL_ALLOW_SPACE; return ARC_CHEMICAL_ALLOW_SPACE;
} }
if(ARC_String_EqualsCStringWithStrlen(string, "<groupName>")){
return ARC_CHEMICAL_GROUP_NAME;
}
if(ARC_String_EqualsCStringWithStrlen(string, "<type>")){ if(ARC_String_EqualsCStringWithStrlen(string, "<type>")){
return ARC_CHEMICAL_TYPE; return ARC_CHEMICAL_TYPE;
} }
@ -321,6 +329,7 @@ void ARC_ChemicalData_CreateFn(void **data, ARC_ParserTagToken *parsedData, void
printf("HERE??\n"); printf("HERE??\n");
*data = NULL; *data = NULL;
if(parsedData == NULL || userData == NULL){ if(parsedData == NULL || userData == NULL){
printf("Parsed Data was NULL\n");
//TODO: error here? //TODO: error here?
*data = NULL; *data = NULL;
return; return;
@ -364,26 +373,29 @@ void ARC_Chemical_Create(ARC_Chemical **chemical){
/* ~ define the language as a string ~ */ /* ~ define the language as a string ~ */
char *languageCString = char *languageCString =
"<language> -> <variableLine> <language> | <whitespace> <language> | LAMBDA\n" "<language> -> <group> <language> | <variableLines> <language> | LAMBDA\n"
"<variableLine> -> <allowSpace> <type> <whitespace> <variable> <whitespace> EQUAL <whitespace> <value> <whitespace> SEMICOLON <allowSpace>\n" "<group> -> <whitespace> <groupName> <whitespace> <variable> <whitespace> OPEN_CURLY_BRACE <groupArgs> <whitespace> CLOSE_CURLY_BRACE\n"
"<groupName> -> <variable>\n"
"<groupArgs> -> <whitespace> <variableLines> | LAMBDA\n"
"<variableLines> -> <variableLine> <whitespace> <variableLines> | <variableLine>\n"
"<variableLine> -> <whitespace> <type> <whitespace> <variable> <whitespace> EQUAL <whitespace> <value> <whitespace> SEMICOLON\n"
"<allowSpace> -> SPACE <allowSpace> | TAB <allowSpace> | LAMBDA\n" "<allowSpace> -> SPACE <allowSpace> | TAB <allowSpace> | LAMBDA\n"
"<groupName> -> <variable>\n"
"<type> -> <variable>\n" "<type> -> <variable>\n"
"<value> -> <variable> | <number>\n" "<value> -> <variable> | <number> | <string> | <nestedValue>\n"
//"<value> -> <variable> | <number> | <string> | <nestedValue>\n" "<nestedValue> -> OPEN_CURLY_BRACE <whitespace> <valueArgs> <whitespace> CLOSE_CURLY_BRACE\n"
//"<nestedValue> -> OPEN_CURLY_BRACE <whitespace> <valueArgs> <whitespace> CLOSE_CURLY_BRACE\n" "<valueArgs> -> <value> COMMA <valueArgs> | <value>\n"
//"<valueArgs> -> <value> COMMA <valueArgs> | <value>\n"
"<variable> -> ALPHA_UPPER_CHAR <variableName> | ALPHA_LOWER_CHAR <variableName> | UNDERSCORE <variableName>\n" "<variable> -> ALPHA_UPPER_CHAR <variableName> | ALPHA_LOWER_CHAR <variableName> | UNDERSCORE <variableName>\n"
"<variableName> -> <variableChar> <variableName> | LAMBDA\n" "<variableName> -> <variableChar> <variableName> | LAMBDA\n"
"<variableChar> -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n" "<variableChar> -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n"
//"<string> -> QUOTE <stringChars> QUOTE\n" "<string> -> QUOTE <stringChars> QUOTE\n"
//"<stringChars> -> <stringChar> <stringChars> | <escapeChar> <stringChars> | LAMBDA\n" "<stringChars> -> <stringChar> <stringChars> | <escapeChar> <stringChars> | LAMBDA\n"
//"<stringChar> -> 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" "<stringChar> -> 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"
//"<escapeChar> -> BACKSLASH BACKSLASH | BACKSLASH QUOTE | BACKSLASH ALPHA_UPPER_CHAR | BACKSLASH ALPHA_LOWER_CHAR\n" "<escapeChar> -> BACKSLASH BACKSLASH | BACKSLASH QUOTE | BACKSLASH ALPHA_UPPER_CHAR | BACKSLASH ALPHA_LOWER_CHAR\n"
"<number> -> NUMBER <number> | NUMBER\n" "<number> -> NUMBER <number> | NUMBER\n"

View file

@ -10,7 +10,9 @@ ARC_TEST(Chemical_BasicTest){
ARC_CHECK(arc_errno == 0); 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 *tempString;
ARC_String_CreateWithStrlen(&tempString, tempCString); ARC_String_CreateWithStrlen(&tempString, tempCString);
ARC_Chemical_LoadFromString(chemical, &tempString); ARC_Chemical_LoadFromString(chemical, &tempString);