From b58791b726228b97297cc4512476f6016b9346a2 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 26 Jan 2012 12:26:16 -0800 Subject: * eval.c (dwim_loc, dwim_op): Eliminated redundant re-evaluation of range arguments. They are already evaluated since the cons expression is evaluates as part of the dwim arglist. Replaced some open code with function calls to the new listref and listref_l functions. (tostring, tostringp): made extern and moved to lib.c. * lib.c (listref, listref_l): New functions. (tostring, tostringp): moved here from eval.c. * lib.h (listref, listref_l, tostring, tostringp): Declared. * match.c (format_field): Handle index and range references. * txr.1: Documented new output variable syntax. --- txr.1 | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index 3853fe7f..ff427fc8 100644 --- a/txr.1 +++ b/txr.1 @@ -1046,7 +1046,10 @@ into the literal template. If a is bound to "apple" and b to "banana", the quasiliteral `one@a and two @{b}s` represents the string "one apple and two bananas". A backquote escaped by a backslash represents itself, and two consecutive @ characters code for a literal @. -There is no \e@ escape. +There is no \e@ escape. Quasiliterals support the full output variable +syntax. Expressions within variables substitutions follow the evaluation rules +of TXR Lisp when the quasiliteral occurs in TXR Lisp, and the rules of +the TXR pattern language when the quasiliteral occurs in the pattern language. .SS Numbers @@ -3318,6 +3321,39 @@ for the output clause. The syntax for this is @(NAME :filter }. The filter specification syntax is the same as in the output clause. See Output Filtering below. +Additional syntax is supported in output variables that is does not appear +in pattern matching variables. + +A square bracket index notation may be used to extract elements from a variable +which is a list, or to extract ranges. Elements are indexed from zero. This +notation is only available in brace-enclosed syntax, and looks like this: + +.IP +@{NAME[expr]) + +Extract the element at the position given by expr. + +.IP +@{NAME[expr1..expr2]) + +Extract a list of elements from the position given by expr1, up to +one position less than the position given by expr2. +The elements from the range are catenated together to form a single string, +with a separator character in between. The default character is a space. +An alternate character may be given as a string argument. + +.TP +Example: + + @(bind a ("a" "b" "c" "d")) + @(output) + @{a[1..3] "," 10} + @(end) + +The above produces the text "b,c" in a field 10 spaces wide. The [1..3] +argument extracts a range of a; the "," argument specifies an alternate +separator string, and 10 specifies the field width. + .SS The Repeat Directive The repeat directive is generates repeated text from a ``boilerplate'', -- cgit v1.2.3