diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-07-07 23:43:08 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-07-07 23:43:08 -0700 |
commit | fa3c90eb3ac48abd8bb9065884fe15523a864766 (patch) | |
tree | c96e5c01207325af768cba0032f3a47184d15f20 /txr.1 | |
parent | cb31c444c367ffe950cffae7adca5a3ec024620a (diff) | |
download | txr-fa3c90eb3ac48abd8bb9065884fe15523a864766.tar.gz txr-fa3c90eb3ac48abd8bb9065884fe15523a864766.tar.bz2 txr-fa3c90eb3ac48abd8bb9065884fe15523a864766.zip |
txr: support @(if)/@(elif)/@(else) in @(output).
This turns out to be way easier than I thought.
* match.c (do_output_if): New static function.
(do_output): Handle if via do_output_if.
* parser.y (out_if_clause, out_elif_clauses_opt,
out_else_clause_opt): New nonterminal symbols and grammar
rules.
(out_clause): Now produces out_if_clause.
(not_a_clause): Remove ELIF and ELSE; these entries here cause
conflicts now. Here, continue to recognize the Lisp if, which
is distinguished by having at least two arguments.
out_if_clause matches only a one-argument if, and a
no-argumeent one that is diagnosed as erroneous.
* txr.1: Documented.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 49 |
1 files changed, 47 insertions, 2 deletions
@@ -3484,7 +3484,10 @@ directive with optional and .code else clauses allows one of multiple bodies of pattern matching directives to be -conditionally selected by testing the values of Lisp expressions. +conditionally selected by testing the values of Lisp expressions. It is +also available inside +.code @(output) +for conditionally selecting output clauses. .coIP @(choose) Multiple clauses are applied to the same input. The one whose effect persists @@ -5067,7 +5070,14 @@ Example: The .code if directive allows for conditional selection of pattern matching clauses, -based on the Boolean results Lisp expressions. +based on the Boolean results of Lisp expressions. + +A variant of the +.code if +directive is also available for use inside an +.code output +clauses, where it similarly allows for the conditional selection of output +clauses. The syntax of the .code if @@ -5153,6 +5163,41 @@ clause, then the directive is deemed to have trivially succeeded, allowing matching to continue with whatever directive follows it. +.coNP The Lisp @ if versus TXR @ if + +The +.code @(output) +directive supports the embedding of Lisp expressions, whose values are +interpolated into the output. In particular, Lisp +.code if +expressions are useful. For instance +.code "@(if expr \(dqA\(dq \(dqB\(dq)" +reproduces +.code A +if +.code expr +yields a true value, otherwise +.codn B . +Yet the +.code @(if) +directive is also supported in +.codn @(output) . +How the apparent conflict between the two is resolved is that the two take +different numbers of arguments. An +.code @(if) +which has no arguments at all is a syntax error. One that has one argument +is the head of the +.code if +directive syntax which must be terminated by +.code @(end) +and which takes the optional +.code @(elif) +and +.code @(else) +clauses. An +.code @(if) +which has two or more arguments is parsed as a self-contained Lisp expression. + .dir gather Sometimes text is structured as items that can appear in an arbitrary order. |