summaryrefslogtreecommitdiffstats
path: root/parser.y
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-11-23 13:06:32 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-11-23 13:06:32 -0800
commit41fc1ec1db8a937c893520589fb5af5ae01c693b (patch)
treeee53d34dec835d1926a9c398725c01437b620d08 /parser.y
parent5133802c58ef432ab8b289418ee834ba480d74eb (diff)
downloadtxr-41fc1ec1db8a937c893520589fb5af5ae01c693b.tar.gz
txr-41fc1ec1db8a937c893520589fb5af5ae01c693b.tar.bz2
txr-41fc1ec1db8a937c893520589fb5af5ae01c693b.zip
Optimization: if all the elements of (text ...) are
strings, then replace the (text ...) by the catenation of those strings. * parser.y (optimize_text): New function. (elem): Use optimize_text.
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y11
1 files changed, 10 insertions, 1 deletions
diff --git a/parser.y b/parser.y
index 8b8744bf..27a668de 100644
--- a/parser.y
+++ b/parser.y
@@ -47,6 +47,7 @@ static val repeat_rep_helper(val sym, val main, val parts);
static val o_elems_transform(val output_form);
static val define_transform(val define_form);
static val lit_char_helper(val litchars);
+static val optimize_text(val text_form);
static wchar_t char_from_name(wchar_t *name);
static val parsed_spec;
@@ -286,7 +287,8 @@ texts : text %prec LOW { $$ = rl(cons($1, nil), $1); }
| text texts { $$ = rl(cons($1, $2), $2); }
;
-elem : texts { $$ = rl(cons(text_s, $1), $1); }
+elem : texts { $$ = rl(cons(text_s, $1), $1);
+ $$ = optimize_text($$); }
| var { $$ = rl($1, num(lineno)); }
| list { $$ = $1; }
| COLL exprs_opt ')' elems END { $$ = list(coll_s, $4, nil, $2, nao);
@@ -864,6 +866,13 @@ static val lit_char_helper(val litchars)
return ret;
}
+static val optimize_text(val text_form)
+{
+ if (all_satisfy(rest(text_form), func_n1(stringp), nil))
+ return cat_str(rest(text_form), lit(""));
+ return text_form;
+}
+
val rl(val form, val lineno)
{
sethash(form_to_ln_hash, form, lineno);