first commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#ifndef CONFIG_TOOLS_H_
|
||||
#define CONFIG_TOOLS_H_
|
||||
|
||||
#include "data.h"
|
||||
#include "parser.h"
|
||||
#include <stdio.h>
|
||||
|
||||
config_t *config_create(void);
|
||||
void free_node(node_t *node);
|
||||
void config_destroy(config_t *config);
|
||||
int handle_map_key(config_t *config, node_t **args, int arg_count);
|
||||
int handle_define(config_t *config, node_t **args, int arg_count);
|
||||
int execute_function_call(config_t *config, node_t *call);
|
||||
int config_parse_string(config_t *config, const char *input);
|
||||
int config_parse_file(config_t *config, const char *filename);
|
||||
|
||||
const char *config_get_key_mapping(config_t *config, const char *key_combo);
|
||||
node_t *find_variable(config_t *config, const char *name);
|
||||
|
||||
const char *config_get_string(config_t *config, const char *path,
|
||||
const char *default_value);
|
||||
int config_get_int(config_t *config, const char *path, int default_value);
|
||||
double config_get_double(config_t *config, const char *path,
|
||||
double default_value);
|
||||
bool config_get_bool(config_t *config, const char *path, bool default_value);
|
||||
void config_print_all(config_t *config);
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
int (*handler)(config_t *config, node_t **args, int arg_count);
|
||||
} builtin_functions[] = {
|
||||
{"map-key", handle_map_key}, {"define", handle_define}, {NULL, NULL}};
|
||||
|
||||
#endif
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
#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
|
||||
|
||||
typedef enum {
|
||||
TOKEN_COMMA, // ,
|
||||
TOKEN_PERCENT, // %
|
||||
TOKEN_LPAREN, // (
|
||||
TOKEN_RPAREN, // )
|
||||
TOKEN_SYMBOL, // identifiers/function names
|
||||
TOKEN_STRING, // "quoted strings"
|
||||
TOKEN_NUMBER, // integers and floats
|
||||
TOKEN_BOOLEAN, // true false
|
||||
TOKEN_NEWLINE, // \n (statement separator)
|
||||
TOKEN_EOF,
|
||||
TOKEN_ERROR
|
||||
} token_type_t;
|
||||
|
||||
typedef struct {
|
||||
token_type_t type;
|
||||
char value[MAX_TOKEN_LENGTH];
|
||||
int line;
|
||||
int column;
|
||||
} token_t;
|
||||
|
||||
// AST node types
|
||||
typedef enum {
|
||||
NODE_SYMBOL,
|
||||
NODE_STRING,
|
||||
NODE_NUMBER,
|
||||
NODE_BOOLEAN,
|
||||
NODE_FUNCTION_REF, // %function-name
|
||||
NODE_FUNCTION_CALL // ,function-name()
|
||||
} node_type_t;
|
||||
|
||||
typedef struct node {
|
||||
node_type_t type;
|
||||
union {
|
||||
char symbol[MAX_SYMBOL_LENGTH];
|
||||
char string[MAX_STRING_LENGTH];
|
||||
double number;
|
||||
bool boolean;
|
||||
char function_ref[MAX_SYMBOL_LENGTH];
|
||||
struct {
|
||||
char function_name[MAX_SYMBOL_LENGTH];
|
||||
struct node *args[MAX_ARGS];
|
||||
int arg_count;
|
||||
} call;
|
||||
} data;
|
||||
} node_t;
|
||||
|
||||
// Lexer state
|
||||
typedef struct {
|
||||
const char *input;
|
||||
int pos;
|
||||
int line;
|
||||
int column;
|
||||
char current_char;
|
||||
} lexer_t;
|
||||
|
||||
// Configuration storage
|
||||
typedef struct key_mapping {
|
||||
char *key_combo;
|
||||
char *function_name;
|
||||
struct key_mapping *next;
|
||||
} key_mapping_t;
|
||||
|
||||
typedef struct config_var {
|
||||
char *name;
|
||||
node_t *value;
|
||||
struct config_var *next;
|
||||
} config_var_t;
|
||||
|
||||
typedef struct {
|
||||
key_mapping_t *key_mappings;
|
||||
config_var_t *variables;
|
||||
} config_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);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef BLISP_DEFINE_H_
|
||||
#define BLISP_DEFINE_H_
|
||||
|
||||
#define MAX_TOKEN_LENGTH 256
|
||||
#define MAX_SYMBOL_LENGTH 128
|
||||
#define MAX_STRING_LENGTH 512
|
||||
#define MAX_ARGS 16
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef LEXER_H_
|
||||
#define LEXER_H_
|
||||
|
||||
#include "data.h"
|
||||
|
||||
token_t next_token(lexer_t *lexer);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef PARSER_H_
|
||||
#define PARSER_H_
|
||||
|
||||
#include "data.h"
|
||||
#include "lexer.h"
|
||||
|
||||
node_t *parse_atom(lexer_t *lexer, token_t *token);
|
||||
node_t *parse_function_call(lexer_t *lexer, const char *function_name);
|
||||
node_t *parse_statement(lexer_t *lexer);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user