creation and destruction in parser, also added some stuff to gitingore
This commit is contained in:
parent
5842197142
commit
60acfd075a
6 changed files with 151 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -527,3 +527,5 @@ FodyWeavers.xsd
|
||||||
doxygen/html
|
doxygen/html
|
||||||
[Bb][Uu][Ii][Ll][Dd]
|
[Bb][Uu][Ii][Ll][Dd]
|
||||||
.ccls
|
.ccls
|
||||||
|
.vscode
|
||||||
|
tests/test_error_out.txt
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ set(ARCHEUS_STD_SOURCES
|
||||||
src/std/hashtable.c
|
src/std/hashtable.c
|
||||||
src/std/io.c
|
src/std/io.c
|
||||||
src/std/lexer.c
|
src/std/lexer.c
|
||||||
|
src/std/parser.c
|
||||||
src/std/queue.c
|
src/std/queue.c
|
||||||
src/std/stack.c
|
src/std/stack.c
|
||||||
src/std/string.c
|
src/std/string.c
|
||||||
|
|
@ -127,7 +128,8 @@ if(ARCHEUS_STD_TESTS)
|
||||||
tests/test.c
|
tests/test.c
|
||||||
|
|
||||||
#tests/std/vector.c
|
#tests/std/vector.c
|
||||||
tests/std/lexer.c
|
#tests/std/lexer.c
|
||||||
|
tests/std/parser.c
|
||||||
|
|
||||||
${ARCHEUS_STD_SOURCES}
|
${ARCHEUS_STD_SOURCES}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ typedef ARC_Bool (* ARC_LexerTokenRule_AutomataFn)(ARC_String **string, ARC_Stri
|
||||||
*/
|
*/
|
||||||
typedef void (* ARC_LexerTokenRule_DestroyAutomataDataFn)(void *automataData);
|
typedef void (* ARC_LexerTokenRule_DestroyAutomataDataFn)(void *automataData);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief a lexer token rule type
|
* @brief a lexer token rule type
|
||||||
*/
|
*/
|
||||||
|
|
@ -59,7 +58,7 @@ typedef struct ARC_LexerTokenRule {
|
||||||
/**
|
/**
|
||||||
* @brief creates an ARC_Lexer type
|
* @brief creates an ARC_Lexer type
|
||||||
*
|
*
|
||||||
* @param[out] lexer
|
* @param[out] lexer ARC_Lexer to create
|
||||||
*/
|
*/
|
||||||
void ARC_Lexer_Create(ARC_Lexer **lexer);
|
void ARC_Lexer_Create(ARC_Lexer **lexer);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
#ifndef ARC_STD_PARSER_H_
|
||||||
|
#define ARC_STD_PARSER_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "arc/std/array.h"
|
||||||
|
//#include "arc/std/bool.h"
|
||||||
|
//#include "arc/std/lexer.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief a lexer type
|
||||||
|
*/
|
||||||
|
typedef struct ARC_Parser ARC_Parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief a lexer type
|
||||||
|
*/
|
||||||
|
typedef struct ARC_ParserLanguageTag {
|
||||||
|
uint32_t tagId;
|
||||||
|
|
||||||
|
uint32_t **tokensOrTags;
|
||||||
|
uint32_t tokensOrTagsSize;
|
||||||
|
} ARC_ParserLanguageTag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief creates an ARC_Parser type
|
||||||
|
*
|
||||||
|
* @TODO: probs want to move the note to another file
|
||||||
|
* @note array of tokens for langauge? like
|
||||||
|
* ARC_ParserTag tag = {
|
||||||
|
* VARIABLE_NAME, //tagId
|
||||||
|
* {
|
||||||
|
* { 2, CHAR_OR_NUM, VARIABLE_NAME },
|
||||||
|
* { 1, LAMBDA },
|
||||||
|
* }, //components
|
||||||
|
* 2 //componentsSize
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* @param[out] parser ARC_Parser to create
|
||||||
|
* @param[in] language an arry of ARC_ParserLanguageTags defining a langauge
|
||||||
|
*/
|
||||||
|
void ARC_Parser_Create(ARC_Parser **parser, ARC_Array *language);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief destroys an ARC_Parser type
|
||||||
|
*
|
||||||
|
* @param[in] parser ARC_Parser to free
|
||||||
|
*/
|
||||||
|
void ARC_Parser_Destroy(ARC_Parser *parser);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // !ARC_STD_PARSER_H_
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include "arc/std/parser.h"
|
||||||
|
#include "arc/std/lexer.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
struct ARC_Parser {
|
||||||
|
ARC_Array language;
|
||||||
|
|
||||||
|
ARC_Lexer *lexer;
|
||||||
|
};
|
||||||
|
|
||||||
|
void ARC_Parser_Create(ARC_Parser **parser, ARC_Array *language){
|
||||||
|
*parser = (ARC_Parser *)malloc(sizeof(ARC_Parser));
|
||||||
|
|
||||||
|
//set the language size to 0 and data to NULL in case the language is NULL
|
||||||
|
(*parser)->language.size = 0;
|
||||||
|
(*parser)->language.data = NULL;
|
||||||
|
|
||||||
|
//if the language exists, copy the language
|
||||||
|
if(language != NULL){
|
||||||
|
(*parser)->language.size = language->size;
|
||||||
|
(*parser)->language.data = malloc(sizeof(ARC_ParserLanguageTag) * language->size);
|
||||||
|
|
||||||
|
memcpy((*parser)->language.data, language->data, language->size);
|
||||||
|
}
|
||||||
|
|
||||||
|
//create the lexer
|
||||||
|
ARC_Lexer_Create(&((*parser)->lexer));
|
||||||
|
|
||||||
|
//TODO: register instructions to the lexer
|
||||||
|
//TODO: probs want to pass in a callback for this
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARC_Parser_Destroy(ARC_Parser *parser){
|
||||||
|
free(parser->language.data);
|
||||||
|
|
||||||
|
ARC_Lexer_Destroy(parser->lexer);
|
||||||
|
|
||||||
|
free(parser);
|
||||||
|
}
|
||||||
45
tests/std/parser.c
Normal file
45
tests/std/parser.c
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
#include "../test.h"
|
||||||
|
#include "arc/std/parser.h"
|
||||||
|
|
||||||
|
#define LAMBDA 0
|
||||||
|
#define CHAR 1
|
||||||
|
#define NUM 2
|
||||||
|
#define CHAR_OR_NUM 3
|
||||||
|
#define VARIABLE_NAME 4
|
||||||
|
#define VARIABLE 5
|
||||||
|
|
||||||
|
ARC_TEST(Lexer_Char_Match){
|
||||||
|
ARC_Parser *parser;
|
||||||
|
|
||||||
|
uint32_t *charOrNumTokens[] = { (uint32_t[]){ 1, CHAR }, (uint32_t[]){ 1, NUM } };
|
||||||
|
uint32_t *variableNameTags[] = { (uint32_t[]){ 2, CHAR_OR_NUM, VARIABLE_NAME }, (uint32_t[]){ 1, LAMBDA } };
|
||||||
|
uint32_t *variableTokensOrTags[] = { (uint32_t[]){ 2, CHAR, VARIABLE_NAME } };
|
||||||
|
ARC_ParserLanguageTag testTags[3] = {
|
||||||
|
{
|
||||||
|
CHAR_OR_NUM, //tagId
|
||||||
|
charOrNumTokens, //tokensOrTags
|
||||||
|
2 //tokenOrTagsSize
|
||||||
|
},
|
||||||
|
{
|
||||||
|
VARIABLE_NAME, //tagId
|
||||||
|
variableNameTags, //tokensOrTags
|
||||||
|
2 //tokenOrTagsSize
|
||||||
|
},
|
||||||
|
{
|
||||||
|
VARIABLE, //tagId
|
||||||
|
variableTokensOrTags, //tokensOrTags
|
||||||
|
1 //tokenOrTagsSize
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ARC_Array languageArray = {
|
||||||
|
3, //size
|
||||||
|
testTags //data
|
||||||
|
};
|
||||||
|
|
||||||
|
ARC_Parser_Create(&parser, &languageArray);
|
||||||
|
|
||||||
|
ARC_Parser_Destroy(parser);
|
||||||
|
|
||||||
|
ARC_CHECK(1 == 1);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue