summaryrefslogtreecommitdiffstats
path: root/parser.y
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-04-08 07:00:40 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-04-08 07:00:40 -0700
commit44638912c7353e46c5d2d9b6fe9362f662809f02 (patch)
tree8304aa7454f852e7dd910822ebb9e5a43bed9a67 /parser.y
parentc4eb7f17cf2912575d483b21a0021375f23553cb (diff)
downloadtxr-44638912c7353e46c5d2d9b6fe9362f662809f02.tar.gz
txr-44638912c7353e46c5d2d9b6fe9362f662809f02.tar.bz2
txr-44638912c7353e46c5d2d9b6fe9362f662809f02.zip
parser: add some error cases to hash notations.
Produce better diagnostics for expressions like #[... or #Habc. * parser.y (vector, hash, struct, range): Add error productions.
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y10
1 files changed, 9 insertions, 1 deletions
diff --git a/parser.y b/parser.y
index 11664604..df054f95 100644
--- a/parser.y
+++ b/parser.y
@@ -818,6 +818,8 @@ vector : '#' list { if (unquotes_occur($2, 0))
cons($2, nil)), $2);
else
$$ = rlcp(vec_list($2), $2); }
+ | '#' error { $$ = nil;
+ yybadtok(yychar, lit("unassigned/reserved # notation")); }
;
hash : HASH_H list { if (unquotes_occur($2, 0))
@@ -826,6 +828,8 @@ hash : HASH_H list { if (unquotes_occur($2, 0))
$$ = rl(hash_construct(first($2),
rest($2)),
num($1)); }
+ | HASH_H error { $$ = nil;
+ yybadtok(yychar, lit("hash literal")); }
;
struct : HASH_S list { if (unquotes_occur($2, 0))
@@ -835,13 +839,17 @@ struct : HASH_S list { if (unquotes_occur($2, 0))
{ val strct = make_struct_lit(first($2),
rest($2));
$$ = rl(strct, num($1)); } }
+ | HASH_S error { $$ = nil;
+ yybadtok(yychar, lit("struct literal")); }
;
range : HASH_R list { if (length($2) != two)
yyerr("range literal needs two elements");
{ val range = rcons(first($2), second($2));
$$ = rl(range, num($1)); } }
- ;
+ | HASH_R error { $$ = nil;
+ yybadtok(yychar, lit("range literal")); }
+ ;
list : '(' n_exprs ')' { $$ = rl($2, num($1)); }
| '(' '.' n_exprs ')' { val a = car($3);