diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-11-23 13:06:32 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-11-23 13:06:32 -0800 |
commit | 41fc1ec1db8a937c893520589fb5af5ae01c693b (patch) | |
tree | ee53d34dec835d1926a9c398725c01437b620d08 /parser.y | |
parent | 5133802c58ef432ab8b289418ee834ba480d74eb (diff) | |
download | txr-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.y | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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); |