summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-03-01 21:49:46 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-03-01 21:49:46 -0800
commit684c8e9d60812778b785ef0fc3fa78592f228bf8 (patch)
tree3ce51eb4db7a039fcc4e04b2022cfa5b54fde953 /lib.c
parent29bfa94d05a5c7d1a8205753b6c13731ecba564a (diff)
downloadtxr-684c8e9d60812778b785ef0fc3fa78592f228bf8.tar.gz
txr-684c8e9d60812778b785ef0fc3fa78592f228bf8.tar.bz2
txr-684c8e9d60812778b785ef0fc3fa78592f228bf8.zip
New quasiquote idea: let's have two quasiquote macros sharing one
expander. One macro based on sys:qquote, sys:unquote and sys:splice, and the other based on qquote, unquote and splice in the user package. The read syntax puts out the sys: one. * eval.c (expand_qquote): Takes three additional arguments: the qquote, unquote and splice symbols to recognize. The invalid splice diagnostic is adjusted based on which backquote we are expanding. (me_qquote): Look at the symbol in the first position of the form and then expand either the internal quasiquote macro or the public one, passing the right symbols into expand_qquote. (eval_init): Register error-throwing stub functions for the sys_qquote_s, sys_unquote_s and sys_splice_s symbols. Register a macro for sys_qquote_s. * lib.c (sys_qquote_s, sys_unquote_s, sys_splice_s): New symbol variables. (obj_init): Initialize new variables. Change qquote_s, unquote_s and splice_s to user package. (obj_print, obj_pprint): Convert only sys_qquote_s, sys_unquote_s and sys_splice_s to the read syntax. The quote_s, unquote_s and splice_s symbols are not treated specially. * lib.h (sys_qquote_s, sys_unquote_s, sys_splice_s): Declared. * parser.y (n_expr): Use sys_qquote_s, sys_unquote_s and sys_splice_s rather than qquote_s, unquote_s and splice_s. (unquotes_occur): Likewise. * txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib.c b/lib.c
index dee6af8f..04c550fa 100644
--- a/lib.c
+++ b/lib.c
@@ -75,6 +75,7 @@ val env_s, bignum_s, float_s;
val var_s, expr_s, regex_s, chset_s, set_s, cset_s, wild_s, oneplus_s;
val nongreedy_s, compiled_regex_s;
val quote_s, qquote_s, unquote_s, splice_s;
+val sys_qquote_s, sys_unquote_s, sys_splice_s;
val zeroplus_s, optional_s, compl_s, compound_s, or_s, and_s, quasi_s;
val skip_s, trailer_s, block_s, next_s, freeform_s, fail_s, accept_s;
val all_s, some_s, none_s, maybe_s, cases_s, collect_s, until_s, coll_s;
@@ -5139,9 +5140,12 @@ static void obj_init(void)
nongreedy_s = intern(lit("ng0+"), user_package);
compiled_regex_s = intern(lit("compiled-regex"), system_package);
quote_s = intern(lit("quote"), user_package);
- qquote_s = intern(lit("qquote"), system_package);
- unquote_s = intern(lit("unquote"), system_package);
- splice_s = intern(lit("splice"), system_package);
+ qquote_s = intern(lit("qquote"), user_package);
+ unquote_s = intern(lit("unquote"), user_package);
+ splice_s = intern(lit("splice"), user_package);
+ sys_qquote_s = intern(lit("qquote"), system_package);
+ sys_unquote_s = intern(lit("unquote"), system_package);
+ sys_splice_s = intern(lit("splice"), system_package);
chset_s = intern(lit("chset"), system_package);
set_s = intern(lit("set"), user_package);
cset_s = intern(lit("cset"), user_package);
@@ -5229,13 +5233,13 @@ val obj_print(val obj, val out)
{
val sym = car(obj);
- if (sym == quote_s || sym == qquote_s) {
+ if (sym == quote_s || sym == sys_qquote_s) {
put_char(chr('\''), out);
obj_print(second(obj), out);
- } else if (sym == unquote_s) {
+ } else if (sym == sys_unquote_s) {
put_char(chr(','), out);
obj_print(second(obj), out);
- } else if (sym == splice_s) {
+ } else if (sym == sys_splice_s) {
put_string(lit(",*"), out);
obj_print(second(obj), out);
} else if (sym == vector_lit_s) {
@@ -5415,13 +5419,13 @@ val obj_pprint(val obj, val out)
{
val sym = car(obj);
- if (sym == quote_s || sym == qquote_s) {
+ if (sym == quote_s || sym == sys_qquote_s) {
put_char(chr('\''), out);
obj_pprint(second(obj), out);
- } else if (sym == unquote_s) {
+ } else if (sym == sys_unquote_s) {
put_char(chr(','), out);
obj_pprint(second(obj), out);
- } else if (sym == splice_s) {
+ } else if (sym == sys_splice_s) {
put_string(lit(",*"), out);
obj_pprint(second(obj), out);
} else if (sym == vector_lit_s) {