Loading...
Searching...
No Matches
parserlang.c File Reference
`#include "arc/std/parser/parserlang.h"`
`#include "arc/std/bool.h"`
`#include "arc/std/errno.h"`
`#include "arc/std/lexer.h"`
`#include "arc/std/parser.h"`
`#include "arc/std/string.h"`
`#include "arc/std/vector.h"`
`#include <stddef.h>`
`#include <stdlib.h>`

Go to the source code of this file.

## Functions

void | ARC_ParserLang_InitLexerRulesFn (ARC_Lexer *lexer)
void | ARC_ParserLang_VectorDestroyVectorFn (void *data)
void | ARC_ParserLang_VectorDestroyUInt32Fn (void *data)
void | ARC_ParserLang_VectorDestroyParserTagFn (void *data)
void | ARC_ParserLangParsedData_RecurseStringAdd (ARC_String **data, ARC_ParserTagToken *tagToken)
void | ARC_ParserLangParsedData_CreateTagString (ARC_String **tagString, ARC_ParserTagToken *tagToken)
void | ARC_ParserLangParsedData_GetArgumentTag (ARC_Vector *orTokensOrTags, ARC_ParserTagToken *tagToken, ARC_Parser_GetStringIdFn *getStringIdFn)
void | ARC_ParserLangParsedData_GetArgumentsTag (ARC_Vector *tokensOrTags, ARC_ParserTagToken *tagToken, ARC_Parser_GetStringIdFn *getStringIdFn)
void | ARC_ParserLangParsedData_CreateBodyTag (ARC_ParserTag **tag, ARC_ParserTagToken *tagToken, ARC_Parser_GetStringIdFn *getStringIdFn)
void | ARC_ParserLangParsedData_RunLineTag (ARC_Vector *tags, ARC_ParserTagToken *tagToken, ARC_Parser_GetStringIdFn *getStringIdFn)
void | ARC_ParserLang_CreateDataFn (void **data, ARC_ParserTagToken *parsedData, void *userData)
void | ARC_ParserLang_DestroyDataFn (void *data, ARC_Bool clear, void *userData)
void | ARC_ParserLang_CreateAsParser (ARC_Parser **parser, ARC_Parser_GetStringIdFn getStringIdFn)
| creates a parser for the Parser Lang

## Function Documentation

## ARC_ParserLang_CreateAsParser()

void ARC_ParserLang_CreateAsParser | ( | ARC_Parser ** | parser,
|  | ARC_Parser_GetStringIdFn | getStringIdFn )

creates a parser for the Parser Lang

Note
  the rules will be inited for the parser lang
  the parsed data will be saved as a vector of ARC_ParserLanguageTag

Parameters

  [out] | parser | the parser to create

Definition at line 324 of file parserlang.c.

{
//<line> -> <body> NEWLINE <line> | <body> | NEWLINE <line> | LAMBDA
uint32_t *line[] = { (uint32_t[]){ 3, ARC_PARSERLANG_BODY, ARC_PARSERLANG_TOKEN_NEWLINE_ID, ARC_PARSERLANG_LINE }, (uint32_t[]){ 1, ARC_PARSERLANG_BODY }, (uint32_t[]){ 2, ARC_PARSERLANG_TOKEN_NEWLINE_ID, ARC_PARSERLANG_LINE }, (uint32_t[]){ 1, ARC_PARSERLANG_LAMBDA } };
//<body> -> <tag> <whitespace> ARROW <whitespace> <arguments>
uint32_t *body[] = { (uint32_t[]){ 5, ARC_PARSERLANG_TAG, ARC_PARSERLANG_WHITESPACE, ARC_PARSERLANG_TOKEN_ARROW_ID, ARC_PARSERLANG_WHITESPACE, ARC_PARSERLANG_ARGUMENTS } };
//<arguments> -> <argument> <whitespace> OR <whitespace> <arguments> | <argument>
uint32_t *arguments[] = { (uint32_t[]){ 5, ARC_PARSERLANG_ARGUMENT, ARC_PARSERLANG_WHITESPACE, ARC_PARSERLANG_TOKEN_OR_ID, ARC_PARSERLANG_WHITESPACE, ARC_PARSERLANG_ARGUMENTS }, (uint32_t[]){ 1, ARC_PARSERLANG_ARGUMENT } };
//<argument> -> <tagOrConstant> <whitespace> <argument> | <tagOrConstant>
uint32_t *argument[] = { (uint32_t[]){ 3, ARC_PARSERLANG_TAG_OR_CONSTANT, ARC_PARSERLANG_WHITESPACE, ARC_PARSERLANG_ARGUMENT }, (uint32_t[]){ 1, ARC_PARSERLANG_TAG_OR_CONSTANT } };
//<tagOrConstant> -> <parserLangageTag> | <constant>
uint32_t *tagOrConstant[] = { (uint32_t[]){ 1, ARC_PARSERLANG_TAG }, (uint32_t[]){ 1, ARC_PARSERLANG_CONSTANT } };
//<constant> -> ALPHA_UPPER_CHAR <constantBody>
uint32_t *constant[] = { (uint32_t[]){ 2, ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR, ARC_PARSERLANG_CONSTANT_BODY } };
//<constantBody> -> <constantChar> <constantBody> | LAMBDA
uint32_t *constantBody[] = { (uint32_t[]){ 2, ARC_PARSERLANG_CONSTANT_CHAR, ARC_PARSERLANG_CONSTANT_BODY }, (uint32_t[]){ 1, ARC_PARSERLANG_LAMBDA } };
//<constantChar> -> ALPHA_UPPER_CHAR | UNDERSCORE
uint32_t *constantChar[] = { (uint32_t[]){ 1, ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR }, (uint32_t[]){ 1, ARC_PARSERLANG_TOKEN_UNDERSCORE_ID } };
//<tag> -> LESS_THAN <variable> GREATER_THAN
uint32_t *tag[] = { (uint32_t[]){ 3, ARC_PARSERLANG_TOKEN_LESS_THAN_ID, ARC_PARSERLANG_VARIABLE, ARC_PARSERLANG_TOKEN_GREATER_THAN_ID } };
//<variable> -> <alphaChar> <variableBody> | UNDERSCORE <variableBody>
uint32_t *variable[] = { (uint32_t[]){ 2, ARC_PARSERLANG_ALPHA_CHAR, ARC_PARSERLANG_VARIABLE_BODY }, (uint32_t[]){ 2, ARC_PARSERLANG_TOKEN_UNDERSCORE_ID, ARC_PARSERLANG_VARIABLE_BODY } };
//<variableBody> -> <variableChar> <variableBody> | LAMBDA
uint32_t *variableBody[] = { (uint32_t[]){ 2, ARC_PARSERLANG_VARIABLE_CHAR, ARC_PARSERLANG_VARIABLE_BODY }, (uint32_t[]){ 1, ARC_PARSERLANG_LAMBDA } };
//<variableChar> -> <alphaChar> | NUMBER | UNDERSCORE
uint32_t *variableChar[] = { (uint32_t[]){ 1, ARC_PARSERLANG_ALPHA_CHAR }, (uint32_t[]){ 1, ARC_PARSERLANG_TOKEN_NUMBER }, (uint32_t[]){ 1, ARC_PARSERLANG_TOKEN_UNDERSCORE_ID } };
//<alphaChar> -> ALPHA_LOWER_CHAR | ALPHA_UPPER_CHAR
uint32_t *alphaChar[] = { (uint32_t[]){ 1, ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR }, (uint32_t[]){ 1, ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR }};
//<whitespace> -> WHITESPACE <whitespace> | WHITESPACE
uint32_t *whitespace[] = { (uint32_t[]){ 2, ARC_PARSERLANG_TOKEN_WHITESPACE, ARC_PARSERLANG_WHITESPACE }, (uint32_t[]){ 1, ARC_PARSERLANG_TOKEN_WHITESPACE }};
ARC_ParserTag parserLangTags[14] = {
{ ARC_PARSERLANG_LINE , line , 4 },
{ ARC_PARSERLANG_BODY , body , 1 },
{ ARC_PARSERLANG_ARGUMENTS , arguments , 2 },
{ ARC_PARSERLANG_ARGUMENT , argument , 2 },
{ ARC_PARSERLANG_TAG_OR_CONSTANT, tagOrConstant, 2 },
{ ARC_PARSERLANG_CONSTANT , constant , 1 },
{ ARC_PARSERLANG_CONSTANT_BODY , constantBody , 2 },
{ ARC_PARSERLANG_CONSTANT_CHAR , constantChar , 2 },
{ ARC_PARSERLANG_TAG , tag , 1 },
{ ARC_PARSERLANG_VARIABLE , variable , 2 },
{ ARC_PARSERLANG_VARIABLE_BODY , variableBody , 2 },
{ ARC_PARSERLANG_VARIABLE_CHAR , variableChar , 3 },
{ ARC_PARSERLANG_ALPHA_CHAR , alphaChar , 2 },
{ ARC_PARSERLANG_WHITESPACE , whitespace , 2 }
};
ARC_Array parserLanguageArray = {
14, //size
parserLangTags //data
};
ARC_ParserData_CreateFn createDataFn = ARC_ParserLang_CreateDataFn;
ARC_ParserData_DestroyFn destroyDataFn = ARC_ParserLang_DestroyDataFn;
//this will be cleaned up by the destroyDataFn
ARC_Parser_GetStringIdFn *newGetStringIdFn = (ARC_Parser_GetStringIdFn *)malloc(sizeof(ARC_Parser_GetStringIdFn));
*newGetStringIdFn = getStringIdFn;
//create the parserlang
ARC_Parser_Create(parser, &parserLanguageArray, ARC_ParserLang_InitLexerRulesFn, &createDataFn, &destroyDataFn, (void *)newGetStringIdFn);
}
ARC_Parser_Create
void ARC_Parser_Create(ARC_Parser **parser, ARC_Array *language, ARC_Parser_InitLexerRulesFn initLexerRulesFn, ARC_ParserData_CreateFn *createDataFn, ARC_ParserData_DestroyFn *destroyDataFn, void *userData)
creates an ARC_Parser type
Definition parser.c:24
ARC_Parser_GetStringIdFn
uint32_t(* ARC_Parser_GetStringIdFn)(ARC_String *string)
TODO: write this.
Definition parser.h:52
ARC_ParserData_CreateFn
void(* ARC_ParserData_CreateFn)(void **data, ARC_ParserTagToken *parsedData, void *userData)
TODO: write this.
Definition parser.h:57
ARC_ParserData_DestroyFn
void(* ARC_ParserData_DestroyFn)(void *data, ARC_Bool clear, void *userData)
TODO: write this.
Definition parser.h:62
ARC_ParserLang_CreateDataFn
void ARC_ParserLang_CreateDataFn(void **data, ARC_ParserTagToken *parsedData, void *userData)
Definition parserlang.c:286
ARC_ParserLang_DestroyDataFn
void ARC_ParserLang_DestroyDataFn(void *data, ARC_Bool clear, void *userData)
Definition parserlang.c:312
ARC_ParserLang_InitLexerRulesFn
void ARC_ParserLang_InitLexerRulesFn(ARC_Lexer *lexer)
Definition parserlang.c:12
ARC_PARSERLANG_CONSTANT_CHAR
#define ARC_PARSERLANG_CONSTANT_CHAR
Definition parserlang.h:69
ARC_PARSERLANG_TAG
#define ARC_PARSERLANG_TAG
Definition parserlang.h:70
ARC_PARSERLANG_ALPHA_CHAR
#define ARC_PARSERLANG_ALPHA_CHAR
Definition parserlang.h:74
ARC_PARSERLANG_TOKEN_NEWLINE_ID
#define ARC_PARSERLANG_TOKEN_NEWLINE_ID
Definition parserlang.h:47
ARC_PARSERLANG_BODY
#define ARC_PARSERLANG_BODY
Definition parserlang.h:63
ARC_PARSERLANG_WHITESPACE
#define ARC_PARSERLANG_WHITESPACE
Definition parserlang.h:75
ARC_PARSERLANG_CONSTANT
#define ARC_PARSERLANG_CONSTANT
Definition parserlang.h:67
ARC_PARSERLANG_TOKEN_NUMBER
#define ARC_PARSERLANG_TOKEN_NUMBER
Definition parserlang.h:42
ARC_PARSERLANG_TAG_OR_CONSTANT
#define ARC_PARSERLANG_TAG_OR_CONSTANT
Definition parserlang.h:66
ARC_PARSERLANG_TOKEN_ARROW_ID
#define ARC_PARSERLANG_TOKEN_ARROW_ID
Definition parserlang.h:58
ARC_PARSERLANG_TOKEN_LESS_THAN_ID
#define ARC_PARSERLANG_TOKEN_LESS_THAN_ID
Definition parserlang.h:49
ARC_PARSERLANG_TOKEN_GREATER_THAN_ID
#define ARC_PARSERLANG_TOKEN_GREATER_THAN_ID
Definition parserlang.h:51
ARC_PARSERLANG_TOKEN_OR_ID
#define ARC_PARSERLANG_TOKEN_OR_ID
Definition parserlang.h:53
ARC_PARSERLANG_TOKEN_WHITESPACE
#define ARC_PARSERLANG_TOKEN_WHITESPACE
Definition parserlang.h:45
ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR
#define ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR
Definition parserlang.h:44
ARC_PARSERLANG_LINE
#define ARC_PARSERLANG_LINE
Definition parserlang.h:62
ARC_PARSERLANG_VARIABLE_BODY
#define ARC_PARSERLANG_VARIABLE_BODY
Definition parserlang.h:72
ARC_PARSERLANG_VARIABLE_CHAR
#define ARC_PARSERLANG_VARIABLE_CHAR
Definition parserlang.h:73
ARC_PARSERLANG_CONSTANT_BODY
#define ARC_PARSERLANG_CONSTANT_BODY
Definition parserlang.h:68
ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR
#define ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR
Definition parserlang.h:43
ARC_PARSERLANG_ARGUMENT
#define ARC_PARSERLANG_ARGUMENT
Definition parserlang.h:65
ARC_PARSERLANG_TOKEN_UNDERSCORE_ID
#define ARC_PARSERLANG_TOKEN_UNDERSCORE_ID
Definition parserlang.h:55
ARC_PARSERLANG_ARGUMENTS
#define ARC_PARSERLANG_ARGUMENTS
Definition parserlang.h:64
ARC_PARSERLANG_VARIABLE
#define ARC_PARSERLANG_VARIABLE
Definition parserlang.h:71
ARC_PARSERLANG_LAMBDA
#define ARC_PARSERLANG_LAMBDA
Definition parserlang.h:61
ARC_Array
a type that holds an array of data and its size
Definition array.h:13
ARC_ParserTag
a langue tag type for the parser //TODO: explain this better
Definition parser.h:21

References ARC_Parser_Create(), ARC_PARSERLANG_ALPHA_CHAR, ARC_PARSERLANG_ARGUMENT, ARC_PARSERLANG_ARGUMENTS, ARC_PARSERLANG_BODY, ARC_PARSERLANG_CONSTANT, ARC_PARSERLANG_CONSTANT_BODY, ARC_PARSERLANG_CONSTANT_CHAR, ARC_ParserLang_CreateDataFn(), ARC_ParserLang_DestroyDataFn(), ARC_ParserLang_InitLexerRulesFn(), ARC_PARSERLANG_LAMBDA, ARC_PARSERLANG_LINE, ARC_PARSERLANG_TAG, ARC_PARSERLANG_TAG_OR_CONSTANT, ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR, ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR, ARC_PARSERLANG_TOKEN_ARROW_ID, ARC_PARSERLANG_TOKEN_GREATER_THAN_ID, ARC_PARSERLANG_TOKEN_LESS_THAN_ID, ARC_PARSERLANG_TOKEN_NEWLINE_ID, ARC_PARSERLANG_TOKEN_NUMBER, ARC_PARSERLANG_TOKEN_OR_ID, ARC_PARSERLANG_TOKEN_UNDERSCORE_ID, ARC_PARSERLANG_TOKEN_WHITESPACE, ARC_PARSERLANG_VARIABLE, ARC_PARSERLANG_VARIABLE_BODY, ARC_PARSERLANG_VARIABLE_CHAR, and ARC_PARSERLANG_WHITESPACE.

Referenced by ARC_Parser_CreateFromString().

## ARC_ParserLang_CreateDataFn()

void ARC_ParserLang_CreateDataFn | ( | void ** | data,
|  | ARC_ParserTagToken * | parsedData,
|  | void * | userData )

Definition at line 286 of file parserlang.c.

