[template-glib] expr: allow "pass" as a no-op



commit 9acc0a76ec2e97797585c2c1f91a1ef764e2f195
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 4 15:33:49 2022 -0700

    expr: allow "pass" as a no-op

 src/tmpl-expr-parser.y  | 5 ++++-
 src/tmpl-expr-scanner.l | 1 +
 tests/test1.script      | 5 ++++-
 3 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/src/tmpl-expr-parser.y b/src/tmpl-expr-parser.y
index 37926cf..e2321d7 100644
--- a/src/tmpl-expr-parser.y
+++ b/src/tmpl-expr-parser.y
@@ -109,8 +109,8 @@ add_to_list (TmplExpr *stmt,
 %token <fn> BUILTIN
 %token <s> REQUIRE VERSION
 %token EOL
-
 %token IF THEN ELSE WHILE DO FUNC
+%token NOP
 
 %nonassoc <cmp> CMP
 %right '='
@@ -233,6 +233,9 @@ exp: exp CMP exp {
   | '!' exp {
     $$ = tmpl_expr_new_invert_boolean ($2);
   }
+  | NOP {
+    $$ = tmpl_expr_new_nop ();
+  }
   | REQUIRE NAME {
     $$ = tmpl_expr_new_require ($2, NULL);
     g_free ($2);
diff --git a/src/tmpl-expr-scanner.l b/src/tmpl-expr-scanner.l
index c6c240f..84fc7db 100644
--- a/src/tmpl-expr-scanner.l
+++ b/src/tmpl-expr-scanner.l
@@ -75,6 +75,7 @@ TmplExprParser *parser = yyextra;
 "func"     { return FUNC; }
 "require"  { return REQUIRE; }
 "version"  { return VERSION; }
+"pass"     { return NOP; }
 
 "true"     { yylval->b = 1; return BOOL; }
 "false"    { yylval->b = 0; return BOOL; }
diff --git a/tests/test1.script b/tests/test1.script
index d4e4639..f39ef03 100644
--- a/tests/test1.script
+++ b/tests/test1.script
@@ -23,8 +23,11 @@ assert(abc != "def")
 func pow(a,b) = while b > 1 do a = a * a; b = b - 1;
 assert(pow(2,3) == 8)
 assert(pow(2,3) == 8) # and here
-func multiply(x,y) = x * y;
+func multiply(x,y) = x * y
 assert(multiply(10, 10) == 100)
 assert(multiply(-10, 10) == -100)
 
+func nop() = pass
+nop()
+
 1234;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]