Skip to content

Commit

Permalink
appmodel: add support for parsing Transformations
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed May 16, 2024
1 parent 8ede165 commit 7605180
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
49 changes: 49 additions & 0 deletions modules/appmodel/appmodel-grammar.ym
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@
/* INCLUDE_DECLS */

%token KW_APPLICATION
%token KW_TRANSFORMATION
%token KW_TRANSFORM
%token KW_STEP

%type <ptr> application_definition
%type <ptr> transformation_definition

%%

Expand All @@ -60,6 +64,12 @@ start
*instance = $2;
YYACCEPT;
}
| LL_CONTEXT_ROOT transformation_definition
{
appmodel_register_transformation(configuration, $2);
*instance = $2;
YYACCEPT;
}
;


Expand Down Expand Up @@ -87,6 +97,45 @@ application_option
| KW_FILTERX _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_filterx($<ptr>0, $3); free($3); }
;


transformation_definition
: KW_TRANSFORMATION string '[' string ']'
<ptr>{
$$ = transformation_new($2, $4);
}[transformation]
'{' <ptr>{ $$ = $transformation; } transformation_options '}'
{
$$ = $transformation;
free($2);
free($4);
}
;

transformation_options
: transformation_option semicolons { $<ptr>$ = $<ptr>0; } transformation_options
|
;

/* $0 is Transformation */
transformation_option
: KW_TRANSFORM '[' string ']' '{' { $<ptr>$ = transformation_block_new($3); } transformation_steps '}'
{ free($3); transformation_add_block($<ptr>0, $<ptr>6); }
;

/* $0 is TransformationBlock */
transformation_steps
: transformation_step semicolons { $<ptr>$ = $<ptr>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($<ptr>0, $3, $6); free($3); free($6);
}
;

/* INCLUDE_RULES */

%%
5 changes: 4 additions & 1 deletion modules/appmodel/appmodel-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};

Expand Down
5 changes: 5 additions & 0 deletions modules/appmodel/appmodel-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions modules/appmodel/appmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 4 additions & 0 deletions modules/appmodel/appmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@

#include "module-config.h"
#include "application.h"
#include "transformation.h"

AppModelContext *appmodel_get_context(GlobalConfig *cfg);
void appmodel_register_application(GlobalConfig *cfg, Application *application);
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

0 comments on commit 7605180

Please sign in to comment.