Loading...
Searching...
No Matches
lexer.c File Reference
`#include "../test.h"`
`#include "arc/std/lexer.h"`

Go to the source code of this file.

## Functions

| ARC_TEST (Lexer_Char_Match)
| ARC_TEST (Lexer_Check_Id_Basic)
| ARC_TEST (Lexer_Check_Id_Unordered_But_Continious)
| ARC_TEST (Lexer_Check_Id_Unordered_Not_Continious)
| ARC_TEST (Lexer_Check_Continious)
| ARC_TEST (Lexer_Check_Not_Continious)

## Function Documentation

## ARC_TEST() [1/6]

ARC_TEST | ( | Lexer_Char_Match |  | ) |

Definition at line 4 of file lexer.c.

{
ARC_Lexer *lexer;
ARC_Lexer_Create(&lexer);
ARC_Lexer_InitBasicTokenRules(lexer);
ARC_String *simple;
ARC_String_CreateWithStrlen(&simple, "::{}!/.");
ARC_Lexer_LexString(lexer, &simple);
ARC_LexerToken *token;
token = ARC_Lexer_GetToken(lexer, 0);
ARC_CHECK(token->rule == ARC_LEXER_TOKEN_COLON_ID);
token = ARC_Lexer_GetToken(lexer, 1);
ARC_CHECK(token->rule == ARC_LEXER_TOKEN_COLON_ID);
token = ARC_Lexer_GetToken(lexer, 2);
ARC_CHECK(token->rule == ARC_LEXER_TOKEN_LEFT_CURLY_BRACE_ID);
token = ARC_Lexer_GetToken(lexer, 3);
ARC_CHECK(token->rule == ARC_LEXER_TOKEN_RIGHT_CURLY_BRACE_ID);
token = ARC_Lexer_GetToken(lexer, 4);
ARC_CHECK(token->rule == ARC_LEXER_TOKEN_BANG_ID);
token = ARC_Lexer_GetToken(lexer, 5);
ARC_CHECK(token->rule == ARC_LEXER_TOKEN_FORWARD_SLASH_ID);
token = ARC_Lexer_GetToken(lexer, 6);
ARC_CHECK(token->rule == ARC_LEXER_TOKEN_PERIOD_ID);
ARC_Lexer_Destroy(lexer);
}
ARC_LEXER_TOKEN_FORWARD_SLASH_ID
#define ARC_LEXER_TOKEN_FORWARD_SLASH_ID
Definition lexer.h:271
ARC_LEXER_TOKEN_PERIOD_ID
#define ARC_LEXER_TOKEN_PERIOD_ID
Definition lexer.h:268
ARC_LEXER_TOKEN_LEFT_CURLY_BRACE_ID
#define ARC_LEXER_TOKEN_LEFT_CURLY_BRACE_ID
Definition lexer.h:283
ARC_LEXER_TOKEN_RIGHT_CURLY_BRACE_ID
#define ARC_LEXER_TOKEN_RIGHT_CURLY_BRACE_ID
Definition lexer.h:286
ARC_LEXER_TOKEN_BANG_ID
#define ARC_LEXER_TOKEN_BANG_ID
Definition lexer.h:289
ARC_LEXER_TOKEN_COLON_ID
#define ARC_LEXER_TOKEN_COLON_ID
Definition lexer.h:259
ARC_Lexer_GetToken
ARC_LexerToken * ARC_Lexer_GetToken(ARC_Lexer *lexer, uint32_t index)
gets a token at a given index from a lexer
Definition lexer.c:272
ARC_Lexer_LexString
void ARC_Lexer_LexString(ARC_Lexer *lexer, ARC_String **data)
creates tokens using a given string with ARC_LexerToken rules
Definition lexer.c:166
ARC_Lexer_InitBasicTokenRules
void ARC_Lexer_InitBasicTokenRules(ARC_Lexer *lexer)
adds a bunch of basic token rules (matching the BasicTokens above)
Definition lexer.c:472
ARC_Lexer_Create
void ARC_Lexer_Create(ARC_Lexer **lexer)
creates an ARC_Lexer type
Definition lexer.c:50
ARC_Lexer_Destroy
void ARC_Lexer_Destroy(ARC_Lexer *lexer)
destroys an ARC_Lexer type
Definition lexer.c:68
ARC_String_CreateWithStrlen
void ARC_String_CreateWithStrlen(ARC_String **string, char *data)
creates ARC_String type with strinlen
Definition string.c:32
ARC_LexerToken
a lexer token type
Definition lexer.h:18
ARC_LexerToken::rule
uint32_t rule
Definition lexer.h:19
ARC_Lexer
Definition lexer.c:10
ARC_String
substring position within a string
Definition string.h:14
ARC_CHECK
#define ARC_CHECK(TEST)
Definition test.h:33

