added life (entity component system) type, and changed chemical param to try to match more to archeus (or at least what I've read from wikipedia)
This commit is contained in:
parent
e698fb54a2
commit
990c22d27d
6 changed files with 43 additions and 21 deletions
|
|
@ -128,7 +128,7 @@ if(ARCHEUS_TESTS)
|
||||||
add_executable(tests
|
add_executable(tests
|
||||||
tests/test.c
|
tests/test.c
|
||||||
|
|
||||||
tests/std/chemical.c
|
#tests/std/chemical.c
|
||||||
#tests/std/hashtable.c
|
#tests/std/hashtable.c
|
||||||
#tests/std/lexer.c
|
#tests/std/lexer.c
|
||||||
#tests/std/parser.c
|
#tests/std/parser.c
|
||||||
|
|
|
||||||
|
|
@ -89,11 +89,11 @@ void ARC_Chemical_SetGroupWithCStr(ARC_Chemical *chemical, const char *groupName
|
||||||
* @note name may be prefaced with <group>:: to specify group
|
* @note name may be prefaced with <group>:: to specify group
|
||||||
*
|
*
|
||||||
* @param[in] chemical ARC_Chemical to get value from
|
* @param[in] chemical ARC_Chemical to get value from
|
||||||
* @param[in] element name of a variable that has been read in
|
* @param[in] energy name of a variable that has been read in
|
||||||
*
|
*
|
||||||
* @return the stored element on success, or NULL on failure
|
* @return the stored element on success, or NULL on failure
|
||||||
*/
|
*/
|
||||||
void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element);
|
void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *energy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get a value from a given keyname
|
* @brief get a value from a given keyname
|
||||||
|
|
@ -102,11 +102,11 @@ void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element);
|
||||||
* @note this function uses ARC_Chemical_Get so it shares error messages with that function
|
* @note this function uses ARC_Chemical_Get so it shares error messages with that function
|
||||||
*
|
*
|
||||||
* @param[in] chemical ARC_Chemical to get value from
|
* @param[in] chemical ARC_Chemical to get value from
|
||||||
* @param[in] element name of a variable that has been read in
|
* @param[in] energy name of a variable that has been read in
|
||||||
*
|
*
|
||||||
* @return the stored element on success, or NULL on failure
|
* @return the stored element on success, or NULL on failure
|
||||||
*/
|
*/
|
||||||
void *ARC_Chemical_GetWithCStr(ARC_Chemical *chemical, const char *element);
|
void *ARC_Chemical_GetWithCStr(ARC_Chemical *chemical, const char *energy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TODO: write this
|
* @brief TODO: write this
|
||||||
|
|
@ -194,8 +194,9 @@ void ARC_Chemical_UnloadFromFile(ARC_Chemical *chemical, ARC_String *data);
|
||||||
#define ARC_CHEMICAL_STRING_CHARS 0x36
|
#define ARC_CHEMICAL_STRING_CHARS 0x36
|
||||||
#define ARC_CHEMICAL_STRING_CHAR 0x37
|
#define ARC_CHEMICAL_STRING_CHAR 0x37
|
||||||
#define ARC_CHEMICAL_ESCAPE_CHAR 0x38
|
#define ARC_CHEMICAL_ESCAPE_CHAR 0x38
|
||||||
#define ARC_CHEMICAL_WHITESPACE 0x39
|
#define ARC_CHEMICAL_NUMBER_SIGN 0x39
|
||||||
#define ARC_CHEMICAL_NUMBER_TAG 0x3A
|
#define ARC_CHEMICAL_NUMBER_TAG 0x3A
|
||||||
|
#define ARC_CHEMICAL_WHITESPACE 0x3B
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -250,6 +250,9 @@ uint32_t ARC_Chemical_GetStringIdFn(ARC_String *string){
|
||||||
if(ARC_String_EqualsCStringWithStrlen(string, "<escapeChar>")){
|
if(ARC_String_EqualsCStringWithStrlen(string, "<escapeChar>")){
|
||||||
return ARC_CHEMICAL_ESCAPE_CHAR;
|
return ARC_CHEMICAL_ESCAPE_CHAR;
|
||||||
}
|
}
|
||||||
|
if(ARC_String_EqualsCStringWithStrlen(string, "<numberSign>")){
|
||||||
|
return ARC_CHEMICAL_NUMBER_SIGN;
|
||||||
|
}
|
||||||
if(ARC_String_EqualsCStringWithStrlen(string, "<number>")){
|
if(ARC_String_EqualsCStringWithStrlen(string, "<number>")){
|
||||||
return ARC_CHEMICAL_NUMBER_TAG;
|
return ARC_CHEMICAL_NUMBER_TAG;
|
||||||
}
|
}
|
||||||
|
|
@ -561,7 +564,7 @@ void ARC_Chemical_Create(ARC_Chemical **chemical){
|
||||||
"<allowSpace> -> SPACE <allowSpace> | TAB <allowSpace> | LAMBDA\n"
|
"<allowSpace> -> SPACE <allowSpace> | TAB <allowSpace> | LAMBDA\n"
|
||||||
|
|
||||||
"<type> -> <variable>\n"
|
"<type> -> <variable>\n"
|
||||||
"<value> -> <variable> | <number> | <string> | <nestedValue>\n"
|
"<value> -> <variable> | <numberSign> | <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"
|
||||||
|
|
||||||
|
|
@ -574,6 +577,7 @@ void ARC_Chemical_Create(ARC_Chemical **chemical){
|
||||||
"<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"
|
||||||
|
|
||||||
|
"<numberSign> -> MINUS <number> | <number>\n"
|
||||||
"<number> -> NUMBER <number> | NUMBER\n"
|
"<number> -> NUMBER <number> | NUMBER\n"
|
||||||
|
|
||||||
"<whitespace> -> SPACE <whitespace> | TAB <whitespace> | NEWLINE <whitespace> | LAMBDA\n";
|
"<whitespace> -> SPACE <whitespace> | TAB <whitespace> | NEWLINE <whitespace> | LAMBDA\n";
|
||||||
|
|
@ -669,15 +673,15 @@ void ARC_Chemical_SetGroupWithCStr(ARC_Chemical *chemical, const char *groupName
|
||||||
chemical->currentGroup = currentGroup;
|
chemical->currentGroup = currentGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element){
|
void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *energy){
|
||||||
//check if the group separator exists
|
//check if the group separator exists
|
||||||
uint64_t startSeparatorIndex = ARC_String_FindCStringWithStrlen(element, ARC_CHEMICAL_GROUP_SEPARATOR);
|
uint64_t startSeparatorIndex = ARC_String_FindCStringWithStrlen(energy, ARC_CHEMICAL_GROUP_SEPARATOR);
|
||||||
if(startSeparatorIndex == ~(uint64_t)0){
|
if(startSeparatorIndex == ~(uint64_t)0){
|
||||||
//use empty group
|
//use empty group
|
||||||
chemical->currentGroup = ARC_Hashtable_Get(chemical->groups, (void *)ARC_CHEMICAL_DEFAULT_GROUP);
|
chemical->currentGroup = ARC_Hashtable_Get(chemical->groups, (void *)ARC_CHEMICAL_DEFAULT_GROUP);
|
||||||
|
|
||||||
//get the typeData and pass back the data without the cleanup function
|
//get the typeData and pass back the data without the cleanup function
|
||||||
ARC_ChemicalTypeData *typeData = (ARC_ChemicalTypeData *)ARC_Hashtable_Get(chemical->currentGroup, (void *)element->data);
|
ARC_ChemicalTypeData *typeData = (ARC_ChemicalTypeData *)ARC_Hashtable_Get(chemical->currentGroup, (void *)energy->data);
|
||||||
if(typeData == NULL){
|
if(typeData == NULL){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -688,7 +692,7 @@ void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element){
|
||||||
//get the group
|
//get the group
|
||||||
startSeparatorIndex--;
|
startSeparatorIndex--;
|
||||||
ARC_String *groupString;
|
ARC_String *groupString;
|
||||||
ARC_String_CopySubstring(&groupString, element, 0, startSeparatorIndex);
|
ARC_String_CopySubstring(&groupString, energy, 0, startSeparatorIndex);
|
||||||
|
|
||||||
//set the group
|
//set the group
|
||||||
chemical->currentGroup = ARC_Hashtable_Get(chemical->groups, (void *)groupString->data);
|
chemical->currentGroup = ARC_Hashtable_Get(chemical->groups, (void *)groupString->data);
|
||||||
|
|
@ -697,13 +701,13 @@ void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element){
|
||||||
ARC_String_Destroy(groupString);
|
ARC_String_Destroy(groupString);
|
||||||
|
|
||||||
//get the element
|
//get the element
|
||||||
ARC_String *elementString;
|
ARC_String *energyString;
|
||||||
startSeparatorIndex += strlen(ARC_CHEMICAL_GROUP_SEPARATOR);
|
startSeparatorIndex += strlen(ARC_CHEMICAL_GROUP_SEPARATOR);
|
||||||
ARC_String_CopySubstring(&elementString, element, startSeparatorIndex, element->length - startSeparatorIndex);
|
ARC_String_CopySubstring(&energyString, energy, startSeparatorIndex, energy->length - startSeparatorIndex);
|
||||||
|
|
||||||
//this will either return the value or NULL
|
//this will either return the value or NULL
|
||||||
ARC_ChemicalTypeData *typeData = (ARC_ChemicalTypeData *)ARC_Hashtable_Get(chemical->currentGroup, (void *)elementString->data);
|
ARC_ChemicalTypeData *typeData = (ARC_ChemicalTypeData *)ARC_Hashtable_Get(chemical->currentGroup, (void *)energyString->data);
|
||||||
ARC_String_Destroy(elementString);
|
ARC_String_Destroy(energyString);
|
||||||
if(typeData == NULL){
|
if(typeData == NULL){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -711,16 +715,16 @@ void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element){
|
||||||
return typeData->data;
|
return typeData->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ARC_Chemical_GetWithCStr(ARC_Chemical *chemical, const char *element){
|
void *ARC_Chemical_GetWithCStr(ARC_Chemical *chemical, const char *energy){
|
||||||
//create and copy into ARC_String
|
//create and copy into ARC_String
|
||||||
ARC_String *elementString;
|
ARC_String *energyString;
|
||||||
ARC_String_CreateWithStrlen(&elementString, (char *)element);
|
ARC_String_CreateWithStrlen(&energyString, (char *)energy);
|
||||||
|
|
||||||
//get the return value
|
//get the return value
|
||||||
void *returnValue = ARC_Chemical_Get(chemical, elementString);
|
void *returnValue = ARC_Chemical_Get(chemical, energyString);
|
||||||
|
|
||||||
//cleanup
|
//cleanup
|
||||||
ARC_String_Destroy(elementString);
|
ARC_String_Destroy(energyString);
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
group test {
|
group test {
|
||||||
int32 test = 5;
|
int32 test = 5;
|
||||||
|
|
||||||
|
int32 test1 = -7;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,22 @@
|
||||||
static const char *testType = "int32";
|
static const char *testType = "int32";
|
||||||
|
|
||||||
void TEST_ChemicalType_CopyInt32Fn(void **type, ARC_ParserTagToken *parsedData, ARC_Chemical *chemical){
|
void TEST_ChemicalType_CopyInt32Fn(void **type, ARC_ParserTagToken *parsedData, ARC_Chemical *chemical){
|
||||||
|
//go into the <numberSign> tag
|
||||||
|
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
|
||||||
|
if(childTagToken->id != ARC_CHEMICAL_NUMBER_SIGN){
|
||||||
|
arc_errno = ARC_ERRNO_DATA;
|
||||||
|
ARC_DEBUG_LOG_ERROR("TEST_ChemicalType_CopyInt32Fn(type, parsedData, chemical), parsed data was not a <numberSign>");
|
||||||
|
*type = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check if the first tag is a minus sign and create a string starting with that if it is
|
||||||
|
childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 0);
|
||||||
ARC_String *int32String;
|
ARC_String *int32String;
|
||||||
ARC_String_Create(&int32String, NULL, 0);
|
ARC_String_Create(&int32String, NULL, 0);
|
||||||
|
if(childTagToken->id == ARC_CHEMICAL_MINUS){
|
||||||
|
ARC_String_AppendCStringWithStrlen(&int32String, "-");
|
||||||
|
}
|
||||||
|
|
||||||
ARC_ParserData_HelperRecurseStringAdd(&int32String, parsedData);
|
ARC_ParserData_HelperRecurseStringAdd(&int32String, parsedData);
|
||||||
|
|
||||||
|
|
@ -80,6 +94,8 @@ ARC_TEST(Chemical_BasicTest){
|
||||||
|
|
||||||
int32_t testVal = *(int32_t *)ARC_Chemical_GetWithCStr(chemical, "test::test");
|
int32_t testVal = *(int32_t *)ARC_Chemical_GetWithCStr(chemical, "test::test");
|
||||||
ARC_CHECK(testVal == 5);
|
ARC_CHECK(testVal == 5);
|
||||||
|
testVal = *(int32_t *)ARC_Chemical_GetWithCStr(chemical, "test::test1");
|
||||||
|
ARC_CHECK(testVal == -7);
|
||||||
|
|
||||||
ARC_Chemical_UnloadFromFile(chemical, tempString);
|
ARC_Chemical_UnloadFromFile(chemical, tempString);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,6 @@ ARC_TEST(Hashtable_Add_Get_Remove){
|
||||||
ARC_CHECK(5 == *(int32_t *)ARC_Hashtable_Get(hashtable, (void *)"key7"));
|
ARC_CHECK(5 == *(int32_t *)ARC_Hashtable_Get(hashtable, (void *)"key7"));
|
||||||
ARC_CHECK(6 == *(int32_t *)ARC_Hashtable_Get(hashtable, (void *)"key8"));
|
ARC_CHECK(6 == *(int32_t *)ARC_Hashtable_Get(hashtable, (void *)"key8"));
|
||||||
|
|
||||||
TEST_Hashtable_Print(hashtable);
|
|
||||||
ARC_Hashtable_Remove(hashtable, (void *)"key2");
|
ARC_Hashtable_Remove(hashtable, (void *)"key2");
|
||||||
|
|
||||||
ARC_CHECK(2 == *(int32_t *)ARC_Hashtable_Get(hashtable, (void *)"key0"));
|
ARC_CHECK(2 == *(int32_t *)ARC_Hashtable_Get(hashtable, (void *)"key0"));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue