diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-03-06 20:53:48 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-03-06 20:53:48 -0800 |
commit | fd87267eb4802d1e3ec3c22a48e09a86f76810ad (patch) | |
tree | 8760a2fb325d259e5e86983b20f690ee08da93c4 /share | |
parent | 266e28cb7129d175ad4af5af5cb45fbbd3054862 (diff) | |
download | txr-fd87267eb4802d1e3ec3c22a48e09a86f76810ad.tar.gz txr-fd87267eb4802d1e3ec3c22a48e09a86f76810ad.tar.bz2 txr-fd87267eb4802d1e3ec3c22a48e09a86f76810ad.zip |
uref: the a.b.c syntax extended to .a.b.c
Now it is possible to use a leading dot on the referencing
dot syntax. This is the is the "unbound reference dot". It
expands to the uref macro, which denotes an unbound-reference:
it produces a function which takes an object as the argument,
and curries the reference implied by the remaining arguments.
* eval.c (uref_s): New global symbol variable.
(eval_init): Intern uref symbol and init uref_s.
* eval.h (uref_s): Declared.
* lib.c (simple_qref_args_p): A qref expression is now
also not simple if it contains an embedded uref, meaning
that it cannot be rendered into the dot notation without
ambiguity.
(obj_print_impl): Support printing (uref a b c) as .a.b.c.
* lisplib.c (struct_set_entries): Add uref to the list of
autoload triggers for struct.tl.
* parser.l (DOTDOT): Consume any leading whitespace as part
of recognizing the DOTDOT token. Otherwise the new rule
for UREFDOT, which matches (mandatory) leading space
will take precedence, causing " .." to be scanned wrong.
(UREFDOT): Rule for new kind of dot token, which is
preceded by mandatory whitespace, and isn't consing
dot (which has mandatory trailing whitespace too,
matched by an earlier rule).
* parser.y (UREFDOT): New token type.
(i_dot_expr, n_dot_expr): New grammar rules.
(list): Handle a leading dot on the first element of a list as
a special case. Things are done this way because trying to
work a UREFDOT into the grammar otherwise causes intractable
conflicts.
(i_expr): The ^, ' and , punctuators are now followed by
an i_dot_expr, so that the expression can be an unbound
dot.
(n_expr): Same change as in i_expr, but using n_dot_expr.
Plus new UREFDOT n_expr production.
* share/txr/stdlib/struct.tl (uref): New macro.
* txr.1: Documented.
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/struct.tl | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/share/txr/stdlib/struct.tl b/share/txr/stdlib/struct.tl index ec48bcb3..7de81ae9 100644 --- a/share/txr/stdlib/struct.tl +++ b/share/txr/stdlib/struct.tl @@ -207,6 +207,16 @@ ((sym . more) ^(qref (slot ,obj ',sym) ,*more)) (obj (throwf 'eval-error "~s: bad syntax: ~s" 'qref refs)))) +(defmacro uref (:whole form . args) + (cond + ((null args) (throwf 'eval-error "~s: bad syntax" 'uref)) + ((null (cdr args)) + (if (consp (car args)) + ^(umeth ,*(car args)) + ^(usl ,(car args)))) + (t (with-gensyms (ovar) + ^(lambda (,ovar) (qref ,ovar ,*args)))))) + (defmacro new (spec . pairs) (if (oddp (length pairs)) (throwf 'eval-error "~s: slot initform arguments must occur pairwise" |