working on debuging chemical language string
This commit is contained in:
parent
bb3601b8f2
commit
18fc05d3d4
4 changed files with 34 additions and 23 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
"<language> -> <variableLine> <language> | <whitespace> <language> | LAMBDA\n"
|
||||
"<language> -> <variableLine> <language> | <whitespace> <language> | LAMBDA\n"
|
||||
|
||||
"<variableLines> -> <variableLine> NEWLINE <variableLines> | <variableLine>\n"
|
||||
"<variableLine> -> <allowSpace> <type> <whitespace> <variable> <whitespace> EQUAL <whitespace> <value> <whitespace> SEMICOLON <allowSpace>\n"
|
||||
"<allowSpace> -> SPACE <allowSpace> | TAB <allowSpace> | LAMBDA\n"
|
||||
"<variableLine> -> <allowSpace> <type> <whitespace> <variable> <whitespace> EQUAL <whitespace> <value> <whitespace> SEMICOLON <allowSpace>\n"
|
||||
"<allowSpace> -> SPACE <allowSpace> | TAB <allowSpace> | LAMBDA\n"
|
||||
|
||||
"<groupName> -> <variable>\n"
|
||||
"<type> -> <variable>\n"
|
||||
"<value> -> <nestedValue> | <variable> | <number> | <string>\n"
|
||||
"<nestedValue> -> OPEN_CURLY_BRACE <whitespace> <valueArgs> <whitespace> CLOSE_CURLY_BRACE\n"
|
||||
"<valueArgs> -> <value> COMMA <valueArgs> | <value>\n"
|
||||
"<groupName> -> <variable>\n"
|
||||
"<type> -> <variable>\n"
|
||||
"<value> -> <variable> | <number>\n"
|
||||
//"<value> -> <variable> | <number> | <string> | <nestedValue>\n"
|
||||
//"<nestedValue> -> OPEN_CURLY_BRACE <whitespace> <valueArgs> <whitespace> CLOSE_CURLY_BRACE\n"
|
||||
//"<valueArgs> -> <value> COMMA <valueArgs> | <value>\n"
|
||||
|
||||
"<variable> -> ALPHA_UPPER_CHAR <variableName> | ALPHA_LOWER_CHAR <variableName> | UNDERSCORE <variableName>\n"
|
||||
"<variableName> -> <variableChar> <variableName> | LAMBDA\n"
|
||||
"<variableChar> -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n"
|
||||
"<variable> -> ALPHA_UPPER_CHAR <variableName> | ALPHA_LOWER_CHAR <variableName> | UNDERSCORE <variableName>\n"
|
||||
"<variableName> -> <variableChar> <variableName> | LAMBDA\n"
|
||||
"<variableChar> -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n"
|
||||
|
||||
"<string> -> QUOTE <stringChars> QUOTE\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"
|
||||
"<escapeChar> -> BACKSLASH BACKSLASH | BACKSLASH QUOTE | BACKSLASH ALPHA_UPPER_CHAR | BACKSLASH ALPHA_LOWER_CHAR\n"
|
||||
//"<string> -> QUOTE <stringChars> QUOTE\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"
|
||||
//"<escapeChar> -> BACKSLASH BACKSLASH | BACKSLASH QUOTE | BACKSLASH ALPHA_UPPER_CHAR | BACKSLASH ALPHA_LOWER_CHAR\n"
|
||||
|
||||
"<number> -> NUMBER <number> | NUMBER\n"
|
||||
"<number> -> NUMBER <number> | NUMBER\n"
|
||||
|
||||
"<whitespace> -> SPACE <whitespace> | TAB <whitespace> | SPACE | TAB\n";
|
||||
"<whitespace> -> SPACE <whitespace> | TAB <whitespace> | NEWLINE <whitespace> | 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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue