diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-11-26 08:40:22 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-11-26 08:40:22 -0800 |
commit | df9f85b3b720a9ebf7381b2cad7a9680ad0e31bf (patch) | |
tree | c7075648f15fda21e1eb313421206c4b8828f381 /parser.y | |
parent | 1f959abcf7cc1d18401d440b42761ac0b1babb78 (diff) | |
download | txr-df9f85b3b720a9ebf7381b2cad7a9680ad0e31bf.tar.gz txr-df9f85b3b720a9ebf7381b2cad7a9680ad0e31bf.tar.bz2 txr-df9f85b3b720a9ebf7381b2cad7a9680ad0e31bf.zip |
bugfix: quasilit read/print consistency, part 1.
The bug is that `@@@a` prints as `@@a` which
reads as a different object.
In this patch we simplify how quasiliterals are represented.
Embedded expressions are no longer (sys:expr E), just E.
Meta-numbers N and variables V are still (sys:var N).
However `@@a` and `@a` remain equivalent.
* eval.c (subst_vars): No need to look for expr_s;
just evaluate a compound form. The recursive nested
case is unnecessary and is removed.
(expand_quasi): Do nothandle expr_s; it is not
part of the quasi syntax any more.
* lib.c (out_quasi_str): Do not look for expr_s in the
quasi syntax; just print any expression with a @
the fallback case.
* match.c (tx_subst_vars): Analogous changes to those
done in subst_vars in eval.c.
* parser.y (quasi_meta_helper): Static function removed.
This was responsible for the issue due to stripping a
level of meta from expressions already having a meta
on them.
(quasi_item): In the `@` n_expr syntax case, no longer
call quasi_meta_helper. The remaining logic is simple
enough to put in line. Symbols and integers get wrapped
with (sys:var ...); other expressions are integrated
into the syntax as-is.
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 25 |
1 files changed, 5 insertions, 20 deletions
@@ -68,7 +68,6 @@ static val rlrec(parser_t *, val form, val line); static wchar_t char_from_name(const wchar_t *name); static val make_expr(parser_t *, val sym, val rest, val lineno); static val check_for_include(val spec_rev); -static val quasi_meta_helper(val obj); static void misplaced_consing_dot_check(scanner_t *scanner, val term_atom_cons); #if YYBISON @@ -1165,7 +1164,11 @@ quasi_item : litchars { $$ = lit_char_helper($1); } | q_var { $$ = $1; } | METANUM { $$ = cons(var_s, cons($1, nil)); rl($$, num(parser->lineno)); } - | '@' n_expr { $$ = quasi_meta_helper($2); } + | '@' n_expr { if (integerp($2) || symbolp($2)) + $$ = rlcp_tree(cons(var_s, cons($2, nil)), + $2); + else + $$ = $2; } ; litchars : LITCHAR { $$ = rl(cons(chr($1), nil), num(parser->lineno)); } @@ -1644,24 +1647,6 @@ static val check_for_include(val spec_rev) return spec_rev; } -static val quasi_meta_helper(val obj) -{ - if (integerp(obj) || symbolp(obj)) - goto var; - - if (atom(obj)) - goto expr; - - if (first(obj) == var_s || first(obj) == expr_s) - return obj; - -expr: - return rlcp(cons(expr_s, obj), obj); - -var: - return rlcp_tree(cons(var_s, cons(obj, nil)), obj); -} - static void misplaced_consing_dot_check(scanner_t *scanner, val term_atom_cons) { if (car(term_atom_cons) != unique_s) { |