[template-glib] expr: handle ; specially



commit 178c7613d43df5b657aa00f9eeac8761bb6fbb61
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 4 16:24:55 2022 -0700

    expr: handle ; specially
    
    It turned out to be too much effort to treat it as EOL.

 src/tmpl-expr-parser.y  | 17 +++++++++++++++++
 src/tmpl-expr-scanner.l |  2 +-
 tests/test1.script      |  1 -
 3 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/src/tmpl-expr-parser.y b/src/tmpl-expr-parser.y
index 9e1e0bc..913d189 100644
--- a/src/tmpl-expr-parser.y
+++ b/src/tmpl-expr-parser.y
@@ -133,14 +133,28 @@ expr: /* nothing */ EOL {
     add_expr_to_parser (parser, $1);
     YYACCEPT;
   }
+  | stmt ';' {
+    add_expr_to_parser (parser, $1);
+    YYACCEPT;
+  }
+
   | FUNC NAME '(' symlist ')' '=' list EOL {
     define_function (parser, $2, g_steal_pointer (&$4), $7);
     YYACCEPT;
   }
+  | FUNC NAME '(' symlist ')' '=' list ';' {
+    define_function (parser, $2, g_steal_pointer (&$4), $7);
+    YYACCEPT;
+  }
+
   | FUNC NAME '(' ')' '=' list EOL {
     define_function (parser, $2, NULL, $6);
     YYACCEPT;
   }
+  | FUNC NAME '(' ')' '=' list ';' {
+    define_function (parser, $2, NULL, $6);
+    YYACCEPT;
+  }
 ;
 
 stmt: IF exp THEN list {
@@ -156,6 +170,9 @@ stmt: IF exp THEN list {
 ;
 
 list: /* nothing */ { $$ = NULL; }
+  | stmt ';' list {
+    $$ = add_to_list ($1, $3);
+  }
   | stmt EOL list {
     $$ = add_to_list ($1, $3);
   }
diff --git a/src/tmpl-expr-scanner.l b/src/tmpl-expr-scanner.l
index d334a9b..e124f54 100644
--- a/src/tmpl-expr-scanner.l
+++ b/src/tmpl-expr-scanner.l
@@ -53,6 +53,7 @@ TmplExprParser *parser = yyextra;
 "," |
 "." |
 "!" |
+";" |
 "(" |
 ")" { return yytext [0]; }
 
@@ -121,7 +122,6 @@ L?\"(\\.|[^\\"])*\" { yylval->s = copy_literal (yytext); return STRING_LITERAL;
 [ \t]   /* ignore whitespace */
 #[^\n]* { return EOL; } /* line-wise comments should EOL things */
 "\n"    { return EOL; }
-";"     { return EOL; }
 <<EOF>> { parser->reached_eof = TRUE; return EOL; }
 .       {
           g_free (parser->error_str);
diff --git a/tests/test1.script b/tests/test1.script
index 5523f40..18385eb 100644
--- a/tests/test1.script
+++ b/tests/test1.script
@@ -36,6 +36,5 @@ assert(multiply(-10, 10) == -100)
 func nop() = pass
 nop()
 
-;;;
 
 1234;


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