lexer added to documentation, and fixed alignment of some imports
This commit is contained in:
parent
a9a26ec122
commit
acde9dfe3c
17 changed files with 88 additions and 30 deletions
|
|
@ -9,9 +9,7 @@ The API Reference for ::ARC_Array can be found here: arc/std/array.h
|
|||
# Example
|
||||
|
||||
```c
|
||||
#include <arc/std/array.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <archeus.h>
|
||||
|
||||
//initing the array (as it is a basic type there is no ARC_Array_Create or ARC_Array_Destroy)
|
||||
ARC_Array exampleArray;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ The API Reference for ::ARC_Bool can be found here: arc/std/bool.h
|
|||
# Basic Example
|
||||
|
||||
```c
|
||||
#include <arc/std/bool.h>
|
||||
#include <archeus.h>
|
||||
|
||||
ARC_Bool example = ARC_True;
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ if(example == ARC_True){
|
|||
#define ARC_True 1
|
||||
#define ARC_False 0
|
||||
|
||||
#include <arc/std/bool.h>
|
||||
#include <archeus.h>
|
||||
|
||||
ARC_Bool example = ARC_False;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ When throwing errors, ::arc_errno should usually be set to an ARC_ERRNO_ define
|
|||
# Basic Example
|
||||
|
||||
```c
|
||||
#include <arc/std/errno.h>
|
||||
#include <archeus.h>
|
||||
|
||||
void ARC_Example_ThrowNullError(){
|
||||
uint32_t *exampleNumber = NULL;
|
||||
|
|
@ -35,8 +35,7 @@ Sometimes the error will have data that could be helpful when debugging, so ther
|
|||
# Example With Variables
|
||||
|
||||
```c
|
||||
#include <arc/std/errno.h>
|
||||
#include <arc/std/string.h>
|
||||
#include <archeus.h>
|
||||
|
||||
void ARC_Example_ThrowPathError(ARC_String *path){
|
||||
ARC_String *data;
|
||||
|
|
|
|||
|
|
@ -1 +1,64 @@
|
|||
\page standard-lexer ARC_Lexer
|
||||
|
||||
# Basic Overview
|
||||
|
||||
The ::ARC_Lexer type takes rules for what a token in, then takes a string and splits it up into tokens based on the rules.
|
||||
|
||||
The API Reference for ::ARC_Lexer can be found here: arc/std/lexer.h
|
||||
|
||||
Note: @ref standard-config "ARC_Config" uses a lot of functions from the lexer
|
||||
|
||||
# Basic Example
|
||||
|
||||
```c
|
||||
#include <archeus.h>
|
||||
|
||||
const uint32_t TOKEN_NULL = 0;
|
||||
const uint32_t TOKEN_NUMBER = 1;
|
||||
const uint32_t TOKEN_ALPHA_LOWER_CHAR = 2;
|
||||
const uint32_t TOKEN_ALPHA_UPPER_CHAR = 3;
|
||||
const uint32_t TOKEN_HYPHEN = 4;
|
||||
|
||||
//private function to initialize the lexer rules for the language
|
||||
void ARC_Example_InitLexerRulesFn(ARC_Lexer *lexer){
|
||||
//null
|
||||
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(TOKEN_NULL, 0));
|
||||
|
||||
//number
|
||||
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(TOKEN_NUMBER, '0', '9'));
|
||||
|
||||
//alphabetic characters
|
||||
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(TOKEN_ALPHA_LOWER_CHAR, 'a', 'z'));
|
||||
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(TOKEN_ALPHA_UPPER_CHAR, 'A', 'Z'));
|
||||
|
||||
//hyphen
|
||||
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(TOKEN_HYPHEN, '-'));
|
||||
}
|
||||
|
||||
int main(){
|
||||
ARC_Lexer *lexer;
|
||||
ARC_Lexer_Create(&lexer);
|
||||
|
||||
//add the rules to the lexer
|
||||
ARC_Example_InitLexerRulesFn(lexer);
|
||||
|
||||
//create the example string to lex
|
||||
ARC_String *exampleString;
|
||||
ARC_String_CreateWithStrlen(&exampleString, "T-1000");
|
||||
|
||||
//this function handles cleanup for the string
|
||||
ARC_Lexer_LexString(lexer, &exampleString);
|
||||
|
||||
//loop through all the tokens printing the lexed contents
|
||||
for(uint32_t index = 0; index < ARC_Lexer_GetTokenSize(lexer); index++){
|
||||
ARC_LexerToken *token = ARC_Lexer_GetToken(lexer, index);
|
||||
|
||||
printf("%u) Token Rule: %u\n", index, token->rule);
|
||||
}
|
||||
|
||||
//cleanup
|
||||
ARC_Lexer_Destroy(lexer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -9,9 +9,7 @@ The API Reference for ::ARC_Vector can be found here: arc/std/vector.h
|
|||
# Basic Example:
|
||||
|
||||
```c
|
||||
#include <arc/std/vector.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <archeus.h>
|
||||
|
||||
//creating an array with no callbacks (the simplest example of the array)
|
||||
ARC_Vector *vector;
|
||||
|
|
@ -51,9 +49,7 @@ A handy feature of this implmentation fo a vector is the ability to add a compar
|
|||
# Comparison Callback Example
|
||||
|
||||
```c
|
||||
#include <arc/std/vector.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <archeus.h>
|
||||
|
||||
//the comparison callback to check if two integer pointers hold the same value
|
||||
ARC_Bool ARC_Example_VectorCompareDataFn(void *dataA, void *dataB){
|
||||
|
|
@ -115,10 +111,7 @@ As the vector takes a pointer, usually that pointer is allocated right before be
|
|||
# Destruction Callback Example
|
||||
|
||||
```c
|
||||
#include <arc/std/vector.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <archeus.h>
|
||||
|
||||
//the destruction callback to free the allocated int32_t values
|
||||
void ARC_Example_VectorDestroyDataFn(void *data){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue