diff --git a/lib/filterx/expr-generator.c b/lib/filterx/expr-generator.c index 882c386113..33af41baec 100644 --- a/lib/filterx/expr-generator.c +++ b/lib/filterx/expr-generator.c @@ -22,6 +22,9 @@ */ #include "filterx/expr-generator.h" +#include "filterx/object-dict-interface.h" +#include "filterx/object-list-interface.h" +#include "filterx/filterx-eval.h" /* Takes reference of fillable */ void @@ -41,6 +44,21 @@ _eval(FilterXExpr *s) if (!fillable) return NULL; + if (fillable->readonly) + { + filterx_eval_push_error("cannot fill object: object is readonly", self, fillable); + filterx_object_unref(fillable); + return NULL; + } + + if (!filterx_object_is_type(fillable, &FILTERX_TYPE_NAME(dict)) && + !filterx_object_is_type(fillable, &FILTERX_TYPE_NAME(list))) + { + filterx_eval_push_error("cannot fill object: dict or list is expected", self, fillable); + filterx_object_unref(fillable); + return NULL; + } + if (self->generate(self, fillable)) return fillable; diff --git a/lib/filterx/filterx-grammar.ym b/lib/filterx/filterx-grammar.ym index c6cea683db..497d211cca 100644 --- a/lib/filterx/filterx-grammar.ym +++ b/lib/filterx/filterx-grammar.ym @@ -211,6 +211,7 @@ generator_assignment : expr '.' LL_IDENTIFIER KW_ASSIGN expr_generator { filterx_generator_set_fillable($5, filterx_getattr_new(filterx_expr_ref($1), $3)); + // filterx_expr_set_location($5, lexer, &@1); $$ = filterx_compound_expr_new_va(TRUE, filterx_setattr_new($1, $3, filterx_generator_create_container_new($5, $1)), @@ -222,6 +223,7 @@ generator_assignment | expr '[' expr ']' KW_ASSIGN expr_generator { filterx_generator_set_fillable($6, filterx_get_subscript_new(filterx_expr_ref($1), filterx_expr_ref($3))); + // filterx_expr_set_location($6, lexer, &@1); $$ = filterx_compound_expr_new_va(TRUE, filterx_set_subscript_new($1, $3, filterx_generator_create_container_new($6, $1)), @@ -233,6 +235,7 @@ generator_assignment { FilterXExpr *minus_one = filterx_literal_new(filterx_config_freeze_object(configuration, filterx_integer_new(-1))); filterx_generator_set_fillable($5, filterx_get_subscript_new(filterx_expr_ref($1), minus_one)); + // filterx_expr_set_location($5, lexer, &@1); $$ = filterx_compound_expr_new_va(TRUE, filterx_set_subscript_new($1, NULL, filterx_generator_create_container_new($5, $1)), @@ -245,9 +248,25 @@ generator_assignment ; generator_plus_assignment - : variable KW_PLUS_ASSIGN expr_generator { $$ = $3; filterx_generator_set_fillable($3, $1); } - | expr '[' expr ']' KW_PLUS_ASSIGN expr_generator { $$ = $6; filterx_generator_set_fillable($6, filterx_get_subscript_new($1, $3)); } - | expr '.' LL_IDENTIFIER KW_PLUS_ASSIGN expr_generator { $$ = $5; filterx_generator_set_fillable($5, filterx_getattr_new($1, $3)); free($3);} + : variable KW_PLUS_ASSIGN expr_generator + { + filterx_generator_set_fillable($3, $1); + // filterx_expr_set_location($3, lexer, &@1); + $$ = $3; + } + | expr '[' expr ']' KW_PLUS_ASSIGN expr_generator + { + filterx_generator_set_fillable($6, filterx_get_subscript_new($1, $3)); + // filterx_expr_set_location($6, lexer, &@1); + $$ = $6; + } + | expr '.' LL_IDENTIFIER KW_PLUS_ASSIGN expr_generator + { + filterx_generator_set_fillable($5, filterx_getattr_new($1, $3)); + // filterx_expr_set_location($5, lexer, &@1); + free($3); + $$ = $5; + } generator_casted_assignment /* TODO extract lvalues */ @@ -259,8 +278,12 @@ generator_casted_assignment filterx_generator_set_fillable($5, filterx_expr_ref($1)); + FilterXExpr *assign = filterx_assign_new($1, func); + assign->suppress_from_trace = TRUE; + ((FilterXExpr *) $5)->suppress_from_trace = TRUE; + $$ = filterx_compound_expr_new_va(TRUE, - filterx_assign_new($1, func), + assign, $5, NULL ); @@ -358,6 +381,7 @@ expr_value expr_generator : expr_generator_unchecked { $$ = $1; + filterx_expr_set_location($1, lexer, &@1); CHECK_ERROR($1, @1, "error initializing generator expression"); } ;