summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-28 10:22:23 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-05-28 10:23:43 (GMT)
commita8e67c64aa6932f11fb81d5c3dd7ae613721edb8 (patch) (side-by-side diff)
tree6fcdb1101560ef8f612f64764294d5e0a5a2522e /src
parent8893389e6bbd27b03d77b7ffa63061e543e8df09 (diff)
downloadgrecs-a8e67c64aa6932f11fb81d5c3dd7ae613721edb8.tar.gz
grecs-a8e67c64aa6932f11fb81d5c3dd7ae613721edb8.tar.bz2
Accept empty input files.
* src/bind-gram.y: Input may be empty. * src/grecs-gram.y: Likewise. * src/meta1-gram.y: Likewise. * tests/empty.at: New test. * tests/Makefile.am: Add new testcase. * tests/testsuite.at: Add new testcase.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/bind-gram.y17
-rw-r--r--src/grecs-gram.y17
-rw-r--r--src/meta1-gram.y17
3 files changed, 42 insertions, 9 deletions
diff --git a/src/bind-gram.y b/src/bind-gram.y
index 5acc780..7259e5d 100644
--- a/src/bind-gram.y
+++ b/src/bind-gram.y
@@ -55,17 +55,28 @@ static struct grecs_value *stmtlist_to_value(struct grecs_node *node);
%type <svalue> value ctlsub
%type <pvalue> vallist tag
%type <list> vlist ctllist
-%type <node> stmt simple block
+%type <node> stmt simple block maybe_stmtlist
%type <node_list> stmtlist
%%
-input : stmtlist
+input : maybe_stmtlist
{
parse_tree = grecs_node_create(grecs_node_root,
&grecs_current_locus);
parse_tree->v.texttab = grecs_text_table();
- grecs_node_bind(parse_tree, $1.head, 1);
+ grecs_node_bind(parse_tree, $1, 1);
+ }
+ ;
+
+maybe_stmtlist:
+ /* empty */
+ {
+ $$ = NULL;
+ }
+ | stmtlist
+ {
+ $$ = $1.head;
}
;
diff --git a/src/grecs-gram.y b/src/grecs-gram.y
index 3452074..bbe3d5e 100644
--- a/src/grecs-gram.y
+++ b/src/grecs-gram.y
@@ -51,17 +51,28 @@ static struct grecs_node *parse_tree;
%type <svalue> value
%type <pvalue> vallist tag
%type <list> values list vlist
-%type <node> stmt simple block
+%type <node> stmt simple block maybe_stmtlist
%type <node_list> stmtlist
%%
-input : stmtlist
+input : maybe_stmtlist
{
parse_tree = grecs_node_create(grecs_node_root,
&grecs_current_locus);
parse_tree->v.texttab = grecs_text_table();
- grecs_node_bind(parse_tree, $1.head, 1);
+ grecs_node_bind(parse_tree, $1, 1);
+ }
+ ;
+
+maybe_stmtlist:
+ /* empty */
+ {
+ $$ = NULL;
+ }
+ | stmtlist
+ {
+ $$ = $1.head;
}
;
diff --git a/src/meta1-gram.y b/src/meta1-gram.y
index 2983221..455c362 100644
--- a/src/meta1-gram.y
+++ b/src/meta1-gram.y
@@ -43,7 +43,7 @@ extern int yy_flex_debug;
%token <ident> META1_IDENT
%token <string> META1_STRING
-%type <node> stmt simple block
+%type <node> stmt simple block maybe_stmtlist
%type <node_list> stmtlist
%type <pvalue> tag value
%type <string> string slist
@@ -51,12 +51,23 @@ extern int yy_flex_debug;
%type <list> values list
%%
-input : stmtlist
+input : maybe_stmtlist
{
parse_tree = grecs_node_create(grecs_node_root,
&grecs_current_locus);
parse_tree->v.texttab = grecs_text_table();
- grecs_node_bind(parse_tree, $1.head, 1);
+ grecs_node_bind(parse_tree, $1, 1);
+ }
+ ;
+
+maybe_stmtlist:
+ /* empty */
+ {
+ $$ = NULL;
+ }
+ | stmtlist
+ {
+ $$ = $1.head;
}
;

Return to:

Send suggestions and report system problems to the System administrator.