{
ARC_Parser_GetStringIdFn *getStringIdFn = (ARC_Parser_GetStringIdFn *)userData;
//make sure there is parsed data to use
if(parsedData == NULL){
arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG_ERROR("ARC_ParserLang_CreateDataFn(void **data, ARC_ParserTagToken *parsedData, void *userData), parsedData was NULL when passed in");
return;
}
//function callback to cleanup added tags
ARC_Vector_DestroyDataFn destroyParserTagFn = ARC_ParserLang_VectorDestroyParserTagFn;
//I don't see a reason to have a comparison function right now. this might change in the future
ARC_Vector_Create((ARC_Vector **)data, NULL, &destroyParserTagFn);
//check if there are any tags (thes could be empty if a file is blank)
if(parsedData->tagTokens == NULL){
return;
}
//load the language into a vector recursivly
ARC_ParserLangParsedData_RunLineTag(*((ARC_Vector **)data), parsedData, getStringIdFn);
}
arc_errno
int32_t arc_errno
Definition errno.c:5
ARC_ERRNO_NULL
#define ARC_ERRNO_NULL
Definition errno.h:6
ARC_DEBUG_LOG_ERROR
#define ARC_DEBUG_LOG_ERROR(STR)
Definition errno.h:39
ARC_ParserLang_VectorDestroyParserTagFn
void ARC_ParserLang_VectorDestroyParserTagFn(void *data)
Definition parserlang.c:53
ARC_ParserLangParsedData_RunLineTag
void ARC_ParserLangParsedData_RunLineTag(ARC_Vector *tags, ARC_ParserTagToken *tagToken, ARC_Parser_GetStringIdFn *getStringIdFn)
Definition parserlang.c:259
ARC_ParserTagToken::tagTokens
ARC_Vector * tagTokens
Definition parser.h:39
ARC_Vector
Definition vector.c:9
ARC_Vector_DestroyDataFn
void(* ARC_Vector_DestroyDataFn)(void *data)
a callback that cleans up memory when it is removed from the vector
Definition vector.h:31
ARC_Vector_Create
void ARC_Vector_Create(ARC_Vector **vector, ARC_Vector_CompareDataFn *compareDataFn, ARC_Vector_DestroyDataFn *destroyDataFn)
creates an ARC_Vector which is an "expandable" array
Definition vector.c:28

References ARC_DEBUG_LOG_ERROR, arc_errno, ARC_ERRNO_NULL, ARC_ParserLang_VectorDestroyParserTagFn(), ARC_ParserLangParsedData_RunLineTag(), ARC_Vector_Create(), and ARC_ParserTagToken::tagTokens.

Referenced by ARC_ParserLang_CreateAsParser().

## ARC_ParserLang_DestroyDataFn()

void ARC_ParserLang_DestroyDataFn | ( | void * | data,
|  | ARC_Bool | clear,
|  | void * | userData )

Definition at line 312 of file parserlang.c.

{
if(userData != NULL){
ARC_Parser_GetStringIdFn *getStringIdFn = (ARC_Parser_GetStringIdFn *)userData;
free(getStringIdFn);
}
//if not clearing (full destroy) check if there is data to free
if(clear == ARC_False && (ARC_Vector *)data != NULL){
ARC_Vector_Destroy((ARC_Vector *)data);
}
}
ARC_False
#define ARC_False
Definition bool.h:12
ARC_Vector_Destroy
void ARC_Vector_Destroy(ARC_Vector *vector)
destroys an ARC_Vector
Definition vector.c:51

References ARC_False, and ARC_Vector_Destroy().

Referenced by ARC_ParserLang_CreateAsParser().

## ARC_ParserLang_InitLexerRulesFn()

void ARC_ParserLang_InitLexerRulesFn | ( | ARC_Lexer * | lexer | ) |

Definition at line 12 of file parserlang.c.

{
//null
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_PARSERLANG_TOKEN_NULL, 0));
//number
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(ARC_PARSERLANG_TOKEN_NUMBER, '0', '9'));
//alpha char
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR, 'a', 'z'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR, 'A', 'Z'));
//whitespace
ARC_String *whitespaceString;
ARC_String_CreateWithStrlen(&whitespaceString, " \t");
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharInStringRule(ARC_LEXER_TOKEN_WHITESPACE, whitespaceString));
ARC_String_Destroy(whitespaceString);
//single char tokens
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_PARSERLANG_TOKEN_NEWLINE_ID , ARC_PARSERLANG_TOKEN_NEWLINE_CHAR ));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_PARSERLANG_TOKEN_LESS_THAN_ID , ARC_PARSERLANG_TOKEN_LESS_THAN_CHAR ));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_PARSERLANG_TOKEN_GREATER_THAN_ID, ARC_PARSERLANG_TOKEN_GREATER_THAN_CHAR));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_PARSERLANG_TOKEN_OR_ID , ARC_PARSERLANG_TOKEN_OR_CHAR ));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_PARSERLANG_TOKEN_UNDERSCORE_ID , ARC_PARSERLANG_TOKEN_UNDERSCORE_CHAR ));
//arrow
ARC_String *arrowString;
ARC_String_CreateWithStrlen(&arrowString, ARC_PARSERLANG_TOKEN_ARROW_CSTRING);
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchStringRule(ARC_PARSERLANG_TOKEN_ARROW_ID, arrowString));
ARC_String_Destroy(arrowString);
}
ARC_LEXER_TOKEN_WHITESPACE
#define ARC_LEXER_TOKEN_WHITESPACE
Definition lexer.h:252
ARC_Lexer_RegisterTokenRule
void ARC_Lexer_RegisterTokenRule(ARC_Lexer *lexer, ARC_LexerTokenRule tokenRule)
adds a token rule to a lexer
Definition lexer.c:79
ARC_LexerTokenRule_CreateAndReturnMatchStringRule
ARC_LexerTokenRule ARC_LexerTokenRule_CreateAndReturnMatchStringRule(uint32_t id, ARC_String *string)
creates a ARC_LexerTokenRule with a given id and string
Definition lexer.c:428
ARC_LexerTokenRule_CreateAndReturnMatchCharRule
ARC_LexerTokenRule ARC_LexerTokenRule_CreateAndReturnMatchCharRule(uint32_t id, char character)
creates a ARC_LexerTokenRule with a given id and character
Definition lexer.c:378
ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween
ARC_LexerTokenRule ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(uint32_t id, char start, char end)
creates a ARC_LexerTokenRule with a given id and character range
Definition lexer.c:400
ARC_LexerTokenRule_CreateAndReturnMatchCharInStringRule
ARC_LexerTokenRule ARC_LexerTokenRule_CreateAndReturnMatchCharInStringRule(uint32_t id, ARC_String *string)
creates a ARC_LexerTokenRule with a given id and string
Definition lexer.c:450
ARC_PARSERLANG_TOKEN_OR_CHAR
#define ARC_PARSERLANG_TOKEN_OR_CHAR
Definition parserlang.h:54
ARC_PARSERLANG_TOKEN_UNDERSCORE_CHAR
#define ARC_PARSERLANG_TOKEN_UNDERSCORE_CHAR
Definition parserlang.h:56
ARC_PARSERLANG_TOKEN_GREATER_THAN_CHAR
#define ARC_PARSERLANG_TOKEN_GREATER_THAN_CHAR
Definition parserlang.h:52
ARC_PARSERLANG_TOKEN_NEWLINE_CHAR
#define ARC_PARSERLANG_TOKEN_NEWLINE_CHAR
Definition parserlang.h:48
ARC_PARSERLANG_TOKEN_NULL
#define ARC_PARSERLANG_TOKEN_NULL
Definition parserlang.h:41
ARC_PARSERLANG_TOKEN_ARROW_CSTRING
#define ARC_PARSERLANG_TOKEN_ARROW_CSTRING
Definition parserlang.h:59
ARC_PARSERLANG_TOKEN_LESS_THAN_CHAR
#define ARC_PARSERLANG_TOKEN_LESS_THAN_CHAR
Definition parserlang.h:50
ARC_String_CreateWithStrlen
void ARC_String_CreateWithStrlen(ARC_String **string, char *data)
creates ARC_String type with strinlen
Definition string.c:32
ARC_String_Destroy
void ARC_String_Destroy(ARC_String *string)
destroys ARC_String type
Definition string.c:52
ARC_String
substring position within a string
Definition string.h:14

References ARC_Lexer_RegisterTokenRule(), ARC_LEXER_TOKEN_WHITESPACE, ARC_LexerTokenRule_CreateAndReturnMatchCharInStringRule(), ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(), ARC_LexerTokenRule_CreateAndReturnMatchCharRule(), ARC_LexerTokenRule_CreateAndReturnMatchStringRule(), ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR, ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR, ARC_PARSERLANG_TOKEN_ARROW_CSTRING, ARC_PARSERLANG_TOKEN_ARROW_ID, ARC_PARSERLANG_TOKEN_GREATER_THAN_CHAR, ARC_PARSERLANG_TOKEN_GREATER_THAN_ID, ARC_PARSERLANG_TOKEN_LESS_THAN_CHAR, ARC_PARSERLANG_TOKEN_LESS_THAN_ID, ARC_PARSERLANG_TOKEN_NEWLINE_CHAR, ARC_PARSERLANG_TOKEN_NEWLINE_ID, ARC_PARSERLANG_TOKEN_NULL, ARC_PARSERLANG_TOKEN_NUMBER, ARC_PARSERLANG_TOKEN_OR_CHAR, ARC_PARSERLANG_TOKEN_OR_ID, ARC_PARSERLANG_TOKEN_UNDERSCORE_CHAR, ARC_PARSERLANG_TOKEN_UNDERSCORE_ID, ARC_String_CreateWithStrlen(), and ARC_String_Destroy().

Referenced by ARC_ParserLang_CreateAsParser().

## ARC_ParserLang_VectorDestroyParserTagFn()

void ARC_ParserLang_VectorDestroyParserTagFn | ( | void * | data | ) |

Definition at line 53 of file parserlang.c.

{
ARC_ParserTag *currentTag = (ARC_ParserTag *)data;
//free the orIndex vlues
for(uint32_t orIndex = 0; orIndex < currentTag->tokensOrTagsSize; orIndex++){
free(currentTag->tokensOrTags[orIndex]);
}
//free the tokens or tags
free(currentTag->tokensOrTags);
//free the tag itself
free(currentTag);
}
ARC_ParserTag::tokensOrTagsSize
uint32_t tokensOrTagsSize
Definition parser.h:25
ARC_ParserTag::tokensOrTags
uint32_t ** tokensOrTags
Definition parser.h:24

References ARC_ParserTag::tokensOrTags, and ARC_ParserTag::tokensOrTagsSize.

Referenced by ARC_ParserLang_CreateDataFn().

## ARC_ParserLang_VectorDestroyUInt32Fn()

void ARC_ParserLang_VectorDestroyUInt32Fn | ( | void * | data | ) |

Definition at line 48 of file parserlang.c.

{
uint32_t *uint = (uint32_t *)data;
free(uint);
}

Referenced by ARC_ParserLangParsedData_CreateBodyTag(), and ARC_ParserLangParsedData_GetArgumentsTag().

## ARC_ParserLang_VectorDestroyVectorFn()

