|
Archeus 0.0.0
A C library and game engine that focuses on documentation
|
#include "arc/std/lexer.h"#include "arc/std/bool.h"#include "arc/std/errno.h"#include "arc/std/string.h"#include "arc/std/vector.h"#include "arc/std/io.h"#include <stdlib.h>Go to the source code of this file.
Data Structures | |
| struct | ARC_Lexer |
Functions | |
| ARC_Bool | ARC_LexerTokenRule_VectorCompareDataFn (void *dataA, void *dataB) |
| void | ARC_LexerTokenRule_VectorDestroyDataFn (void *data) |
| void | ARC_LexerToken_VectorDestroyDataFn (void *data) |
| void | ARC_Lexer_Create (ARC_Lexer **lexer) |
| creates an ARC_Lexer type | |
| void | ARC_Lexer_Destroy (ARC_Lexer *lexer) |
| destroys an ARC_Lexer type | |
| void | ARC_Lexer_RegisterTokenRule (ARC_Lexer *lexer, ARC_LexerTokenRule tokenRule) |
| adds a token rule to a lexer | |
| void | ARC_Lexer_Clear (ARC_Lexer *lexer) |
| clears all tokens from a lexer (will not clear token rules) | |
| void | ARC_Lexer_LexString (ARC_Lexer *lexer, ARC_String **data) |
| creates tokens using a given string with ARC_LexerToken rules | |
| void | ARC_Lexer_LexFile (ARC_Lexer *lexer, ARC_String *path) |
| reads in and lexs a file | |
| void | ARC_Lexer_PrintTokenRules (ARC_Lexer *lexer) |
| prints rule id and hex of the function name | |
| ARC_LexerToken * | ARC_Lexer_GetToken (ARC_Lexer *lexer, uint32_t index) |
| gets a token at a given index from a lexer | |
| uint32_t | ARC_Lexer_GetTokensSize (ARC_Lexer *lexer) |
| gets a token at a given index from a lexer | |
| ARC_Bool | ARC_Lexer_IsContinious (ARC_Lexer *lexer) |
| returns a boolean based on if a lexers rules are continious | |
| ARC_Bool | ARC_Lexer_IsTokenId (ARC_Lexer *lexer, uint32_t id) |
| returns a boolean based on if a given id is a stored token rule id | |
| uint32_t | ARC_Lexer_AutomataMatchCharFn (ARC_String **tokenData, ARC_String *string, void *automataData) |
| checks if the first character of string matches the automataData cast as a char | |
| uint32_t | ARC_Lexer_AutomataMatchCharOrBetweenFn (ARC_String **tokenData, ARC_String *string, void *automataData) |
| uint32_t | ARC_Lexer_AutomataMatchStringFn (ARC_String **tokenData, ARC_String *string, void *automataData) |
| checks if the substring automataData as an ARC_String matches the first part of string | |
| uint32_t | ARC_Lexer_AutomataMatchCharInStringFn (ARC_String **tokenData, ARC_String *string, void *automataData) |
| checks if the first part of string is a character in substring | |
| void | ARC_LexerTokenRule_DestroyCharAutomataDataFn (void *automataData) |
| ARC_LexerTokenRule | ARC_LexerTokenRule_CreateAndReturnMatchCharRule (uint32_t id, char character) |
| creates a ARC_LexerTokenRule with a given id and character | |
| ARC_LexerTokenRule | ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween (uint32_t id, char start, char end) |
| creates a ARC_LexerTokenRule with a given id and character range | |
| void | ARC_LexerTokenRule_DestroyStringAutomataDataFn (void *automataData) |
| ARC_LexerTokenRule | ARC_LexerTokenRule_CreateAndReturnMatchStringRule (uint32_t id, ARC_String *string) |
| creates a ARC_LexerTokenRule with a given id and string | |
| ARC_LexerTokenRule | ARC_LexerTokenRule_CreateAndReturnMatchCharInStringRule (uint32_t id, ARC_String *string) |
| creates a ARC_LexerTokenRule with a given id and string | |
| void | ARC_Lexer_InitBasicTokenRules (ARC_Lexer *lexer) |
| adds a bunch of basic token rules (matching the BasicTokens above) | |
| uint32_t ARC_Lexer_AutomataMatchCharFn | ( | ARC_String ** | tokenData, |
| ARC_String * | string, | ||
| void * | automataData ) |
checks if the first character of string matches the automataData cast as a char
| [out] | tokenData | a place to store token data (like a variable name), can be NULL if not needed |
| [in] | string | a string to be checked to see if it matches a token |
| [in] | automataData | any data that needs to be used for the ARC_Lexer_AutomataFn |
Definition at line 311 of file lexer.c.
References ARC_String::data.
Referenced by ARC_LexerTokenRule_CreateAndReturnMatchCharRule().
| uint32_t ARC_Lexer_AutomataMatchCharInStringFn | ( | ARC_String ** | tokenData, |
| ARC_String * | string, | ||
| void * | automataData ) |
checks if the first part of string is a character in substring
| [out] | tokenData | a place to store token data (like a variable name), can be NULL if not needed |
| [in] | string | a string to be checked to see if it matches a token |
| [in] | automataData | any data that needs to be used for the ARC_Lexer_AutomataFn |
Definition at line 356 of file lexer.c.
References ARC_String::data, and ARC_String::length.
Referenced by ARC_LexerTokenRule_CreateAndReturnMatchCharInStringRule().
| uint32_t ARC_Lexer_AutomataMatchCharOrBetweenFn | ( | ARC_String ** | tokenData, |
| ARC_String * | string, | ||
| void * | automataData ) |
Definition at line 325 of file lexer.c.
References ARC_String_Create(), and ARC_String::data.
Referenced by ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween().
| uint32_t ARC_Lexer_AutomataMatchStringFn | ( | ARC_String ** | tokenData, |
| ARC_String * | string, | ||
| void * | automataData ) |
checks if the substring automataData as an ARC_String matches the first part of string
| [out] | tokenData | a place to store token data (like a variable name), can be NULL if not needed |
| [in] | string | a string to be checked to see if it matches a token |
| [in] | automataData | any data that needs to be used for the ARC_Lexer_AutomataFn |
Definition at line 341 of file lexer.c.
References ARC_String_SubstringEquals(), and ARC_String::length.
Referenced by ARC_LexerTokenRule_CreateAndReturnMatchStringRule().
| void ARC_Lexer_Clear | ( | ARC_Lexer * | lexer | ) |
clears all tokens from a lexer (will not clear token rules)
| lexer | the lexer to clear tokens from |
Definition at line 161 of file lexer.c.
References ARC_Vector_Clear(), and ARC_Lexer::tokens.
Referenced by ARC_Parser_Parse().
| void ARC_Lexer_Create | ( | ARC_Lexer ** | lexer | ) |
creates an ARC_Lexer type
| [out] | lexer | ARC_Lexer to create |
Definition at line 50 of file lexer.c.
References ARC_LexerToken_VectorDestroyDataFn(), ARC_LexerTokenRule_VectorCompareDataFn(), ARC_LexerTokenRule_VectorDestroyDataFn(), ARC_True, and ARC_Vector_Create().
Referenced by ARC_Parser_Create(), ARC_TEST(), ARC_TEST(), ARC_TEST(), ARC_TEST(), ARC_TEST(), and ARC_TEST().
| void ARC_Lexer_Destroy | ( | ARC_Lexer * | lexer | ) |
destroys an ARC_Lexer type
| [in] | lexer | ARC_Lexer to free |
Definition at line 68 of file lexer.c.
References ARC_Vector_Destroy(), ARC_Lexer::tokenRules, and ARC_Lexer::tokens.
Referenced by ARC_Parser_Destroy(), ARC_TEST(), ARC_TEST(), ARC_TEST(), ARC_TEST(), ARC_TEST(), and ARC_TEST().
| ARC_LexerToken * ARC_Lexer_GetToken | ( | ARC_Lexer * | lexer, |
| uint32_t | index ) |
gets a token at a given index from a lexer
| [in] | lexer | the lexer to get the token from |
| [in] | index | the index of the token in the lexer to get |
Definition at line 272 of file lexer.c.
References ARC_DEBUG_LOG_ERROR, arc_errno, ARC_Vector_Get(), and ARC_Lexer::tokens.
Referenced by ARC_Parser_ParseTag(), and ARC_TEST().
| uint32_t ARC_Lexer_GetTokensSize | ( | ARC_Lexer * | lexer | ) |
gets a token at a given index from a lexer
| [in] | lexer | the lexer to get the tokens size from |
Definition at line 286 of file lexer.c.
References ARC_Vector_GetSize(), and ARC_Lexer::tokens.
Referenced by ARC_Parser_Parse(), and ARC_Parser_ParseTag().
| void ARC_Lexer_InitBasicTokenRules | ( | ARC_Lexer * | lexer | ) |
adds a bunch of basic token rules (matching the BasicTokens above)
Definition at line 472 of file lexer.c.
References ARC_Lexer_RegisterTokenRule(), ARC_LEXER_TOKEN_ALPHA_LOWER_CHAR, ARC_LEXER_TOKEN_ALPHA_UPPER_CHAR, ARC_LEXER_TOKEN_AT_CHAR, ARC_LEXER_TOKEN_AT_ID, ARC_LEXER_TOKEN_BACK_SLASH_CHAR, ARC_LEXER_TOKEN_BACK_SLASH_ID, ARC_LEXER_TOKEN_BANG_CHAR, ARC_LEXER_TOKEN_BANG_ID, ARC_LEXER_TOKEN_COLON_CHAR, ARC_LEXER_TOKEN_COLON_ID, ARC_LEXER_TOKEN_COMMA_CHAR, ARC_LEXER_TOKEN_COMMA_ID, ARC_LEXER_TOKEN_FORWARD_SLASH_CHAR, ARC_LEXER_TOKEN_FORWARD_SLASH_ID, ARC_LEXER_TOKEN_HASH_CHAR, ARC_LEXER_TOKEN_HASH_ID, ARC_LEXER_TOKEN_LEFT_CURLY_BRACE_CHAR, ARC_LEXER_TOKEN_LEFT_CURLY_BRACE_ID, ARC_LEXER_TOKEN_LEFT_PARENTHESIS_CHAR, ARC_LEXER_TOKEN_LEFT_PARENTHESIS_ID, ARC_LEXER_TOKEN_NEWLINE_CHAR, ARC_LEXER_TOKEN_NEWLINE_ID, ARC_LEXER_TOKEN_NULL, ARC_LEXER_TOKEN_NUMBER, ARC_LEXER_TOKEN_PERCENT_CHAR, ARC_LEXER_TOKEN_PERCENT_ID, ARC_LEXER_TOKEN_PERIOD_CHAR, ARC_LEXER_TOKEN_PERIOD_ID, ARC_LEXER_TOKEN_RIGHT_CURLY_BRACE_CHAR, ARC_LEXER_TOKEN_RIGHT_CURLY_BRACE_ID, ARC_LEXER_TOKEN_RIGHT_PARENTHESIS_CHAR, ARC_LEXER_TOKEN_RIGHT_PARENTHESIS_ID, ARC_LEXER_TOKEN_SEMICOLON_CHAR, ARC_LEXER_TOKEN_SEMICOLON_ID, ARC_LEXER_TOKEN_WHITESPACE, ARC_LexerTokenRule_CreateAndReturnMatchCharInStringRule(), ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(), ARC_LexerTokenRule_CreateAndReturnMatchCharRule(), ARC_String_CreateWithStrlen(), and ARC_String_Destroy().
Referenced by ARC_TEST(), and TEST_Parser_InitLexerRulesFn().
returns a boolean based on if a lexers rules are continious
| [in] | lexer | the lexer to check if its ruls are continious |
Definition at line 290 of file lexer.c.
References ARC_Lexer::tokenRulesAreContinuous.
Referenced by ARC_TEST(), and ARC_TEST().
returns a boolean based on if a given id is a stored token rule id
| [in] | lexer | the lexer to check stored token rule ids |
| [in] | id | the id to check against the token rules |
Definition at line 294 of file lexer.c.
References ARC_False, ARC_True, ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_LexerTokenRule::id, ARC_Lexer::tokenRules, ARC_Lexer::tokenRulesAreContinuous, and ARC_Lexer::tokenRulesMaxVal.
Referenced by ARC_Parser_ParseTag(), ARC_TEST(), ARC_TEST(), and ARC_TEST().
| void ARC_Lexer_LexFile | ( | ARC_Lexer * | lexer, |
| ARC_String * | path ) |
reads in and lexs a file
| [in] | lexer | the lexer which holds to rules to use |
| [in] | path | path of file to read in and lex |
Definition at line 245 of file lexer.c.
References ARC_DEBUG_LOG_ERROR, arc_errno, ARC_IO_FileToStr(), ARC_Lexer_LexString(), and ARC_String_Destroy().
| void ARC_Lexer_LexString | ( | ARC_Lexer * | lexer, |
| ARC_String ** | data ) |
creates tokens using a given string with ARC_LexerToken rules
| [in] | lexer | the lexer to get the ARC_LexerTokens from |
| [in/out] | data the string to lex, will be freed and set to NULL by the end of this function |
Definition at line 166 of file lexer.c.
References ARC_DEBUG_LOG_ERROR, ARC_DEBUG_LOG_ERROR_WITH_VARIABLES, arc_errno, ARC_ERRNO_DATA, ARC_LexerToken_VectorDestroyDataFn(), ARC_String_Destroy(), ARC_String_ReplaceWithSubstring(), ARC_Vector_Add(), ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_LexerTokenRule::automataData, ARC_LexerTokenRule::automataFn, ARC_LexerToken::data, ARC_LexerTokenRule::id, ARC_String::length, ARC_LexerToken::rule, ARC_Lexer::tokenRules, and ARC_Lexer::tokens.
Referenced by ARC_Lexer_LexFile(), ARC_Parser_Parse(), and ARC_TEST().
| void ARC_Lexer_PrintTokenRules | ( | ARC_Lexer * | lexer | ) |
prints rule id and hex of the function name
| [in] | lexer | the lexer to print rules from |
Definition at line 265 of file lexer.c.
References ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_LexerTokenRule::automataFn, ARC_LexerTokenRule::id, and ARC_Lexer::tokenRules.
| void ARC_Lexer_RegisterTokenRule | ( | ARC_Lexer * | lexer, |
| ARC_LexerTokenRule | tokenRule ) |
adds a token rule to a lexer
| [in] | lexer | the lexer to add a token rule to |
| [in] | tokenRule | the token rule to add |
Definition at line 79 of file lexer.c.
References ARC_Bool, ARC_DEBUG_LOG_ERROR, arc_errno, ARC_False, ARC_True, ARC_Vector_Add(), ARC_Vector_Get(), ARC_Vector_GetSize(), ARC_LexerTokenRule::id, ARC_Lexer::tokenRules, ARC_Lexer::tokenRulesAreContinuous, and ARC_Lexer::tokenRulesMaxVal.
Referenced by ARC_Lexer_InitBasicTokenRules(), ARC_ParserCSV_InitLexerRulesFn(), ARC_ParserLang_InitLexerRulesFn(), ARC_TEST(), ARC_TEST(), ARC_TEST(), ARC_TEST(), ARC_TEST(), and TEST_Parser_InitBasicLexerTokenRules().
| void ARC_LexerToken_VectorDestroyDataFn | ( | void * | data | ) |
Definition at line 39 of file lexer.c.
References ARC_String_Destroy(), and ARC_LexerToken::data.
Referenced by ARC_Lexer_Create(), and ARC_Lexer_LexString().
| ARC_LexerTokenRule ARC_LexerTokenRule_CreateAndReturnMatchCharInStringRule | ( | uint32_t | id, |
| ARC_String * | string ) |
creates a ARC_LexerTokenRule with a given id and string
| [in] | id | a tokens id (basically the token value) |
| [in] | character | the string to match against, will be copied |
Definition at line 450 of file lexer.c.
References ARC_Lexer_AutomataMatchCharInStringFn(), ARC_LexerTokenRule_DestroyStringAutomataDataFn(), ARC_String_Copy(), ARC_LexerTokenRule::automataData, ARC_LexerTokenRule::automataFn, ARC_LexerTokenRule::destroyAutomataDataFn, and ARC_LexerTokenRule::id.
Referenced by ARC_Lexer_InitBasicTokenRules(), and ARC_ParserLang_InitLexerRulesFn().
| ARC_LexerTokenRule ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween | ( | uint32_t | id, |
| char | start, | ||
| char | end ) |
creates a ARC_LexerTokenRule with a given id and character range
| [in] | id | a tokens id (basically the token value) |
| [in] | start | the minimum character value to match against |
| [in] | end | the maxamum character value to match against |
Definition at line 400 of file lexer.c.
References ARC_Lexer_AutomataMatchCharOrBetweenFn(), ARC_LexerTokenRule_DestroyCharAutomataDataFn(), ARC_LexerTokenRule::automataData, ARC_LexerTokenRule::automataFn, ARC_LexerTokenRule::destroyAutomataDataFn, and ARC_LexerTokenRule::id.
Referenced by ARC_Lexer_InitBasicTokenRules(), ARC_ParserCSV_InitLexerRulesFn(), ARC_ParserLang_InitLexerRulesFn(), and TEST_Parser_InitBasicLexerTokenRules().
| ARC_LexerTokenRule ARC_LexerTokenRule_CreateAndReturnMatchCharRule | ( | uint32_t | id, |
| char | character ) |
creates a ARC_LexerTokenRule with a given id and character
| [in] | id | a tokens id (basically the token value) |
| [in] | character | the character to match against |
Definition at line 378 of file lexer.c.
References ARC_Lexer_AutomataMatchCharFn(), ARC_LexerTokenRule_DestroyCharAutomataDataFn(), ARC_LexerTokenRule::automataData, ARC_LexerTokenRule::automataFn, ARC_LexerTokenRule::destroyAutomataDataFn, and ARC_LexerTokenRule::id.
Referenced by ARC_Lexer_InitBasicTokenRules(), ARC_ParserCSV_InitLexerRulesFn(), ARC_ParserLang_InitLexerRulesFn(), ARC_TEST(), ARC_TEST(), ARC_TEST(), ARC_TEST(), ARC_TEST(), and TEST_Parser_InitBasicLexerTokenRules().
| ARC_LexerTokenRule ARC_LexerTokenRule_CreateAndReturnMatchStringRule | ( | uint32_t | id, |
| ARC_String * | string ) |
creates a ARC_LexerTokenRule with a given id and string
| [in] | id | a tokens id (basically the token value) |
| [in] | character | the string to match against, will be copied |
Definition at line 428 of file lexer.c.
References ARC_Lexer_AutomataMatchStringFn(), ARC_LexerTokenRule_DestroyStringAutomataDataFn(), ARC_String_Copy(), ARC_LexerTokenRule::automataData, ARC_LexerTokenRule::automataFn, ARC_LexerTokenRule::destroyAutomataDataFn, and ARC_LexerTokenRule::id.
Referenced by ARC_ParserLang_InitLexerRulesFn().
| void ARC_LexerTokenRule_DestroyCharAutomataDataFn | ( | void * | automataData | ) |
Definition at line 374 of file lexer.c.
Referenced by ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(), and ARC_LexerTokenRule_CreateAndReturnMatchCharRule().
| void ARC_LexerTokenRule_DestroyStringAutomataDataFn | ( | void * | automataData | ) |
Definition at line 424 of file lexer.c.
References ARC_String_Destroy().
Referenced by ARC_LexerTokenRule_CreateAndReturnMatchCharInStringRule(), and ARC_LexerTokenRule_CreateAndReturnMatchStringRule().
| ARC_Bool ARC_LexerTokenRule_VectorCompareDataFn | ( | void * | dataA, |
| void * | dataB ) |
Definition at line 20 of file lexer.c.
References ARC_False, ARC_True, and ARC_LexerTokenRule::id.
Referenced by ARC_Lexer_Create().
| void ARC_LexerTokenRule_VectorDestroyDataFn | ( | void * | data | ) |
Definition at line 32 of file lexer.c.
References ARC_LexerTokenRule::automataData, and ARC_LexerTokenRule::destroyAutomataDataFn.
Referenced by ARC_Lexer_Create().