lexer added to documentation, and fixed alignment of some imports

This commit is contained in:
herbglitch 2025-03-28 04:12:57 -06:00
parent a9a26ec122
commit acde9dfe3c
17 changed files with 88 additions and 30 deletions

View file

@ -21,7 +21,7 @@ $search
$mathjax $mathjax
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" /> <link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
$extrastylesheet $extrastylesheet
<script type="text/javascript" src="$relpath^doxygen-awesome-darkmode-toggle.js"></script> <!-- script type="text/javascript" src="$relpath^doxygen-awesome-darkmode-toggle.js"></script -->
</head> </head>
<body> <body>
<!--BEGIN DISABLE_INDEX--> <!--BEGIN DISABLE_INDEX-->

View file

@ -9,9 +9,7 @@ The API Reference for ::ARC_Array can be found here: arc/std/array.h
# Example # Example
```c ```c
#include <arc/std/array.h> #include <archeus.h>
#include <stdint.h>
#include <stdlib.h>
//initing the array (as it is a basic type there is no ARC_Array_Create or ARC_Array_Destroy) //initing the array (as it is a basic type there is no ARC_Array_Create or ARC_Array_Destroy)
ARC_Array exampleArray; ARC_Array exampleArray;

View file

@ -9,7 +9,7 @@ The API Reference for ::ARC_Bool can be found here: arc/std/bool.h
# Basic Example # Basic Example
```c ```c
#include <arc/std/bool.h> #include <archeus.h>
ARC_Bool example = ARC_True; ARC_Bool example = ARC_True;
@ -30,7 +30,7 @@ if(example == ARC_True){
#define ARC_True 1 #define ARC_True 1
#define ARC_False 0 #define ARC_False 0
#include <arc/std/bool.h> #include <archeus.h>
ARC_Bool example = ARC_False; ARC_Bool example = ARC_False;

View file

@ -13,7 +13,7 @@ When throwing errors, ::arc_errno should usually be set to an ARC_ERRNO_ define
# Basic Example # Basic Example
```c ```c
#include <arc/std/errno.h> #include <archeus.h>
void ARC_Example_ThrowNullError(){ void ARC_Example_ThrowNullError(){
uint32_t *exampleNumber = NULL; 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 # Example With Variables
```c ```c
#include <arc/std/errno.h> #include <archeus.h>
#include <arc/std/string.h>
void ARC_Example_ThrowPathError(ARC_String *path){ void ARC_Example_ThrowPathError(ARC_String *path){
ARC_String *data; ARC_String *data;

View file

@ -1 +1,64 @@
\page standard-lexer ARC_Lexer \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;
}
```

View file

@ -9,9 +9,7 @@ The API Reference for ::ARC_Vector can be found here: arc/std/vector.h
# Basic Example: # Basic Example:
```c ```c
#include <arc/std/vector.h> #include <archeus.h>
#include <stdint.h>
#include <stdio.h>
//creating an array with no callbacks (the simplest example of the array) //creating an array with no callbacks (the simplest example of the array)
ARC_Vector *vector; 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 # Comparison Callback Example
```c ```c
#include <arc/std/vector.h> #include <archeus.h>
#include <stdint.h>
#include <stdio.h>
//the comparison callback to check if two integer pointers hold the same value //the comparison callback to check if two integer pointers hold the same value
ARC_Bool ARC_Example_VectorCompareDataFn(void *dataA, void *dataB){ 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 # Destruction Callback Example
```c ```c
#include <arc/std/vector.h> #include <archeus.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
//the destruction callback to free the allocated int32_t values //the destruction callback to free the allocated int32_t values
void ARC_Example_VectorDestroyDataFn(void *data){ void ARC_Example_VectorDestroyDataFn(void *data){

View file

@ -1,3 +1,5 @@
@page style-guide Style Guide
# Introduction # Introduction
This document outlines the style for any C code that is to be stored within this repository. This document will most likely be changed over time as the style becomes more set. This document outlines the style for any C code that is to be stored within this repository. This document will most likely be changed over time as the style becomes more set.

View file

@ -5,8 +5,8 @@
extern "C" { extern "C" {
#endif #endif
#include <stdint.h>
#include "arc/std/parser.h" #include "arc/std/parser.h"
#include <stdint.h>
/** /**
* @brief the config type for archeus, loads in a .chemical file which syntax is specified in the documentation * @brief the config type for archeus, loads in a .chemical file which syntax is specified in the documentation

View file

@ -7,7 +7,6 @@ extern "C" {
#include "arc/std/bool.h" #include "arc/std/bool.h"
#include <stdint.h> #include <stdint.h>
#include <stddef.h>
/** /**
* @brief a hashing function ptr * @brief a hashing function ptr

View file

@ -5,8 +5,8 @@
extern "C" { extern "C" {
#endif #endif
#include <stdint.h>
#include "arc/std/string.h" #include "arc/std/string.h"
#include <stdint.h>
/** /**
* @brief get string and size from file * @brief get string and size from file

View file

@ -4,6 +4,7 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "arc/std/string.h" #include "arc/std/string.h"
#include <stdint.h> #include <stdint.h>
@ -220,7 +221,7 @@ ARC_LexerTokenRule ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(uint32_t
* @brief creates a ARC_LexerTokenRule with a given id and string * @brief creates a ARC_LexerTokenRule with a given id and string
* *
* @note this is intended as a helper funtion * @note this is intended as a helper funtion
* #note string will not be freed (it will be copied and the copy will be freed) * @note string will not be freed (it will be copied and the copy will be freed)
* *
* @param[in] id a tokens id (basically the token value) * @param[in] id a tokens id (basically the token value)
* @param[in] character the string to match against, will be copied * @param[in] character the string to match against, will be copied
@ -233,7 +234,7 @@ ARC_LexerTokenRule ARC_LexerTokenRule_CreateAndReturnMatchStringRule(uint32_t id
* @brief creates a ARC_LexerTokenRule with a given id and string * @brief creates a ARC_LexerTokenRule with a given id and string
* *
* @note this is intended as a helper funtion * @note this is intended as a helper funtion
* #note string will not be freed (it will be copied and the copy will be freed) * @note string will not be freed (it will be copied and the copy will be freed)
* *
* @param[in] id a tokens id (basically the token value) * @param[in] id a tokens id (basically the token value)
* @param[in] character the string to match against, will be copied * @param[in] character the string to match against, will be copied

View file

@ -5,8 +5,8 @@
extern "C" { extern "C" {
#endif #endif
#include <stdint.h>
#include "bool.h" #include "bool.h"
#include <stdint.h>
/** /**
* @brief substring position within a string * @brief substring position within a string

View file

@ -1,4 +1,5 @@
#include "arc/std/config.h" #include "arc/std/config.h"
#include "arc/std/array.h" #include "arc/std/array.h"
#include "arc/std/bool.h" #include "arc/std/bool.h"
#include "arc/std/errno.h" #include "arc/std/errno.h"

View file

@ -1,4 +1,5 @@
#include "arc/std/hashtable.h" #include "arc/std/hashtable.h"
#include "arc/std/errno.h" #include "arc/std/errno.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>

View file

@ -2,9 +2,9 @@
#include "arc/std/bool.h" #include "arc/std/bool.h"
#include "arc/std/errno.h" #include "arc/std/errno.h"
#include "arc/std/io.h"
#include "arc/std/string.h" #include "arc/std/string.h"
#include "arc/std/vector.h" #include "arc/std/vector.h"
#include "arc/std/io.h"
#include <stdlib.h> #include <stdlib.h>
struct ARC_Lexer { struct ARC_Lexer {

View file

@ -1,10 +1,11 @@
#include "arc/std/parser/parserlang.h"
#include "arc/std/parser.h" #include "arc/std/parser.h"
#include "arc/std/bool.h" #include "arc/std/bool.h"
#include "arc/std/errno.h" #include "arc/std/errno.h"
#include "arc/std/io.h" #include "arc/std/io.h"
#include "arc/std/lexer.h" #include "arc/std/lexer.h"
#include "arc/std/vector.h" #include "arc/std/vector.h"
#include "arc/std/parser/parserlang.h"
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View file

@ -51,7 +51,7 @@
#define ARC_LEXER_TOKEN_PERCENT_CHAR '%' #define ARC_LEXER_TOKEN_PERCENT_CHAR '%'
#define ARC_LEXER_TOKEN_PERCENT_TAG "PERCENT" #define ARC_LEXER_TOKEN_PERCENT_TAG "PERCENT"
void ARC_Lexer_InitBasicTokenRules(ARC_Lexer *lexer){ void ARC_Test_InitBasicLexerTokenRules(ARC_Lexer *lexer){
//null //null
ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_LEXER_TOKEN_NULL, 0)); ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_LEXER_TOKEN_NULL, 0));
@ -91,7 +91,7 @@ ARC_TEST(Lexer_Char_Match){
ARC_Lexer *lexer; ARC_Lexer *lexer;
ARC_Lexer_Create(&lexer); ARC_Lexer_Create(&lexer);
ARC_Lexer_InitBasicTokenRules(lexer); ARC_Test_InitBasicLexerTokenRules(lexer);
ARC_String *simple; ARC_String *simple;
ARC_String_CreateWithStrlen(&simple, "::{}!/."); ARC_String_CreateWithStrlen(&simple, "::{}!/.");