void ARC_ParserLang_VectorDestroyVectorFn | ( | void * | data | ) |

Definition at line 43 of file parserlang.c.

{
ARC_Vector *vector = (ARC_Vector *)data;
ARC_Vector_Destroy(vector);
}

References ARC_Vector_Destroy().

Referenced by ARC_ParserLangParsedData_CreateBodyTag().

## ARC_ParserLangParsedData_CreateBodyTag()

void ARC_ParserLangParsedData_CreateBodyTag | ( | ARC_ParserTag ** | tag,
|  | ARC_ParserTagToken * | tagToken,
|  | ARC_Parser_GetStringIdFn * | getStringIdFn )

Definition at line 196 of file parserlang.c.

{
//create the tag to store the body in
ARC_ParserTag *bodyTag = (ARC_ParserTag *)malloc(sizeof(ARC_ParserTag));
/* ~ Tag Id ~ */
//the first tag will always be the tagId, and as the rule is validated there is no need to check for NULL
ARC_ParserTagToken *tagIdToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, 0);
//get the tagId as a string
ARC_String *tagIdString;
ARC_ParserLangParsedData_CreateTagString(&tagIdString, tagIdToken);
//get the tag id as a uint32_t
bodyTag->tagId = (*getStringIdFn)(tagIdString);
//cleanup the tagIdString
ARC_String_Destroy(tagIdString);
/* ~ Tokens Or Tags Array ~ */
//create a vector to store another vector of data
ARC_Vector *tokensOrTags;
ARC_Vector_DestroyDataFn destroyVectorFn = ARC_ParserLang_VectorDestroyVectorFn;
ARC_Vector_Create(&tokensOrTags, NULL, &destroyVectorFn);
//create vector within the tokens or tags vector to store the or rule in
ARC_Vector *orTokensOrTags;
ARC_Vector_DestroyDataFn destroyUint32Fn = ARC_ParserLang_VectorDestroyUInt32Fn;
ARC_Vector_Create(&orTokensOrTags, NULL, &destroyUint32Fn);
//add the first or vector to the tokensOrTags
ARC_Vector_Add(tokensOrTags, (void *)orTokensOrTags);
//skipping whitespace and arrow tokens, the arguments index starts at 4
ARC_ParserTagToken *argumentsToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, 4);
ARC_ParserLangParsedData_GetArgumentsTag(tokensOrTags, argumentsToken, getStringIdFn);
//initialize the tokens or tags array to the needed size
bodyTag->tokensOrTagsSize = ARC_Vector_GetSize(tokensOrTags);
bodyTag->tokensOrTags = (uint32_t **)malloc(sizeof(uint32_t *) * bodyTag->tokensOrTagsSize);
//copy each or section into the tokensOrTags
for(uint32_t orIndex = 0; orIndex < bodyTag->tokensOrTagsSize; orIndex++){
//get the current or vector and its tags
orTokensOrTags = (ARC_Vector *)ARC_Vector_Get(tokensOrTags, orIndex);
uint32_t orTokensOrTagsSize = ARC_Vector_GetSize(orTokensOrTags);
//create the or array with one extra space and store the size in that space
bodyTag->tokensOrTags[orIndex] = (uint32_t *)malloc(sizeof(uint32_t) * (orTokensOrTagsSize + 1));
bodyTag->tokensOrTags[orIndex][0] = orTokensOrTagsSize;
//copy the or data to the tokensOrTags
for(uint32_t tokenOrTagIndex = 0; tokenOrTagIndex < orTokensOrTagsSize; tokenOrTagIndex++){
bodyTag->tokensOrTags[orIndex][tokenOrTagIndex + 1] = *(uint32_t *)ARC_Vector_Get(orTokensOrTags, tokenOrTagIndex);
}
}
//set the tag to the bodyTag
*tag = bodyTag;
//cleanup
ARC_Vector_Destroy(tokensOrTags);
}
ARC_ParserLangParsedData_CreateTagString
void ARC_ParserLangParsedData_CreateTagString(ARC_String **tagString, ARC_ParserTagToken *tagToken)
Definition parserlang.c:104
ARC_ParserLang_VectorDestroyVectorFn
void ARC_ParserLang_VectorDestroyVectorFn(void *data)
Definition parserlang.c:43
ARC_ParserLangParsedData_GetArgumentsTag
void ARC_ParserLangParsedData_GetArgumentsTag(ARC_Vector *tokensOrTags, ARC_ParserTagToken *tagToken, ARC_Parser_GetStringIdFn *getStringIdFn)
Definition parserlang.c:157
ARC_ParserLang_VectorDestroyUInt32Fn
void ARC_ParserLang_VectorDestroyUInt32Fn(void *data)
Definition parserlang.c:48
ARC_ParserTagToken
a parser type used inside of the parser data create function
Definition parser.h:35
ARC_ParserTag::tagId
uint32_t tagId
Definition parser.h:22
ARC_Vector_GetSize
uint32_t ARC_Vector_GetSize(ARC_Vector *vector)
gets the current size of an ARC_Vector as an unsigned 32 bit integer
Definition vector.c:146
ARC_Vector_Get
void * ARC_Vector_Get(ARC_Vector *vector, uint32_t index)
gets an item from an ARC_Vector at a position index
Definition vector.c:150
ARC_Vector_Add
void ARC_Vector_Add(ARC_Vector *vector, void *data)
adds an item to an ARC_Vector
Definition vector.c:67

