[augeas-devel] augeas: master - * src/parser.y: do not allow epsilon as a tree constant

David Lutterkort lutter at fedoraproject.org
Fri Feb 20 18:14:44 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=e6ebc1c7fabb4da598ff516b77903f8beef12ebb
Commit:        e6ebc1c7fabb4da598ff516b77903f8beef12ebb
Parent:        5ab6b8b1ce374039ad20c6844a929f0d00c2addb
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Thu Feb 19 23:12:38 2009 -0800
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Thu Feb 19 23:12:38 2009 -0800

* src/parser.y: do not allow epsilon as a tree constant

This grammar mistake made epsilon a valid expression
---
 src/parser.y                      |   21 ++++++++++++---------
 tests/modules/fail_let_no_exp.aug |    4 ++++
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/parser.y b/src/parser.y
index 519be9f..9230a29 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -65,9 +65,6 @@ typedef struct info YYLTYPE;
 %token          KW_LENS
 %token          KW_TEST KW_GET KW_PUT KW_AFTER
 
-/* Conflicts caused by the binding let decl vs the let expression */
-%expect 3
-
 %union {
   struct term     *term;
   struct type    *type;
@@ -86,7 +83,7 @@ typedef struct info YYLTYPE;
 %type<quant> rep
 %type<term>  test_exp
 %type<intval> test_special_res
-%type<tree>  tree_const tree_branch
+%type<tree>  tree_const tree_const2 tree_branch
 %type<string> tree_label
 
 %{
@@ -282,18 +279,23 @@ atype: KW_STRING
      | '(' type ')'
        { $$ = $2; }
 
-tree_const: '{' tree_branch '}' tree_const
+tree_const: tree_const '{' tree_branch '}'
+            { $$ = tree_concat($1, $3); }
+          | '{' tree_branch '}'
+            { $$ = tree_concat($2, NULL); }
+
+tree_const2: tree_const2 '{' tree_branch '}'
             {
-              $$ = tree_concat($2, $4);
+              $$ = tree_concat($1, $3);
             }
           | /* empty */
             { $$ = NULL; }
 
-tree_branch: tree_label tree_const
+tree_branch: tree_label tree_const2
              {
                $$ = make_tree($1, NULL, NULL, $2);
              }
-           | tree_label '=' DQUOTED tree_const
+           | tree_label '=' DQUOTED tree_const2
              {
                $$ = make_tree($1, $3, NULL, $4);
              }
@@ -486,7 +488,8 @@ static struct term *make_tree_value(struct tree *tree, struct info *locp) {
 }
 
 static struct tree *tree_concat(struct tree *t1, struct tree *t2) {
-  list_append(t1, t2);
+  if (t2 != NULL)
+    list_append(t1, t2);
   return t1;
 }
 
diff --git a/tests/modules/fail_let_no_exp.aug b/tests/modules/fail_let_no_exp.aug
new file mode 100644
index 0000000..cfb3f70
--- /dev/null
+++ b/tests/modules/fail_let_no_exp.aug
@@ -0,0 +1,4 @@
+module Fail_let_no_exp =
+
+  (* This used to be accepted because of a grammar bug *)
+  let x =




More information about the augeas-devel mailing list