[template-glib] expr: add def/end style function blocks
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] expr: add def/end style function blocks
- Date: Thu, 5 May 2022 00:51:50 +0000 (UTC)
commit c3fc66c6b2b6a86961139bbc7a2487d2c4b35e0e
Author: Christian Hergert <chergert redhat com>
Date: Wed May 4 16:29:06 2022 -0700
expr: add def/end style function blocks
We might want to drop names from func as well but we'll see.
src/tmpl-expr-parser.y | 27 +++++++++++++++++++++++++++
src/tmpl-expr-scanner.l | 2 ++
tests/test1.script | 12 ++++++++++++
3 files changed, 41 insertions(+)
---
diff --git a/src/tmpl-expr-parser.y b/src/tmpl-expr-parser.y
index 913d189..0bbde8c 100644
--- a/src/tmpl-expr-parser.y
+++ b/src/tmpl-expr-parser.y
@@ -109,6 +109,7 @@ add_to_list (TmplExpr *stmt,
%token <fn> BUILTIN
%token <s> REQUIRE VERSION
%token EOL
+%token DEF END
%token IF THEN ELSE WHILE DO FUNC
%token NOP
@@ -155,6 +156,32 @@ expr: /* nothing */ EOL {
define_function (parser, $2, NULL, $6);
YYACCEPT;
}
+
+ | DEF NAME '(' ')' EOL list END {
+ define_function (parser, $2, NULL, $6);
+ YYACCEPT;
+ }
+ | DEF NAME '(' ')' list END {
+ define_function (parser, $2, NULL, $5);
+ YYACCEPT;
+ }
+ | DEF NAME '(' ')' EOL END {
+ define_function (parser, $2, NULL, NULL);
+ YYACCEPT;
+ }
+
+ | DEF NAME '(' symlist ')' EOL list END {
+ define_function (parser, $2, $4, $7);
+ YYACCEPT;
+ }
+ | DEF NAME '(' symlist ')' list END {
+ define_function (parser, $2, $4, $6);
+ YYACCEPT;
+ }
+ | DEF NAME '(' symlist ')' EOL END {
+ define_function (parser, $2, $4, NULL);
+ YYACCEPT;
+ }
;
stmt: IF exp THEN list {
diff --git a/src/tmpl-expr-scanner.l b/src/tmpl-expr-scanner.l
index e124f54..fc8f7a9 100644
--- a/src/tmpl-expr-scanner.l
+++ b/src/tmpl-expr-scanner.l
@@ -74,6 +74,8 @@ TmplExprParser *parser = yyextra;
"while" { return WHILE; }
"do" { return DO; }
"func" { return FUNC; }
+"def" { return DEF; }
+"end" { return END; }
"require" { return REQUIRE; }
"version" { return VERSION; }
"pass" { return NOP; }
diff --git a/tests/test1.script b/tests/test1.script
index 18385eb..a8f256f 100644
--- a/tests/test1.script
+++ b/tests/test1.script
@@ -36,5 +36,17 @@ assert(multiply(-10, 10) == -100)
func nop() = pass
nop()
+def order2(a,b) assert(a==1); assert(b==2); end
+order2(1,2)
+
+def order3(a,b,c)
+ assert(a == 1)
+ assert(b == 2)
+ assert(c == 3)
+end
+order3(1,2,3)
+
+def weird1(a) assert(a==1)
+end
1234;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]