[template-glib] expr-parser: cleanup stmt list creation
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] expr-parser: cleanup stmt list creation
- Date: Wed, 4 May 2022 20:48:22 +0000 (UTC)
commit 017265206790a9b10fb8eaaafcefe49bfebad81e
Author: Christian Hergert <chergert redhat com>
Date: Wed May 4 13:47:58 2022 -0700
expr-parser: cleanup stmt list creation
So that we can use this in more ways without duplication.
src/tmpl-expr-parser.y | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/src/tmpl-expr-parser.y b/src/tmpl-expr-parser.y
index 95b1308..5e4cdcb 100644
--- a/src/tmpl-expr-parser.y
+++ b/src/tmpl-expr-parser.y
@@ -82,6 +82,24 @@ define_function (TmplExprParser *parser,
add_expr_to_parser (parser, tmpl_expr_new_func (name, strv, list));
}
+static TmplExpr *
+add_to_list (TmplExpr *stmt,
+ TmplExpr *list)
+{
+ g_assert (stmt != NULL);
+
+ if (list == NULL)
+ {
+ GPtrArray *ar = g_ptr_array_new_with_free_func ((GDestroyNotify)tmpl_expr_unref);
+ g_ptr_array_add (ar, stmt);
+ return tmpl_expr_new_stmt_list (ar);
+ }
+
+ g_assert (list->any.type == TMPL_EXPR_STMT_LIST);
+ g_ptr_array_add (list->stmt_list.stmts, stmt);
+ return list;
+}
+
# define scanner parser->scanner
%}
@@ -139,17 +157,7 @@ stmt: IF exp THEN list {
list: /* nothing */ { $$ = NULL; }
| stmt ';' list {
- if ($3 == NULL)
- { $$ = $1; }
- else if ($1->any.type == TMPL_EXPR_STMT_LIST)
- { g_ptr_array_add ($1->stmt_list.stmts, $3); }
- else
- {
- GPtrArray *ar = g_ptr_array_new_with_free_func ((GDestroyNotify)tmpl_expr_unref);
- g_ptr_array_add (ar, $1);
- g_ptr_array_add (ar, $3);
- $$ = tmpl_expr_new_stmt_list (ar);
- }
+ $$ = add_to_list ($1, $3);
}
;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]