From fd87267eb4802d1e3ec3c22a48e09a86f76810ad Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 6 Mar 2017 20:53:48 -0800 Subject: 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. --- parser.l | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'parser.l') diff --git a/parser.l b/parser.l index 569c4a79..45187dc5 100644 --- a/parser.l +++ b/parser.l @@ -743,7 +743,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} return HASH_N_HASH; } -\.\. { +{WS}\.\. { yylval->lineno = yyextra->lineno; return DOTDOT; } @@ -773,6 +773,11 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} return LAMBDOT; } +{REQWS}\. { + yylval->chr = '.'; + return UREFDOT; +} + \. { yylval->chr = '.'; return '.'; -- cgit v1.2.3