From d3ec853013356d9c8267980a5146728c16e002ba Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 5 Nov 2019 23:50:22 -0800 Subject: syntax: new .? operator for null-safe object access. * lib.c (obj_print_impl): Render the new syntactic conventions introduced in qref/uref back into the .? syntax. The printers for qref and uref are united into a single implementation to reduce code proliferation. * parser.l (grammar): Produce new tokens OREFDOT and UOREFDOT. * parser.y (OREFDOT, UREFDOT): New terminal symbols. (n_expr): Handle .? syntax via the new OREFDOT and UOREFDOT token via qref_helper and uoref_helper. Logic for the existing referencing dot is moved into the new qref_helper function. (n_dot_expr): Handle .? syntax via uoref_helper. (uoref_helper, qref_helper): New static functions. * share/txr/stdlib/struct.tl (qref): Handle the new case when the expression which gives the object is (t expr). Handle the new case when the first argument after the object has this form, and is followed by more arguments. Both these cases emit the right conditional code. (uref): Handle the leading .? syntax indicated by a leading t by generating a lambda which checks its argument for nil. Transformations to qref handle the other cases. * txr.1: Documentation updated in several places. --- parser.l | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'parser.l') diff --git a/parser.l b/parser.l index bebe64f5..292615e1 100644 --- a/parser.l +++ b/parser.l @@ -801,6 +801,16 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} return '.'; } +\.\? { + yylval->chr = '.'; + return OREFDOT; +} + +{REQWS}\.\? { + yylval->chr = '.'; + return UOREFDOT; +} + [\\]{NL}{WS} { if (YYSTATE == SPECIAL) yy_pop_state(yyscanner); /* @\ continuation */ -- cgit v1.2.3