References ARC_ParserLang_VectorDestroyUInt32Fn(), ARC_ParserLang_VectorDestroyVectorFn(), ARC_ParserLangParsedData_CreateTagString(), ARC_ParserLangParsedData_GetArgumentsTag(), ARC_String_Destroy(), ARC_Vector_Add(), ARC_Vector_Create(), ARC_Vector_Destroy(), ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_ParserTag::tagId, ARC_ParserTagToken::tagTokens, ARC_ParserTag::tokensOrTags, and ARC_ParserTag::tokensOrTagsSize.

Referenced by ARC_ParserLangParsedData_RunLineTag().

## ARC_ParserLangParsedData_CreateTagString()

void ARC_ParserLangParsedData_CreateTagString | ( | ARC_String ** | tagString,
|  | ARC_ParserTagToken * | tagToken )

Definition at line 104 of file parserlang.c.

{
ARC_String_Create(tagString, NULL, 0);
for(uint32_t index = 0; index < ARC_Vector_GetSize(tagToken->tagTokens); index++){
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, index);
ARC_ParserLangParsedData_RecurseStringAdd(tagString, childTagToken);
}
}
ARC_ParserLangParsedData_RecurseStringAdd
void ARC_ParserLangParsedData_RecurseStringAdd(ARC_String **data, ARC_ParserTagToken *tagToken)
Definition parserlang.c:68
ARC_String_Create
void ARC_String_Create(ARC_String **string, char *data, uint64_t length)
creates ARC_String type
Definition string.c:9

References ARC_ParserLangParsedData_RecurseStringAdd(), ARC_String_Create(), ARC_Vector_Get(), ARC_Vector_GetSize(), and ARC_ParserTagToken::tagTokens.

Referenced by ARC_ParserLangParsedData_CreateBodyTag().

## ARC_ParserLangParsedData_GetArgumentsTag()

void ARC_ParserLangParsedData_GetArgumentsTag | ( | ARC_Vector * | tokensOrTags,
|  | ARC_ParserTagToken * | tagToken,
|  | ARC_Parser_GetStringIdFn * | getStringIdFn )

Definition at line 157 of file parserlang.c.

{
for(uint32_t index = 0; index < ARC_Vector_GetSize(tagToken->tagTokens); index++){
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, index);
//switch variables
uint32_t tokensOrTagsIndex = 0;
ARC_Vector *orTokensOrTags = NULL;
ARC_Vector_DestroyDataFn destroyUint32Fn = ARC_ParserLang_VectorDestroyUInt32Fn;
switch(childTagToken->id){
case ARC_PARSERLANG_ARGUMENT:
//get the last vector within tokens or tags to add the tag/constant to
tokensOrTagsIndex = ARC_Vector_GetSize(tokensOrTags);
orTokensOrTags = (ARC_Vector *)ARC_Vector_Get(tokensOrTags, tokensOrTagsIndex - 1);
ARC_ParserLangParsedData_GetArgumentTag(orTokensOrTags, childTagToken, getStringIdFn);
continue;
case ARC_PARSERLANG_TOKEN_OR_ID:
//add a new vector to tagsOrTokens for the or statment
ARC_Vector_Create(&orTokensOrTags, NULL, &destroyUint32Fn);
//add the first or vector to the tokensOrTags
ARC_Vector_Add(tokensOrTags, (void *)orTokensOrTags);
continue;
case ARC_PARSERLANG_ARGUMENTS:
//recurse to check all the arguments
ARC_ParserLangParsedData_GetArgumentsTag(tokensOrTags, childTagToken, getStringIdFn);
continue;
default:
//this should only be whitespace
continue;
}
}
}
ARC_ParserLangParsedData_GetArgumentTag
void ARC_ParserLangParsedData_GetArgumentTag(ARC_Vector *orTokensOrTags, ARC_ParserTagToken *tagToken, ARC_Parser_GetStringIdFn *getStringIdFn)
Definition parserlang.c:117
ARC_ParserTagToken::id
uint32_t id
Definition parser.h:36

References ARC_PARSERLANG_ARGUMENT, ARC_PARSERLANG_ARGUMENTS, ARC_PARSERLANG_TOKEN_OR_ID, ARC_ParserLang_VectorDestroyUInt32Fn(), ARC_ParserLangParsedData_GetArgumentsTag(), ARC_ParserLangParsedData_GetArgumentTag(), ARC_Vector_Add(), ARC_Vector_Create(), ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_ParserTagToken::id, and ARC_ParserTagToken::tagTokens.

Referenced by ARC_ParserLangParsedData_CreateBodyTag(), and ARC_ParserLangParsedData_GetArgumentsTag().

## ARC_ParserLangParsedData_GetArgumentTag()

void ARC_ParserLangParsedData_GetArgumentTag | ( | ARC_Vector * | orTokensOrTags,
|  | ARC_ParserTagToken * | tagToken,
|  | ARC_Parser_GetStringIdFn * | getStringIdFn )

Definition at line 117 of file parserlang.c.

{
for(uint32_t index = 0; index < ARC_Vector_GetSize(tagToken->tagTokens); index++){
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, index);
//switch variables
ARC_String *tagOrConstantString = NULL;
uint32_t *id = NULL;
switch(childTagToken->id){
case ARC_PARSERLANG_ARGUMENT:
//recurse to check all the arguments
ARC_ParserLangParsedData_GetArgumentTag(orTokensOrTags, childTagToken, getStringIdFn);
continue;
case ARC_PARSERLANG_TAG_OR_CONSTANT:
//initialize the string to use
ARC_String_Create(&tagOrConstantString, NULL, 0);
//get the id of the tag/constant
ARC_ParserLangParsedData_RecurseStringAdd(&tagOrConstantString, childTagToken);
id = (uint32_t *)malloc(sizeof(uint32_t));
*id = (*getStringIdFn)(tagOrConstantString);
//add the id to the matching or vector
ARC_Vector_Add(orTokensOrTags, (void *)id);
//cleanup
ARC_String_Destroy(tagOrConstantString);
continue;
default:
//this should only be whitespace
continue;
}
}
}

