This commit is contained in:
Arthur Barraux
2025-06-12 17:00:19 +02:00
parent 04464ec2e7
commit 5818a8ecfc
14 changed files with 977 additions and 232 deletions
+72 -21
View File
@@ -1,12 +1,7 @@
#ifndef DATA_H_PARSER
#define DATA_H_PARSER
#include "define.h"
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Token types for lexical analysis
@@ -26,7 +21,7 @@ typedef enum {
typedef struct {
token_type_t type;
char value[MAX_TOKEN_LENGTH];
char *value;
int line;
int column;
} token_t;
@@ -37,23 +32,28 @@ typedef enum {
NODE_STRING,
NODE_NUMBER,
NODE_BOOLEAN,
NODE_FUNCTION_REF, // %function-name
NODE_FUNCTION_CALL // ,function-name()
NODE_FUNCTION_REF, // %function-name
NODE_FUNCTION_CALL, // ,function-name()
NODE_LIST
} node_type_t;
typedef struct node {
node_type_t type;
union {
char symbol[MAX_SYMBOL_LENGTH];
char string[MAX_STRING_LENGTH];
char *symbol;
char *string;
double number;
bool boolean;
char function_ref[MAX_SYMBOL_LENGTH];
char *function_ref;
struct {
char function_name[MAX_SYMBOL_LENGTH];
struct node *args[MAX_ARGS];
char *function_name;
struct node **args;
int arg_count;
} call;
struct {
struct node **children;
int child_count;
} list;
} data;
} node_t;
@@ -79,22 +79,73 @@ typedef struct config_var {
struct config_var *next;
} config_var_t;
typedef struct {
typedef struct config {
key_mapping_t *key_mappings;
config_var_t *variables;
} config_t;
// Execution context for function calls
typedef struct exec_context {
struct {
char **names;
node_t **values;
int count;
} local_vars;
} exec_context_t;
typedef void (*command_func_t)(void);
typedef enum { FUNC_BUILTIN, FUNC_USER_DEFINED, FUNC_REGISTRY } function_type_t;
typedef struct unified_function {
char *name;
function_type_t type;
union {
// For built-in functions
struct {
int (*handler)(node_t **args, int arg_count);
bool eval_args; // Whether to evaluate arguments before calling
} builtin;
// For user-defined functions
struct {
char **parameters;
int param_count;
node_t *body;
} user_defined;
// For registry functions
struct {
command_func_t func;
} registry;
} data;
struct unified_function *next;
} unified_function_t;
void advance_char(lexer_t *lexer);
void skip_whitespace(lexer_t *lexer);
void skip_comment(lexer_t *lexer);
node_t *create_node(node_type_t type);
node_t *create_symbol_node(const char *symbol);
node_t *create_string_node(const char *string);
node_t *create_number_node(double number);
node_t *create_boolean_node(bool value);
node_t *create_function_ref_node(const char *function_name);
node_t *create_function_call_node(const char *function_name);
void add_arg_to_call(node_t *call, node_t *args);
void add_to_list(node_t *node, node_t *element);
#endif
#ifdef GLOBAL_CONFIG
unified_function_t *unified_functions = NULL;
int registry_count;
config_var_t variable_registry[256];
int var_registry_count;
config_t config;
#else
extern unified_function_t *unified_functions;
extern int registry_count;
extern config_var_t variable_registry[256];
extern int var_registry_count;
extern config_t config;
#endif