alec

Abstraction Layer for Escape Codes
git clone git://git.dimitrijedobrota.com/alec.git
Log | Files | Refs | README | LICENSE

commit 9825acafd8ec361f16a67151cad1d2c90f71bfdd
parent 386477550b0ec2d523464ba780be4693f1250a83
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon,  4 Mar 2024 23:12:04 +0000

Use api.value.type union

Diffstat:
MCMakeLists.txt | 2+-
Msrc/generator.c | 24++++++++++++------------
Msrc/generator.h | 1+
Msrc/parser.y | 19++++++++-----------
4 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -3,7 +3,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) project( Alec - VERSION 1.0.3 + VERSION 1.0.4 DESCRIPTION "Abstraction Layer for Escape Codes" HOMEPAGE_URL https://git.dimitrijedobrota.com/alec.git LANGUAGES C CXX diff --git a/src/generator.c b/src/generator.c @@ -11,9 +11,9 @@ int yydebug = 1; #endif -list_t records = { 0 }; -list_t after = { 0 }; -list_t before = { 0 }; +list_t records = {0}; +list_t after = {0}; +list_t before = {0}; int main(const int argc, char *argv[]) { if (argc < 2) { @@ -45,13 +45,13 @@ int main(const int argc, char *argv[]) { printf("\n/* Template compile-time variables */\n\n"); record_print_dupes(&dupes); for (node_t *p = records.head; p; p = p->next) { - const struct record *r = (const struct record *)p->data; + const record_t *r = (const record_t *)p->data; record_print_template(r, list_find(&dupes, r->name, scmp)); } printf("\n/* Run-time functions */\n\n"); for (node_t *p = records.head; p; p = p->next) { - const struct record *r = (const struct record *)p->data; + const record_t *r = (const record_t *)p->data; record_print_function(r); } @@ -109,11 +109,11 @@ void list_append(list_t *l, node_t *n) { l->tail = l->tail->next = n; } -struct record *record_new(char *name, list_t *args, list_t *rules, list_t *recipe) { - struct record *rec; +record_t *record_new(char *name, list_t *args, list_t *rules, list_t *recipe) { + record_t *rec; MALLOC(rec); - *rec = (struct record){ + *rec = (record_t){ .name = name, .args = args, .rules = rules, @@ -124,7 +124,7 @@ struct record *record_new(char *name, list_t *args, list_t *rules, list_t *recip } void record_free(void *rp) { - struct record *r = (struct record *)rp; + record_t *r = (record_t *)rp; if (r->args) list_free(r->args, free), free(r->args); if (r->rules) list_free(r->rules, free), free(r->rules); if (r->recipe) list_free(r->recipe, free), free(r->recipe); @@ -150,7 +150,7 @@ void record_print_dupes(const list_t *l) { printf("\n"); } -void record_print_function(const struct record *r) { +void record_print_function(const record_t *r) { list_t dummy = {0}; if (!r->recipe) { // comment @@ -194,7 +194,7 @@ void record_print_function(const struct record *r) { list_free(&dummy, NULL); } -void record_print_template(const struct record *r, int dup) { +void record_print_template(const record_t *r, int dup) { list_t dummy = {0}; if (!r->recipe) { // comment @@ -255,7 +255,7 @@ void record_dupes(list_t *d, list_t *l) { list_t s = {0}; for (node_t *p = records.head; p; p = p->next) { - const struct record *r = (const struct record *)p->data; + const record_t *r = (const record_t *)p->data; if (!list_find(&s, r->name, scmp)) list_append(&s, node_new(r->name)); else if (!list_find(d, r->name, scmp)) list_append(d, node_new(r->name)); diff --git a/src/generator.h b/src/generator.h @@ -10,6 +10,7 @@ void yyerror(char *s, ...); typedef struct node node_t; typedef struct list list_t; +typedef struct record record_t; struct node { char *data; diff --git a/src/parser.y b/src/parser.y @@ -3,11 +3,14 @@ #include <stdarg.h> } -%union { - struct record *r; - list_t *l; - char *n; -} +%define api.value.type union +%token <char *> n LITERAL COMMENT BEFORE AFTER + +%type <record_t *> record +%type <list_t *> list items +%type <char *> name + +%token EOL COMMA SWITCH EMPTY %code provides { int yylex(void); @@ -20,12 +23,6 @@ extern list_t before; } -%token <n> LITERAL COMMENT BEFORE AFTER -%token EOL COMMA SWITCH EMPTY - -%type <r> record -%type <l> list items -%type <n> name %start document