Loading...
Searching...
No Matches
parserlang.c File Reference
`#include "../../test.h"`
`#include "arc/std/errno.h"`
`#include "arc/std/parser.h"`
`#include "arc/std/string.h"`
`#include "arc/std/parser/parserlang.h"`

Go to the source code of this file.

## Functions

uint32_t | TEST_ParserLang_GetIdFn (ARC_String *string)
| ARC_TEST (Parser_ParserLang_BasicTest)

## Variables

uint32_t | TEST_PARSERLANG_ALPHA_CHAR = 24

## Function Documentation

## ARC_TEST()

ARC_TEST | ( | Parser_ParserLang_BasicTest |  | ) |

Definition at line 26 of file parserlang.c.

{
ARC_Parser *parser;
ARC_ParserLang_CreateAsParser(&parser, TEST_ParserLang_GetIdFn);
ARC_String *tempString;
ARC_String_CreateWithStrlen(&tempString, "\n\n<alphaChar> -> ALPHA_LOWER_CHAR | ALPHA_UPPER_CHAR\n\n\n");
//this destroys string, so no need for cleanup
ARC_Parser_Parse(parser, &tempString);
ARC_CHECK(arc_errno == 0);
void *data = ARC_Parser_GetData(parser);
ARC_ParserTag *tag = ARC_Vector_Get((ARC_Vector *)data, 0);
ARC_CHECK(tag->tagId == TEST_PARSERLANG_ALPHA_CHAR);
ARC_CHECK(tag->tokensOrTagsSize == 2);
ARC_CHECK(tag->tokensOrTags[0][0] == 1);
ARC_CHECK(tag->tokensOrTags[0][1] == ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR);
ARC_CHECK(tag->tokensOrTags[1][0] == 1);
ARC_CHECK(tag->tokensOrTags[1][1] == ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR);
ARC_Parser_Destroy(parser);
}
arc_errno
int32_t arc_errno
Definition errno.c:5
ARC_Parser_Parse
void ARC_Parser_Parse(ARC_Parser *parser, ARC_String **data)
Definition parser.c:297
ARC_Parser_Destroy
void ARC_Parser_Destroy(ARC_Parser *parser)
destroys an ARC_Parser type
Definition parser.c:127
ARC_Parser_GetData
void * ARC_Parser_GetData(ARC_Parser *parser)
Definition parser.c:368
ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR
#define ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR
Definition parserlang.h:44
ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR
#define ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR
Definition parserlang.h:43
ARC_ParserLang_CreateAsParser
void ARC_ParserLang_CreateAsParser(ARC_Parser **parser, ARC_Parser_GetStringIdFn getStringIdFn)
creates a parser for the Parser Lang
Definition parserlang.c:324
ARC_String_CreateWithStrlen
void ARC_String_CreateWithStrlen(ARC_String **string, char *data)
creates ARC_String type with strinlen
Definition string.c:32
ARC_ParserTag
a langue tag type for the parser //TODO: explain this better
Definition parser.h:21
ARC_ParserTag::tagId
uint32_t tagId
Definition parser.h:22
ARC_ParserTag::tokensOrTagsSize
uint32_t tokensOrTagsSize
Definition parser.h:25
ARC_ParserTag::tokensOrTags
uint32_t ** tokensOrTags
Definition parser.h:24
ARC_Parser
Definition parser.c:12
ARC_String
substring position within a string
Definition string.h:14
ARC_Vector
a private dynamic array type
Definition vector.c:12
ARC_CHECK
#define ARC_CHECK(TEST)
Definition test.h:33
TEST_ParserLang_GetIdFn
uint32_t TEST_ParserLang_GetIdFn(ARC_String *string)
Definition parserlang.c:10
TEST_PARSERLANG_ALPHA_CHAR
uint32_t TEST_PARSERLANG_ALPHA_CHAR
Definition parserlang.c:7
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:153

References ARC_CHECK, arc_errno, ARC_Parser_Destroy(), ARC_Parser_GetData(), ARC_Parser_Parse(), ARC_ParserLang_CreateAsParser(), ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR, ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR, ARC_String_CreateWithStrlen(), ARC_Vector_Get(), ARC_ParserTag::tagId, TEST_PARSERLANG_ALPHA_CHAR, TEST_ParserLang_GetIdFn(), ARC_ParserTag::tokensOrTags, and ARC_ParserTag::tokensOrTagsSize.

## TEST_ParserLang_GetIdFn()

uint32_t TEST_ParserLang_GetIdFn | ( | ARC_String * | string | ) |

Definition at line 10 of file parserlang.c.

{
if(ARC_String_EqualsCStringWithStrlen(string, "<alphaChar>")){
return TEST_PARSERLANG_ALPHA_CHAR;
}
if(ARC_String_EqualsCStringWithStrlen(string, "ALPHA_LOWER_CHAR")){
return ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR;
}
if(ARC_String_EqualsCStringWithStrlen(string, "ALPHA_UPPER_CHAR")){
return ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR;
}
return ~(uint32_t)0;
}
ARC_String_EqualsCStringWithStrlen
ARC_Bool ARC_String_EqualsCStringWithStrlen(ARC_String *string, const char *cstring)
check if ARC_String and cstring match
Definition string.c:171

References ARC_PARSERLANG_TOKEN_ALPHA_LOWER_CHAR, ARC_PARSERLANG_TOKEN_ALPHA_UPPER_CHAR, ARC_String_EqualsCStringWithStrlen(), and TEST_PARSERLANG_ALPHA_CHAR.

Referenced by ARC_TEST().

## Variable Documentation

## TEST_PARSERLANG_ALPHA_CHAR

uint32_t TEST_PARSERLANG_ALPHA_CHAR = 24

Definition at line 7 of file parserlang.c.

Referenced by ARC_TEST(), and TEST_ParserLang_GetIdFn().