summaryrefslogtreecommitdiffstats
path: root/parser.l
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-11-05 23:50:22 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-11-05 23:50:22 -0800
commitd3ec853013356d9c8267980a5146728c16e002ba (patch)
treea4cc5ae81784c16d6177b7a4a032b5ea014ab784 /parser.l
parenta8d9b5d83b10ff215e40fffd1d88fd081a5f1728 (diff)
downloadtxr-d3ec853013356d9c8267980a5146728c16e002ba.tar.gz
txr-d3ec853013356d9c8267980a5146728c16e002ba.tar.bz2
txr-d3ec853013356d9c8267980a5146728c16e002ba.zip
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.
Diffstat (limited to 'parser.l')
-rw-r--r--parser.l10
1 files changed, 10 insertions, 0 deletions
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 '.';
}
+<SPECIAL,QSPECIAL,NESTED>\.\? {
+ yylval->chr = '.';
+ return OREFDOT;
+}
+
+<SPECIAL,QSPECIAL,NESTED,BRACED>{REQWS}\.\? {
+ yylval->chr = '.';
+ return UOREFDOT;
+}
+
<SPECIAL,QSPECIAL,NESTED,BRACED>[\\]{NL}{WS} {
if (YYSTATE == SPECIAL)
yy_pop_state(yyscanner); /* @\ continuation */