summaryrefslogtreecommitdiffstats
path: root/parser.y
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-06-20 07:49:04 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-06-20 07:49:04 -0700
commit5b0ee1a4dcdad30c4554a9aaa17600ae3e8073d7 (patch)
tree8bd7d2af63b3985673c54ce6d18a2f91795333a9 /parser.y
parent61a72064b0269ff3443fff3bfbe098de458605ca (diff)
downloadtxr-5b0ee1a4dcdad30c4554a9aaa17600ae3e8073d7.tar.gz
txr-5b0ee1a4dcdad30c4554a9aaa17600ae3e8073d7.tar.bz2
txr-5b0ee1a4dcdad30c4554a9aaa17600ae3e8073d7.zip
Bugfix: macros not being expanded in expansions embedded in
quasilierals: i.e. the forms X and Y in `@{X}` and `@{X Y}`, where X and Y can be Lisp symbol macros or compound forms that is a macro call. * eval.c (expand_quasi): Handle the var forms in a quasi. * parser.y (n_exprs_opt, q_var): New grammar nonterminals. q_var is a clone of o_var, but with different construction behavior. It fixes the bug that o_var applies expand_meta to embedded Lisp forms, which is not appropriate for TXR Lisp quasiliterals. (quasi_item): Derive q_var rather than o_var.
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y26
1 files changed, 23 insertions, 3 deletions
diff --git a/parser.y b/parser.y
index 1266157d..be8e6063 100644
--- a/parser.y
+++ b/parser.y
@@ -95,10 +95,10 @@ static val parsed_spec;
%type <val> if_clause elif_clauses_opt else_clause_opt
%type <val> line elems_opt elems clause_parts_h additional_parts_h
%type <val> text texts elem var var_op modifiers vector hash
-%type <val> list exprs exprs_opt expr n_exprs n_expr
+%type <val> list exprs exprs_opt expr n_exprs n_expr n_exprs_opt
%type <val> out_clauses out_clauses_opt out_clause
%type <val> repeat_clause repeat_parts_opt o_line
-%type <val> o_elems_opt o_elems o_elem o_var rep_elem rep_parts_opt
+%type <val> o_elems_opt o_elems o_elem o_var q_var rep_elem rep_parts_opt
%type <val> regex lisp_regex regexpr regbranch
%type <val> regterm regtoken regclass regclassterm regrange
%type <val> strlit chrlit quasilit quasi_items quasi_item litchars wordslit
@@ -701,6 +701,22 @@ o_var : SYMTOK { $$ = list(var_s, sym_helper($1, nil), nao);
yybadtoken(yychar, lit("variable spec")); }
;
+q_var : SYMTOK { $$ = list(var_s, sym_helper($1, nil), nao);
+ rl($$, num(lineno)); }
+ | SYMTOK quasi_item { $$ = list(var_s, sym_helper($1, nil),
+ $2, nao);
+ rl($$, num(lineno)); }
+ | '{' n_expr n_exprs_opt '}'
+ { $$ = list(var_s, $2, nil, $3, nao);
+ rl($$, num(lineno)); }
+ | '{' n_expr n_exprs_opt '}' quasi_item
+ { $$ = list(var_s, $2, $5, $3, nao);
+ rl($$, num(lineno)); }
+ | SYMTOK error { $$ = nil;
+ yybadtoken(yychar, lit("variable spec")); }
+ ;
+
+
vector : '#' list { if (unquotes_occur($2, 0))
$$ = rlcp(cons(vector_lit_s,
cons($2, nil)), $2);
@@ -783,6 +799,10 @@ n_expr : SYMTOK { $$ = sym_helper($1, t); }
| SPLICE n_expr { $$ = rlcp(list(sys_splice_s, $2, nao), $2); }
;
+n_exprs_opt : n_exprs { $$ = $1; }
+ | /* empty */ { $$ = nil; }
+ ;
+
regex : '/' regexpr '/' { $$ = cons(regex_s, $2); end_of_regex();
rl($$, num(lineno)); }
| '/' error { $$ = nil;
@@ -926,7 +946,7 @@ quasi_items : quasi_item { $$ = cons($1, nil);
quasi_item : litchars { $$ = lit_char_helper($1); }
| TEXT { $$ = string_own($1); }
- | o_var { $$ = $1; }
+ | q_var { $$ = $1; }
| METANUM { $$ = cons(var_s, cons($1, nil));
rl($$, num(lineno)); }
| list { $$ = rlcp(cons(expr_s, $1), $1); }