diff --git a/modules/appmodel/app-parser-generator.c b/modules/appmodel/app-parser-generator.c index 0fd1958cf6..ea7f9fb633 100644 --- a/modules/appmodel/app-parser-generator.c +++ b/modules/appmodel/app-parser-generator.c @@ -79,33 +79,58 @@ app_parser_generator_parse_arguments(AppObjectGenerator *s, CfgArgs *args, const } static void -_generate_filter(AppParserGenerator *self, const gchar *filter_expr) +_generate_at_line(GString *block, const CFG_LTYPE *lloc) { - if (filter_expr) - g_string_append_printf(self->block, - " filter {\n" - " %s\n" - " };\n", filter_expr); + if (lloc->first_column && lloc->first_line) + g_string_append_printf(block, + "@line \"%s\" %d %d\n", + lloc->name, lloc->first_line, lloc->first_column); + } static void -_generate_parser(AppParserGenerator *self, const gchar *parser_expr) +_generate_filter(AppParserGenerator *self, const Application *app) { - if (parser_expr) - g_string_append_printf(self->block, - " parser {\n" - " %s\n" - " };\n", parser_expr); + if (app->filter_expr) + { + g_string_append(self->block, + " filter {\n"); + _generate_at_line(self->block, &app->filter_lloc); + g_string_append_printf(self->block, + "%s\n" + "@line\n" + " };\n", app->filter_expr); + } } static void -_generate_filterx(AppParserGenerator *self, const gchar *filterx_expr) +_generate_parser(AppParserGenerator *self, const Application *app) { - if (filterx_expr) - g_string_append_printf(self->block, - " filterx {\n" - " %s\n" - " };\n", filterx_expr); + if (app->parser_expr) + { + g_string_append(self->block, + " parser {\n"); + _generate_at_line(self->block, &app->parser_lloc); + g_string_append_printf(self->block, + "%s\n" + "@line\n" + " };\n", app->parser_expr); + } +} + +static void +_generate_filterx(AppParserGenerator *self, const Application *app) +{ + if (app->filterx_expr) + { + g_string_append(self->block, + " filterx {\n"); + _generate_at_line(self->block, &app->filterx_lloc); + g_string_append_printf(self->block, + "%s\n" + "@line\n" + " };\n", app->filterx_expr); + } } static void @@ -163,9 +188,9 @@ _generate_application(Application *app, gpointer user_data) g_string_append_printf(self->block, " #Start Application %s\n", app->super.name); - _generate_filter(self, app->filter_expr); - _generate_parser(self, app->parser_expr); - _generate_filterx(self, app->filterx_expr); + _generate_filter(self, app); + _generate_parser(self, app); + _generate_filterx(self, app); _generate_action(self, app); g_string_append_printf(self->block, " #End Application %s\n", app->super.name); diff --git a/modules/appmodel/application.c b/modules/appmodel/application.c index 672ba4d8c9..cd741fb50d 100644 --- a/modules/appmodel/application.c +++ b/modules/appmodel/application.c @@ -24,24 +24,30 @@ #include "application.h" void -application_set_filter(Application *self, const gchar *filter_expr) +application_set_filter(Application *self, const gchar *filter_expr, CFG_LTYPE *lloc) { g_free(self->filter_expr); self->filter_expr = g_strdup(filter_expr); + if (lloc) + self->filter_lloc = *lloc; } void -application_set_parser(Application *self, const gchar *parser_expr) +application_set_parser(Application *self, const gchar *parser_expr, CFG_LTYPE *lloc) { g_free(self->parser_expr); self->parser_expr = g_strdup(parser_expr); + if (lloc) + self->parser_lloc = *lloc; } void -application_set_filterx(Application *self, const gchar *filterx_expr) +application_set_filterx(Application *self, const gchar *filterx_expr, CFG_LTYPE *lloc) { g_free(self->filterx_expr); self->filterx_expr = g_strdup(filterx_expr); + if (lloc) + self->filterx_lloc = *lloc; } static void diff --git a/modules/appmodel/application.h b/modules/appmodel/application.h index 944f6c63a0..dfa06da82c 100644 --- a/modules/appmodel/application.h +++ b/modules/appmodel/application.h @@ -25,6 +25,7 @@ #define APPMODEL_APPLICATION_H_INCLUDED #include "appmodel-context.h" +#include "cfg-lexer.h" #define APPLICATION_TYPE_NAME "application" @@ -34,11 +35,14 @@ typedef struct _Application gchar *filter_expr; gchar *parser_expr; gchar *filterx_expr; + CFG_LTYPE filter_lloc; + CFG_LTYPE parser_lloc; + CFG_LTYPE filterx_lloc; } Application; -void application_set_filter(Application *self, const gchar *filter_expr); -void application_set_parser(Application *self, const gchar *parser_expr); -void application_set_filterx(Application *self, const gchar *parser_expr); +void application_set_filter(Application *self, const gchar *filter_expr, CFG_LTYPE *lloc); +void application_set_parser(Application *self, const gchar *parser_expr, CFG_LTYPE *lloc); +void application_set_filterx(Application *self, const gchar *parser_expr, CFG_LTYPE *lloc); Application *application_new(const gchar *name, const gchar *topic); diff --git a/modules/appmodel/appmodel-grammar.ym b/modules/appmodel/appmodel-grammar.ym index d368c9c33c..78d2600e69 100644 --- a/modules/appmodel/appmodel-grammar.ym +++ b/modules/appmodel/appmodel-grammar.ym @@ -92,9 +92,9 @@ application_options ; application_option - : KW_FILTER _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_filter($0, $3); free($3); } - | KW_PARSER _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_parser($0, $3); free($3); } - | KW_FILTERX _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_filterx($0, $3); free($3); } + : KW_FILTER _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_filter($0, $3, &@3); free($3); } + | KW_PARSER _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_parser($0, $3, &@3); free($3); } + | KW_FILTERX _block_content_context_push LL_BLOCK _block_content_context_pop { application_set_filterx($0, $3, &@3); free($3); } ; diff --git a/modules/appmodel/tests/test_application.c b/modules/appmodel/tests/test_application.c index a7e02c322a..a91f79d157 100644 --- a/modules/appmodel/tests/test_application.c +++ b/modules/appmodel/tests/test_application.c @@ -40,10 +40,10 @@ Test(application, filter_can_be_set_and_queried) const gchar *filter_expr2 = "'2' eq '2'"; app = application_new("foobar", "*"); - application_set_filter(app, filter_expr); + application_set_filter(app, filter_expr, NULL); cr_assert_str_eq(app->filter_expr, filter_expr); - application_set_filter(app, filter_expr2); + application_set_filter(app, filter_expr2, NULL); cr_assert_str_eq(app->filter_expr, filter_expr2); appmodel_object_free(&app->super); } @@ -55,10 +55,10 @@ Test(application, parser_can_be_set_and_queried) const gchar *parser_expr2 = "csv-parser();"; app = application_new("foobar", "*"); - application_set_parser(app, parser_expr); + application_set_parser(app, parser_expr, NULL); cr_assert_str_eq(app->parser_expr, parser_expr); - application_set_parser(app, parser_expr2); + application_set_parser(app, parser_expr2, NULL); cr_assert_str_eq(app->parser_expr, parser_expr2); appmodel_object_free(&app->super); }