From 7605180a0abf4b121f432bfbdcca2b1d3e07e62f Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Sun, 22 Oct 2023 19:46:16 +0200 Subject: [PATCH] appmodel: add support for parsing Transformations Signed-off-by: Balazs Scheidler --- modules/appmodel/appmodel-grammar.ym | 49 ++++++++++++++++++++++++++++ modules/appmodel/appmodel-parser.c | 5 ++- modules/appmodel/appmodel-plugin.c | 5 +++ modules/appmodel/appmodel.c | 15 +++++++++ modules/appmodel/appmodel.h | 4 +++ 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/modules/appmodel/appmodel-grammar.ym b/modules/appmodel/appmodel-grammar.ym index 928c29aee5d..d368c9c33c7 100644 --- a/modules/appmodel/appmodel-grammar.ym +++ b/modules/appmodel/appmodel-grammar.ym @@ -48,8 +48,12 @@ /* INCLUDE_DECLS */ %token KW_APPLICATION +%token KW_TRANSFORMATION +%token KW_TRANSFORM +%token KW_STEP %type application_definition +%type transformation_definition %% @@ -60,6 +64,12 @@ start *instance = $2; YYACCEPT; } + | LL_CONTEXT_ROOT transformation_definition + { + appmodel_register_transformation(configuration, $2); + *instance = $2; + YYACCEPT; + } ; @@ -87,6 +97,45 @@ application_option | KW_FILTERX _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_filterx($0, $3); free($3); } ; + +transformation_definition + : KW_TRANSFORMATION string '[' string ']' + { + $$ = transformation_new($2, $4); + }[transformation] + '{' { $$ = $transformation; } transformation_options '}' + { + $$ = $transformation; + free($2); + free($4); + } + ; + +transformation_options + : transformation_option semicolons { $$ = $0; } transformation_options + | + ; + +/* $0 is Transformation */ +transformation_option + : KW_TRANSFORM '[' string ']' '{' { $$ = transformation_block_new($3); } transformation_steps '}' + { free($3); transformation_add_block($0, $6); } + ; + +/* $0 is TransformationBlock */ +transformation_steps + : transformation_step semicolons { $$ = $0; } transformation_steps + | + ; + +/* $0 is TransformationBlock */ +transformation_step + : KW_STEP '[' string ']' _block_content_context_push LL_BLOCK _block_content_context_pop + { + transformation_block_add_step($0, $3, $6); free($3); free($6); + } + ; + /* INCLUDE_RULES */ %% diff --git a/modules/appmodel/appmodel-parser.c b/modules/appmodel/appmodel-parser.c index c72c14edbc2..29310fc6b80 100644 --- a/modules/appmodel/appmodel-parser.c +++ b/modules/appmodel/appmodel-parser.c @@ -31,7 +31,10 @@ int appmodel_parse(CfgLexer *lexer, gpointer *instance, gpointer arg); static CfgLexerKeyword appmodel_keywords[] = { - { "application", KW_APPLICATION }, + { "application", KW_APPLICATION }, + { "transformation", KW_TRANSFORMATION }, + { "transform", KW_TRANSFORM }, + { "step", KW_STEP }, { NULL } }; diff --git a/modules/appmodel/appmodel-plugin.c b/modules/appmodel/appmodel-plugin.c index 7bd86922618..03ed0d2f592 100644 --- a/modules/appmodel/appmodel-plugin.c +++ b/modules/appmodel/appmodel-plugin.c @@ -43,6 +43,11 @@ static Plugin appmodel_plugins[] = .name = "application", .parser = &appmodel_parser, }, + { + .type = LL_CONTEXT_ROOT, + .name = "transformation", + .parser = &appmodel_parser, + }, { .type = LL_CONTEXT_PARSER | LL_CONTEXT_FLAG_GENERATOR, .name = "app-parser", diff --git a/modules/appmodel/appmodel.c b/modules/appmodel/appmodel.c index e94aea13689..4118143d4f4 100644 --- a/modules/appmodel/appmodel.c +++ b/modules/appmodel/appmodel.c @@ -53,3 +53,18 @@ appmodel_iter_applications(GlobalConfig *cfg, void (*foreach)(Application *app, AppModelContext *appmodel = appmodel_get_context(cfg); appmodel_context_iter_objects(appmodel, APPLICATION_TYPE_NAME, (AppModelContextIterFunc) foreach, user_data); } + +void +appmodel_register_transformation(GlobalConfig *cfg, Transformation *transformation) +{ + AppModelContext *ac = appmodel_get_context(cfg); + + appmodel_context_register_object(ac, &transformation->super); +} + +void +appmodel_iter_transformations(GlobalConfig *cfg, void (*foreach)(Transformation *transformation, gpointer user_data), gpointer user_data) +{ + AppModelContext *appmodel = appmodel_get_context(cfg); + appmodel_context_iter_objects(appmodel, TRANSFORMATION_TYPE_NAME, (AppModelContextIterFunc) foreach, user_data); +} diff --git a/modules/appmodel/appmodel.h b/modules/appmodel/appmodel.h index 34b0f3dd7e9..2b8aca7a431 100644 --- a/modules/appmodel/appmodel.h +++ b/modules/appmodel/appmodel.h @@ -25,6 +25,7 @@ #include "module-config.h" #include "application.h" +#include "transformation.h" AppModelContext *appmodel_get_context(GlobalConfig *cfg); void appmodel_register_application(GlobalConfig *cfg, Application *application); @@ -32,4 +33,7 @@ void appmodel_iter_applications(GlobalConfig *cfg, void (*foreach)(Application *app, gpointer user_data), gpointer user_data); +void appmodel_register_transformation(GlobalConfig *cfg, Transformation *transformation); +void appmodel_iter_transformations(GlobalConfig *cfg, void (*foreach)(Transformation *transformation, gpointer user_data), gpointer user_data); + #endif