commit e05c39ff3578c401277e36d0b6ccc5653666b471
parent 9825acafd8ec361f16a67151cad1d2c90f71bfdd
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Mon, 4 Mar 2024 23:18:40 +0000
Better naming for config sections
* Use prologue, grammar and epilogue
Diffstat:
5 files changed, 26 insertions(+), 27 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -3,7 +3,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(
Alec
- VERSION 1.0.4
+ VERSION 1.0.5
DESCRIPTION "Abstraction Layer for Escape Codes"
HOMEPAGE_URL https://git.dimitrijedobrota.com/alec.git
LANGUAGES C CXX
diff --git a/README.md b/README.md
@@ -136,9 +136,9 @@ and don't need to be called.
Configuration file `alec.rules.hpp` is used to customize the output of
`alec.hpp` file. Similarly to Flex and Bison, configuration files needs to have
-3 sections separated by `%%`. First and last sections are copied as-is to the
-output file whilst the second section contains rules for generating template
-and function code.
+3 sections separated by `%%`: prologue, grammar and epilogue. Prologue and
+epilogue are copied as-is to the output file whilst the grammar section
+contains rules for generating template and function code.
* Rules can be separated by an arbitrary number of blank lines.
* Everything can have arbitrary indentation that is not carried to the resulting file.
@@ -155,8 +155,7 @@ comma, or a single string literal
### Constraints
-* All constraints used in code generation must be defined in the first section of
-the config file.
+* All constraints used in code generation must be defined in the prologue
* Every constraint listed will be applied to all of the arguments one by one.
* Every constraint has to have a function and template concept variant with the
same name, but suffix _v for the template one.
diff --git a/src/generator.c b/src/generator.c
@@ -12,8 +12,8 @@ int yydebug = 1;
#endif
list_t records = {0};
-list_t after = {0};
-list_t before = {0};
+list_t epilogue = {0};
+list_t prologue = {0};
int main(const int argc, char *argv[]) {
if (argc < 2) {
@@ -34,8 +34,8 @@ int main(const int argc, char *argv[]) {
fclose(f);
}
- // print before section
- for (node_t *p = before.head; p; p = p->next) {
+ // print prologue section
+ for (node_t *p = prologue.head; p; p = p->next) {
printf("%s", p->data);
}
@@ -55,16 +55,16 @@ int main(const int argc, char *argv[]) {
record_print_function(r);
}
- // print after section
- for (node_t *p = after.head; p; p = p->next) {
+ // print epilogue section
+ for (node_t *p = epilogue.head; p; p = p->next) {
printf("%s", p->data);
}
list_free(&dupes, 0);
- list_free(&before, free);
+ list_free(&prologue, free);
list_free(&records, record_free);
- list_free(&after, free);
+ list_free(&epilogue, free);
yylex_destroy();
}
diff --git a/src/lexer.l b/src/lexer.l
@@ -15,7 +15,7 @@ LINE_END (\n|\r|\r\n)
"%%"{LINE_END} { BEGIN GEN; return SWITCH; }
-.*{LINE_END} { yylval.n = strdup(yytext); return BEFORE; }
+.*{LINE_END} { yylval.n = strdup(yytext); return PROLOGUE; }
<GEN>{LINE_END} { return EOL; }
<GEN>^[\t ]*{LINE_END} { return EOL; }
@@ -34,7 +34,7 @@ LINE_END (\n|\r|\r\n)
<GEN>"%%"{LINE_END} { BEGIN LAST; return SWITCH; }
-<LAST>.*{LINE_END} { yylval.n = strdup(yytext); return AFTER; }
+<LAST>.*{LINE_END} { yylval.n = strdup(yytext); return EPILOGUE; }
%%
diff --git a/src/parser.y b/src/parser.y
@@ -4,7 +4,7 @@
}
%define api.value.type union
-%token <char *> n LITERAL COMMENT BEFORE AFTER
+%token <char *> n LITERAL COMMENT PROLOGUE EPILOGUE
%type <record_t *> record
%type <list_t *> list items
@@ -19,8 +19,8 @@
int yylex_destroy(void);
extern list_t records;
- extern list_t after;
- extern list_t before;
+ extern list_t epilogue;
+ extern list_t prologue;
}
@@ -28,19 +28,19 @@
%%
-document: before mid after
+document: prologue grammar epilogue
-before: %empty
- | before BEFORE { list_append(&before, node_new($2)); }
+prologue: %empty
+ | prologue PROLOGUE { list_append(&prologue, node_new($2)); }
;
-after: SWITCH
- | after AFTER { list_append(&after, node_new($2)); }
+epilogue: SWITCH
+ | epilogue EPILOGUE { list_append(&epilogue, node_new($2)); }
;
-mid: SWITCH
- | mid EOL
- | mid record { list_append(&records, node_new((char *)$2)); }
+grammar: SWITCH
+ | grammar EOL
+ | grammar record { list_append(&records, node_new((char *)$2)); }
;
record: name list list list { $$ = record_new($1, $2, $3, $4); }