parser working, needs more tests and an actual language to make sure that is true though

This commit is contained in:
herbglitch 2024-11-20 10:27:17 -07:00
parent 63dfb98aad
commit 606f8e4bad
10 changed files with 365 additions and 148 deletions

View file

@ -35,10 +35,15 @@ void ARC_LexerTokenRule_VectorDestroyDataFn(void *data){
free(tokenRule);
}
//private function for destroying a lexer token from a vector
void ARC_LexerToken_VectorDestroyDataFn(void *data){
ARC_LexerToken *token = (ARC_LexerToken *)data;
//deletes the token data string if it exists
if(token->data != NULL){
ARC_String_Destroy(token->data);
}
free(token);
}
@ -177,7 +182,7 @@ void ARC_Lexer_LexString(ARC_Lexer *lexer, ARC_String **data){
ARC_LexerTokenRule *tokenRule = ARC_Vector_Get(lexer->tokenRules, index);
//tokenData should only exist if tokenLength is ARC_True as stated in the header
ARC_String *tokenData;
ARC_String *tokenData = NULL;
tokenLength = tokenRule->automataFn(&tokenData, *data, tokenRule->automataData);
//check if a token was found if it wasn't continue. I'm doing this to try to cut down on the ammount of indentation
@ -189,7 +194,7 @@ void ARC_Lexer_LexString(ARC_Lexer *lexer, ARC_String **data){
if(tokenLength > lastTokenLength){
//free the current token if it exists
if(token != NULL){
ARC_LexerTokenRule_VectorDestroyDataFn((void *)token);
ARC_LexerToken_VectorDestroyDataFn((void *)token);
}
//create the token to add
@ -264,21 +269,18 @@ void ARC_Lexer_PrintTokenRules(ARC_Lexer *lexer){
}
}
ARC_LexerToken ARC_Lexer_GetToken(ARC_Lexer *lexer, uint32_t index){
ARC_LexerToken *ARC_Lexer_GetToken(ARC_Lexer *lexer, uint32_t index){
//get the token and log if there is an error
ARC_LexerToken *token = ARC_Vector_Get(lexer->tokens, index);
if(arc_errno){
ARC_DEBUG_LOG_ERROR("ARC_Lexer_GetToken(lexer, index), errored when running ARC_Vector_Get(lexer->tokens, index);. check logs for more info");
//return a token with max rule value, and NULL for the string to signify an error
return (ARC_LexerToken){
~(uint32_t)0,
NULL
};
return NULL;
}
//the token was found, so return a copy to that
return *token;
//the token was found, so return it
return token;
}
uint32_t ARC_Lexer_GetTokensSize(ARC_Lexer *lexer){
@ -324,8 +326,7 @@ uint32_t ARC_Lexer_AutomataMatchCharOrBetweenFn(ARC_String **tokenData, ARC_Stri
char *automataDataChars = (char *)automataData;
if(string->data[0] >= automataDataChars[0] && string->data[0] <= ((char *)automataData)[1]){
//return the token as token data and the token was found of length 1
//TODO: fix this
//ARC_String_Create(tokenData, string->data, 1);
ARC_String_Create(tokenData, string->data, 1);
return 1;
}