References ARC_PARSERLANG_ARGUMENT, ARC_PARSERLANG_TAG_OR_CONSTANT, ARC_ParserLangParsedData_GetArgumentTag(), ARC_ParserLangParsedData_RecurseStringAdd(), ARC_String_Create(), ARC_String_Destroy(), ARC_Vector_Add(), ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_ParserTagToken::id, and ARC_ParserTagToken::tagTokens.

Referenced by ARC_ParserLangParsedData_GetArgumentsTag(), and ARC_ParserLangParsedData_GetArgumentTag().

## ARC_ParserLangParsedData_RecurseStringAdd()

void ARC_ParserLangParsedData_RecurseStringAdd | ( | ARC_String ** | data,
|  | ARC_ParserTagToken * | tagToken )

Definition at line 68 of file parserlang.c.

{
if(tagToken->token != NULL){
//less than rule does not have a string so add it manually and return
if(tagToken->token->rule == ARC_PARSERLANG_TOKEN_LESS_THAN_ID){
char tokenChar = ARC_PARSERLANG_TOKEN_LESS_THAN_CHAR;
ARC_String_AppendCString(data, &tokenChar, 1);
return;
}
//greater than rule does not have a string so add it manually and return
if(tagToken->token->rule == ARC_PARSERLANG_TOKEN_GREATER_THAN_ID){
char tokenChar = ARC_PARSERLANG_TOKEN_GREATER_THAN_CHAR;
ARC_String_AppendCString(data, &tokenChar, 1);
return;
}
if(tagToken->token->rule == ARC_PARSERLANG_TOKEN_UNDERSCORE_ID){
char tokenChar = ARC_PARSERLANG_TOKEN_UNDERSCORE_CHAR;
ARC_String_AppendCString(data, &tokenChar, 1);
return;
}
ARC_String_Append(data, tagToken->token->data);
return;
}
//TODO: probs don't need this
if(tagToken->tagTokens == NULL){
return;
}
for(uint32_t index = 0; index < ARC_Vector_GetSize(tagToken->tagTokens); index++){
ARC_ParserLangParsedData_RecurseStringAdd(data, (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, index));
}
}
ARC_String_AppendCString
void ARC_String_AppendCString(ARC_String **string, const char *cstring, uint64_t length)
appends to an ARC_String with an ARC_String
Definition string.c:130
ARC_String_Append
void ARC_String_Append(ARC_String **string, ARC_String *append)
appends to an ARC_String with an ARC_String
Definition string.c:126
ARC_LexerToken::rule
uint32_t rule
Definition lexer.h:19
ARC_LexerToken::data
ARC_String * data
Definition lexer.h:20
ARC_ParserTagToken::token
ARC_LexerToken * token
Definition parser.h:38

References ARC_PARSERLANG_TOKEN_GREATER_THAN_CHAR, ARC_PARSERLANG_TOKEN_GREATER_THAN_ID, ARC_PARSERLANG_TOKEN_LESS_THAN_CHAR, ARC_PARSERLANG_TOKEN_LESS_THAN_ID, ARC_PARSERLANG_TOKEN_UNDERSCORE_CHAR, ARC_PARSERLANG_TOKEN_UNDERSCORE_ID, ARC_ParserLangParsedData_RecurseStringAdd(), ARC_String_Append(), ARC_String_AppendCString(), ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_LexerToken::data, ARC_LexerToken::rule, ARC_ParserTagToken::tagTokens, and ARC_ParserTagToken::token.

Referenced by ARC_ParserLangParsedData_CreateTagString(), ARC_ParserLangParsedData_GetArgumentTag(), and ARC_ParserLangParsedData_RecurseStringAdd().

## ARC_ParserLangParsedData_RunLineTag()

void ARC_ParserLangParsedData_RunLineTag | ( | ARC_Vector * | tags,
|  | ARC_ParserTagToken * | tagToken,
|  | ARC_Parser_GetStringIdFn * | getStringIdFn )

Definition at line 259 of file parserlang.c.

{
//loop through the tags either going to the next line or the next body
for(uint32_t index = 0; index < ARC_Vector_GetSize(tagToken->tagTokens); index++){
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(tagToken->tagTokens, index);
//for some reason can't create this in the switch, so placed here
ARC_ParserTag *tag;
switch(childTagToken->id){
//recuse to run the next line
case ARC_PARSERLANG_LINE:
ARC_ParserLangParsedData_RunLineTag(tags, childTagToken, getStringIdFn);
continue;
//get a tag
case ARC_PARSERLANG_BODY:
ARC_ParserLangParsedData_CreateBodyTag(&tag, childTagToken, getStringIdFn);
ARC_Vector_Add(tags, (void *)tag);
continue;
default:
continue;
}
}
}
ARC_ParserLangParsedData_CreateBodyTag
void ARC_ParserLangParsedData_CreateBodyTag(ARC_ParserTag **tag, ARC_ParserTagToken *tagToken, ARC_Parser_GetStringIdFn *getStringIdFn)
Definition parserlang.c:196

References ARC_PARSERLANG_BODY, ARC_PARSERLANG_LINE, ARC_ParserLangParsedData_CreateBodyTag(), ARC_ParserLangParsedData_RunLineTag(), ARC_Vector_Add(), ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_ParserTagToken::id, and ARC_ParserTagToken::tagTokens.

Referenced by ARC_ParserLang_CreateDataFn(), and ARC_ParserLangParsedData_RunLineTag().