summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-08-13 19:30:37 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-08-13 19:30:37 -0700
commitdc35aae3bfb0f5502d0848d9ad6478480a9ddd37 (patch)
tree8543064c549be0c395a66038ef8cd9914cafe0d8
parente05a39e67e5259263ecc4955f3efa8724d887e90 (diff)
downloadtxr-dc35aae3bfb0f5502d0848d9ad6478480a9ddd37.tar.gz
txr-dc35aae3bfb0f5502d0848d9ad6478480a9ddd37.tar.bz2
txr-dc35aae3bfb0f5502d0848d9ad6478480a9ddd37.zip
Uprooting stupidities in handling of output variables.
* parser.y (o_elems_transform): Remove useless function which was only unwrapping the strange parse of output vars. (o_elems_opt, rep_elem, quasilit, wordsqlit): Eliminate o_elems_transform call. (o_var, q_var): Eliminate the phrase structure rules which match an extra o_elem or quasi_item, and which incorporate them into the var syntax tree element. Place the modifiers into the third position, not fourth. * eval.c (subst_vars): Eliminate handling of "pat" element. Actually that was not even there thanks to o_elems_transform being applied: dead code. Pull modifiers from the third element of the var form now, not fourth. * match.c (subst_vars): Similar changes as in the match.c subst_vars function. Here the pat variable is even more obviously useless; if it is not nil, it is just punted back to the spec.
-rw-r--r--ChangeLog22
-rw-r--r--eval.c9
-rw-r--r--match.c6
-rw-r--r--parser.y64
4 files changed, 36 insertions, 65 deletions
diff --git a/ChangeLog b/ChangeLog
index ff2620bf..9100c380 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,27 @@
2014-08-13 Kaz Kylheku <kaz@kylheku.com>
+ Uprooting stupidities in handling of output variables.
+
+ * parser.y (o_elems_transform): Remove useless function which
+ was only unwrapping the strange parse of output vars.
+ (o_elems_opt, rep_elem, quasilit, wordsqlit): Eliminate
+ o_elems_transform call.
+ (o_var, q_var): Eliminate the phrase structure rules which
+ match an extra o_elem or quasi_item, and which incorporate
+ them into the var syntax tree element. Place the modifiers
+ into the third position, not fourth.
+
+ * eval.c (subst_vars): Eliminate handling of "pat"
+ element. Actually that was not even there thanks to
+ o_elems_transform being applied: dead code. Pull modifiers
+ from the third element of the var form now, not fourth.
+
+ * match.c (subst_vars): Similar changes as in the match.c
+ subst_vars function. Here the pat variable is even more obviously
+ useless; if it is not nil, it is just punted back to the spec.
+
+2014-08-13 Kaz Kylheku <kaz@kylheku.com>
+
Fix regression in previous change: we must match a compound text
element whole, and not break it up.
diff --git a/eval.c b/eval.c
index d9f1c51d..ae05adb0 100644
--- a/eval.c
+++ b/eval.c
@@ -1973,8 +1973,7 @@ static val subst_vars(val forms, val env)
if (sym == var_s) {
val expr = second(form);
- val pat = third(form);
- val modifiers = fourth(form);
+ val modifiers = third(form);
val str = eval(expr, env, form);
/* If the object is a list, we let format_field deal with the
@@ -1983,10 +1982,8 @@ static val subst_vars(val forms, val env)
if (!stringp(str) && !listp(str))
str = tostringp(str);
- if (pat) {
- forms = cons(str, cons(pat, rest(forms)));
- } else if (modifiers) {
- forms = cons(format_field(str, modifiers, nil,
+ if (modifiers) {
+ forms = cons(format_field(str, modifiers, nil,
curry_123_1(func_n3(eval), env, form)),
rest(forms));
} else {
diff --git a/match.c b/match.c
index 67d917ea..38e23b2c 100644
--- a/match.c
+++ b/match.c
@@ -1392,8 +1392,7 @@ static val subst_vars(val spec, val bindings, val filter)
if (sym == var_s) {
val expr = second(elem);
- val pat = third(elem);
- val modifiers = fourth(elem);
+ val modifiers = third(elem);
val str = txeval(spec, expr, bindings);
/* If the object is a list, we let format_field deal with the
@@ -1402,9 +1401,6 @@ static val subst_vars(val spec, val bindings, val filter)
if (!stringp(str) && !listp(str))
str = tostringp(str);
- if (pat)
- spec = cons(pat, rest(spec));
-
if (modifiers) {
spec = cons(format_field(str, modifiers, filter,
curry_123_2(func_n3(txeval), spec, bindings)),
diff --git a/parser.y b/parser.y
index b8fdbbd9..2e254954 100644
--- a/parser.y
+++ b/parser.y
@@ -49,7 +49,6 @@
static val sym_helper(void *scnr, wchar_t *lexeme, val meta_allowed);
static val repeat_rep_helper(val sym, val args, val main, val parts);
-static val o_elems_transform(val output_form);
static val define_transform(parser_t *parser, val define_form);
static val lit_char_helper(val litchars);
static val optimize_text(val text_form);
@@ -583,7 +582,7 @@ out_clauses_opt : out_clauses { $$ = $1; }
o_line : o_elems_opt '\n' { $$ = $1; }
;
-o_elems_opt : o_elems { $$ = o_elems_transform($1);
+o_elems_opt : o_elems { $$ = $1;
rl($$, num(parser->lineno)); }
| { $$ = nil; }
;
@@ -605,10 +604,7 @@ o_elem : TEXT { $$ = string_own($1);
;
rep_elem : REP exprs_opt ')' o_elems_opt
- rep_parts_opt END { $$ = repeat_rep_helper(rep_s,
- $2,
- o_elems_transform($4),
- $5);
+ rep_parts_opt END { $$ = repeat_rep_helper(rep_s, $2, $4, $5);
rl($$, num($1)); }
| REP error { $$ = nil;
yybadtok(yychar, lit("rep clause")); }
@@ -674,32 +670,20 @@ modifiers : NUMBER { $$ = cons($1, nil); }
o_var : SYMTOK { $$ = list(var_s, symhlpr($1, nil), nao);
rl($$, num(parser->lineno)); }
- | SYMTOK o_elem { $$ = list(var_s, symhlpr($1, nil),
- $2, nao);
- rl($$, num(parser->lineno)); }
- | '{' expr exprs_opt '}'
- { $$ = list(var_s, $2, nil, $3, nao);
- rl($$, num(parser->lineno)); }
- | '{' expr exprs_opt '}' o_elem
- { $$ = list(var_s, $2, $5, $3, nao);
+ | '{' expr exprs_opt '}'
+ { $$ = list(var_s, $2, $3, nao);
rl($$, num(parser->lineno)); }
| SYMTOK error { $$ = nil;
- yybadtok(yychar, lit("variable spec")); }
+ yybadtok(yychar, lit("variable spec")); }
;
q_var : SYMTOK { $$ = list(var_s, symhlpr($1, nil), nao);
rl($$, num(parser->lineno)); }
- | SYMTOK quasi_item { $$ = list(var_s, symhlpr($1, nil),
- $2, nao);
- rl($$, num(parser->lineno)); }
| '{' n_expr n_exprs_opt '}'
- { $$ = list(var_s, $2, nil, $3, nao);
- rl($$, num(parser->lineno)); }
- | '{' n_expr n_exprs_opt '}' quasi_item
- { $$ = list(var_s, $2, $5, $3, nao);
+ { $$ = list(var_s, $2, $3, nao);
rl($$, num(parser->lineno)); }
| SYMTOK error { $$ = nil;
- yybadtok(yychar, lit("variable spec")); }
+ yybadtok(yychar, lit("variable spec")); }
;
@@ -915,7 +899,7 @@ chrlit : HASH_BACKSLASH SYMTOK { wchar_t ch;
;
quasilit : '`' '`' { $$ = null_string; }
- | '`' quasi_items '`' { $$ = cons(quasi_s, o_elems_transform($2));
+ | '`' quasi_items '`' { $$ = cons(quasi_s, $2);
rlcp($$, $2);
rl($$, num(parser->lineno)); }
| '`' error { $$ = nil;
@@ -952,13 +936,11 @@ wordslit : '"' { $$ = nil; }
wordsqlit : '`' { $$ = nil; }
| ' ' wordsqlit { $$ = $2; }
- | quasi_items '`' { val qword = cons(quasi_s,
- o_elems_transform($1));
+ | quasi_items '`' { val qword = cons(quasi_s, $1);
$$ = rlcp(cons(qword, nil), $1); }
| quasi_items ' '
wordsqlit
- { val qword = cons(quasi_s,
- o_elems_transform($1));
+ { val qword = cons(quasi_s, $1);
$$ = rlcp(cons(qword, $3), $1); }
;
@@ -1099,32 +1081,6 @@ static val repeat_rep_helper(val sym, val args, val main, val parts)
nreverse(modlast_parts), nao);
}
-static val o_elems_transform(val o_elems)
-{
- list_collect_decl(o_elems_out, ptail);
- val iter;
-
- for (iter = o_elems; iter; iter = cdr(iter)) {
- val elem = car(iter);
-
- while (consp(elem) && first(elem) == var_s) {
- val sym = second(elem);
- val pat = third(elem);
- val modifiers = fourth(elem);
-
- ptail = list_collect(ptail,
- rlcp(list(first(elem), sym, nil, modifiers, nao),
- elem));
- elem = pat;
- }
-
- if (elem)
- ptail = list_collect(ptail, elem);
- }
-
- return rlcp(o_elems_out, o_elems);
-}
-
static val define_transform(parser_t *parser, val define_form)
{
void *scnr = parser->scanner;