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
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
$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>
<body>
<!--BEGIN DISABLE_INDEX-->

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;
}
```

View file

@ -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){

View file

@ -1,3 +1,5 @@
@page style-guide Style Guide
# 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.

View file

@ -5,8 +5,8 @@
extern "C" {
#endif
#include <stdint.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

View file

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

View file

@ -5,8 +5,8 @@
extern "C" {
#endif
#include <stdint.h>
#include "arc/std/string.h"
#include <stdint.h>
/**
* @brief get string and size from file
@ -39,4 +39,4 @@ void ARC_IO_WriteStrToFile(ARC_String *path, ARC_String *data);
}
#endif
#endif //ARC_STD_IO_H_
#endif //ARC_STD_IO_H_

View file

@ -4,6 +4,7 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "arc/std/string.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
*
* @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] 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
*
* @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] character the string to match against, will be copied

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -51,7 +51,7 @@
#define ARC_LEXER_TOKEN_PERCENT_CHAR '%'
#define ARC_LEXER_TOKEN_PERCENT_TAG "PERCENT"
void ARC_Lexer_InitBasicTokenRules(ARC_Lexer *lexer){
void ARC_Test_InitBasicLexerTokenRules(ARC_Lexer *lexer){
//null
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_Create(&lexer);
ARC_Lexer_InitBasicTokenRules(lexer);
ARC_Test_InitBasicLexerTokenRules(lexer);
ARC_String *simple;
ARC_String_CreateWithStrlen(&simple, "::{}!/.");