Archeus 0.0.0
A C library and game engine that focuses on documentation
Loading...
Searching...
No Matches
parser.h
Go to the documentation of this file.
1#ifndef ARC_STD_PARSER_H_
2#define ARC_STD_PARSER_H_
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include "arc/std/array.h"
9#include "arc/std/lexer.h"
10#include "arc/std/vector.h"
11#include <stdint.h>
12
13/**
14 * @brief a parser type
15*/
16typedef struct ARC_Parser ARC_Parser;
17
18/**
19 * @brief a langue tag type for the parser //TODO: explain this better
20*/
21typedef struct ARC_ParserTag {
22 uint32_t tagId;
23
24 uint32_t **tokensOrTags;
27
28/**
29 * @brief a parser type used inside of the parser data create function
30 *
31 * @note there are no public creation and destruction functions for this type as it is only ment to be used within the creation callback
32 * @note if the parser tag token is a token then tagTokens will be NULL
33 * @note if the parser tag token is a tag then token will be NULL
34*/
41
42/**
43 * @brief a callback function to initialize the lexer the parser uses with rules
44 *
45 * @param lexer the lexer used by the parser that rules should be added to
46*/
47typedef void (* ARC_Parser_InitLexerRulesFn)(ARC_Lexer *lexer);
48
49/**
50 * @brief TODO: write this
51*/
52typedef uint32_t (* ARC_Parser_GetStringIdFn)(ARC_String *string);
53
54/**
55 * @brief TODO: write this
56*/
57typedef void (* ARC_ParserData_CreateFn)(void **data, ARC_ParserTagToken *parsedData, void *userData);
58
59/**
60 * @brief TODO: write this
61*/
62typedef void (* ARC_ParserData_DestroyFn)(void *data, ARC_Bool clear, void *userData);
63
64/**
65 * @brief creates an ARC_Parser type
66 *
67 * @TODO: fix this documentation to reflect changes
68 *
69 * @TODO: probs want to move the note to another file
70 * @note array of tokens for langauge? like
71 * ARC_ParserTag tag = {
72 * VARIABLE_NAME, //tagId
73 * {
74 * { 2, CHAR_OR_NUM, VARIABLE_NAME },
75 * { 1, LAMBDA },
76 * }, //components
77 * 2 //componentsSize
78 * };
79 *
80 * @param[out] parser ARC_Parser to create
81 * @param[in] language an arry of ARC_ParserLanguageTags defining a langauge
82 * @param[in] initLexerRulesFn a callback used to initalize the token rules the lexer within the parser will use
83*/
84void ARC_Parser_Create(ARC_Parser **parser, ARC_Array *language, ARC_Parser_InitLexerRulesFn initLexerRulesFn, ARC_ParserData_CreateFn *createDataFn, ARC_ParserData_DestroyFn *destroyDataFn, void *userData);
85
86/**
87 * @brief creates an ARC_Parser type from an arc vector
88 *
89 * @param[out] parser ARC_Parser to create
90 * @param[in] language an vector of ARC_ParserLanguageTags defining a langauge
91 * @param[in] initLexerRulesFn a callback used to initalize the token rules the lexer within the parser will use
92*/
93void ARC_Parser_CreateFromVector(ARC_Parser **parser, ARC_Vector *language, ARC_Parser_InitLexerRulesFn initLexerRulesFn, ARC_ParserData_CreateFn *createDataFn, ARC_ParserData_DestroyFn *destroyDataFn, void *userData);
94
95/**
96 * @brief creates an ARC_Parser type from a string
97 *
98 * @TODO: probs want to move the note to another file
99 * @note the syntax looks like:
100 * <variable> -> CHAR <variableName> EOF
101 * <variableName> -> <charOrNum> <variableName> | LAMBDA
102 * <charOrNum> -> CHAR | NUM
103 *
104 * @param[out] parser ARC_Parser to create
105 * @param[in] language an arry of ARC_ParserLanguageTags defining a langauge
106 * @param[in] initLexerRulesFn a callback used to initalize the token rules the lexer within the parser will use
107*/
108void ARC_Parser_CreateFromString(ARC_Parser **parser, ARC_String *languageString, ARC_Parser_InitLexerRulesFn initLexerRulesFn, ARC_Parser_GetStringIdFn getStringIdFn, ARC_ParserData_CreateFn *createDataFn, ARC_ParserData_DestroyFn *destroyDataFn, void *userData);
109
110/**
111 * @brief destroys an ARC_Parser type
112 *
113 * @param[in] parser ARC_Parser to free
114*/
116
117/**
118 * @brief
119 *
120 * @param[in] parser
121 * @param[in/out] data the string to parse, will be freed and set to NULL by the end of this function
122*/
124
125/**
126 * @brief
127 *
128 * @param[in] parser
129 * @param[in] language
130*/
132
133/**
134 * @brief
135 *
136 * @param[in] parser
137*/
139
140/**
141 * @brief
142 *
143 * @param[in] parser
144*/
146
147/**
148 * @brief basic tag for letting the parser know it is ok to end
149*/
150#define ARC_PARSER_TAG_LAMBDA 0
151
152#ifdef __cplusplus
153}
154#endif
155
156#endif // !ARC_STD_PARSER_H_
#define ARC_Bool
Definition bool.h:10
struct ARC_Vector ARC_Vector
a dynamic array type
Definition vector.h:26
struct ARC_Lexer ARC_Lexer
a lexer type
Definition lexer.h:13
void ARC_Parser_CreateFromString(ARC_Parser **parser, ARC_String *languageString, ARC_Parser_InitLexerRulesFn initLexerRulesFn, ARC_Parser_GetStringIdFn getStringIdFn, ARC_ParserData_CreateFn *createDataFn, ARC_ParserData_DestroyFn *destroyDataFn, void *userData)
creates an ARC_Parser type from a string
void ARC_Parser_ParseFile(ARC_Parser *parser, ARC_String *path)
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
uint32_t(* ARC_Parser_GetStringIdFn)(ARC_String *string)
TODO: write this.
Definition parser.h:52
void(* ARC_Parser_InitLexerRulesFn)(ARC_Lexer *lexer)
a callback function to initialize the lexer the parser uses with rules
Definition parser.h:47
void(* ARC_ParserData_CreateFn)(void **data, ARC_ParserTagToken *parsedData, void *userData)
TODO: write this.
Definition parser.h:57
struct ARC_ParserTag ARC_ParserTag
a langue tag type for the parser //TODO: explain this better
void(* ARC_ParserData_DestroyFn)(void *data, ARC_Bool clear, void *userData)
TODO: write this.
Definition parser.h:62
void ARC_Parser_Parse(ARC_Parser *parser, ARC_String **data)
void ARC_Parser_CreateFromVector(ARC_Parser **parser, ARC_Vector *language, ARC_Parser_InitLexerRulesFn initLexerRulesFn, ARC_ParserData_CreateFn *createDataFn, ARC_ParserData_DestroyFn *destroyDataFn, void *userData)
creates an ARC_Parser type from an arc vector
void ARC_Parser_Destroy(ARC_Parser *parser)
destroys an ARC_Parser type
void ARC_Parser_ClearData(ARC_Parser *parser)
void * ARC_Parser_GetData(ARC_Parser *parser)
struct ARC_Parser ARC_Parser
a parser type
Definition parser.h:16
struct ARC_ParserTagToken ARC_ParserTagToken
a parser type used inside of the parser data create function
a type that holds an array of data and its size
Definition array.h:13
a lexer token type
Definition lexer.h:18
a parser type used inside of the parser data create function
Definition parser.h:35
ARC_LexerToken * token
Definition parser.h:38
uint32_t id
Definition parser.h:36
ARC_Vector * tagTokens
Definition parser.h:39
a langue tag type for the parser //TODO: explain this better
Definition parser.h:21
uint32_t tagId
Definition parser.h:22
uint32_t tokensOrTagsSize
Definition parser.h:25
uint32_t ** tokensOrTags
Definition parser.h:24
substring position within a string
Definition string.h:14
creates and outlines a dynamic array type and its functions