References ARC_CHECK, ARC_Lexer_Create(), ARC_Lexer_Destroy(), ARC_Lexer_GetToken(), ARC_Lexer_InitBasicTokenRules(), ARC_Lexer_LexString(), ARC_LEXER_TOKEN_BANG_ID, ARC_LEXER_TOKEN_COLON_ID, ARC_LEXER_TOKEN_FORWARD_SLASH_ID, ARC_LEXER_TOKEN_LEFT_CURLY_BRACE_ID, ARC_LEXER_TOKEN_PERIOD_ID, ARC_LEXER_TOKEN_RIGHT_CURLY_BRACE_ID, ARC_String_CreateWithStrlen(), and ARC_LexerToken::rule.

## ARC_TEST() [2/6]

ARC_TEST | ( | Lexer_Check_Continious |  | ) |

Definition at line 98 of file lexer.c.

{
ARC_Lexer *lexer;
ARC_Lexer_Create(&lexer);
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(2, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(0, 0 ));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(3, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(1, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(4, ':'));
ARC_CHECK(ARC_Lexer_IsContinious(lexer) == ARC_True);
ARC_Lexer_Destroy(lexer);
}
ARC_True
#define ARC_True
Definition bool.h:11
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_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_Lexer_IsContinious
ARC_Bool ARC_Lexer_IsContinious(ARC_Lexer *lexer)
returns a boolean based on if a lexers rules are continious
Definition lexer.c:290

References ARC_CHECK, ARC_Lexer_Create(), ARC_Lexer_Destroy(), ARC_Lexer_IsContinious(), ARC_Lexer_RegisterTokenRule(), ARC_LexerTokenRule_CreateAndReturnMatchCharRule(), and ARC_True.

## ARC_TEST() [3/6]

ARC_TEST | ( | Lexer_Check_Id_Basic |  | ) |

Definition at line 41 of file lexer.c.

{
ARC_Lexer *lexer;
ARC_Lexer_Create(&lexer);
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(0, 0 ));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(1, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(2, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(3, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(4, ':'));
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 0) == ARC_True );
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 7) == ARC_False);
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 2) == ARC_True );
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 4) == ARC_True );
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 5) == ARC_False);
ARC_Lexer_Destroy(lexer);
}
ARC_False
#define ARC_False
Definition bool.h:12
ARC_Lexer_IsTokenId
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
Definition lexer.c:294

References ARC_CHECK, ARC_False, ARC_Lexer_Create(), ARC_Lexer_Destroy(), ARC_Lexer_IsTokenId(), ARC_Lexer_RegisterTokenRule(), ARC_LexerTokenRule_CreateAndReturnMatchCharRule(), and ARC_True.

## ARC_TEST() [4/6]

ARC_TEST | ( | Lexer_Check_Id_Unordered_But_Continious |  | ) |

Definition at line 60 of file lexer.c.

{
ARC_Lexer *lexer;
ARC_Lexer_Create(&lexer);
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(2, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(0, 0 ));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(3, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(1, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(4, ':'));
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 0) == ARC_True );
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 7) == ARC_False);
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 2) == ARC_True );
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 4) == ARC_True );
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 5) == ARC_False);
ARC_Lexer_Destroy(lexer);
}

References ARC_CHECK, ARC_False, ARC_Lexer_Create(), ARC_Lexer_Destroy(), ARC_Lexer_IsTokenId(), ARC_Lexer_RegisterTokenRule(), ARC_LexerTokenRule_CreateAndReturnMatchCharRule(), and ARC_True.

## ARC_TEST() [5/6]

ARC_TEST | ( | Lexer_Check_Id_Unordered_Not_Continious |  | ) |

Definition at line 79 of file lexer.c.

{
ARC_Lexer *lexer;
ARC_Lexer_Create(&lexer);
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(2, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(8, 0 ));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(3, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(1, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(4, ':'));
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 8) == ARC_True );
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 7) == ARC_False);
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 2) == ARC_True );
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 4) == ARC_True );
ARC_CHECK(ARC_Lexer_IsTokenId(lexer, 5) == ARC_False);
ARC_Lexer_Destroy(lexer);
}

References ARC_CHECK, ARC_False, ARC_Lexer_Create(), ARC_Lexer_Destroy(), ARC_Lexer_IsTokenId(), ARC_Lexer_RegisterTokenRule(), ARC_LexerTokenRule_CreateAndReturnMatchCharRule(), and ARC_True.

## ARC_TEST() [6/6]

ARC_TEST | ( | Lexer_Check_Not_Continious |  | ) |

Definition at line 113 of file lexer.c.

{
ARC_Lexer *lexer;
ARC_Lexer_Create(&lexer);
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(2, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(8, 0 ));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(3, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(1, ':'));
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(4, ':'));
ARC_CHECK(ARC_Lexer_IsContinious(lexer) == ARC_False);
ARC_Lexer_Destroy(lexer);
}

References ARC_CHECK, ARC_False, ARC_Lexer_Create(), ARC_Lexer_Destroy(), ARC_Lexer_IsContinious(), ARC_Lexer_RegisterTokenRule(), and ARC_LexerTokenRule_CreateAndReturnMatchCharRule().