diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-10-24 23:35:48 -0400 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-10-24 23:35:48 -0400 |
commit | 77b9c8f289df7b0ba45668e09cdc040252c681c8 (patch) | |
tree | d1d6df2cd1ed2ad82a9aa845cda6c4243f01ce99 /txr.1 | |
parent | 23a6fd5129b285d25faa8198e395ac91db0348c4 (diff) | |
download | txr-77b9c8f289df7b0ba45668e09cdc040252c681c8.tar.gz txr-77b9c8f289df7b0ba45668e09cdc040252c681c8.tar.bz2 txr-77b9c8f289df7b0ba45668e09cdc040252c681c8.zip |
* filter.c (function_filter): New function.
(get_filter): Handle (fun ...) syntax.
* match.c (v_bind): Establish dynamic environment frame around
dest_bind, and stash the bindings there so filters can have access
to the bindings.
(v_output): Likewise, around do_output calls.
(v_fun): New function.
(match_files): Function handling broken out into v_fun.
(match_funcall): New function.
* match.h (match_funcall): Declared.
* unwind.c (uw_push_env): Initialize match_context.
(uw_get_match_context, uw_set_match_context): New functions.
* unwind.h (struct uw_dynamic_env): New member, match_context.
(uw_get_match_context, uw_set_match_context): Declared.
* txr.1: Documented function filters.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 46 |
1 files changed, 44 insertions, 2 deletions
@@ -1073,7 +1073,8 @@ This directive is used for defining named filters, which are useful for filtering variable substitutions in output blocks. Filters are useful when data must be translated between different representations that have different special characters or other syntax, requiring escaping -or similar treatment. +or similar treatment. Note that it is also possible to use a function +as a filter. See Function Filters below. .PP @@ -2153,11 +2154,12 @@ Example, the following produces a match: @(bind "A" "a" :rfilt :upcase) - .IP :filter This keyword is a shorthand to specify both filters to the same value. So for instance :filter :upcase is equivalent to :lfilt :upcase :rfilt :upcase. +For a description of filters, see Output Filtering below. + Of course, compound filters like (:from_html :upcase) are supported with all these keywords. The filters apply across arbitrary patterns and nested data. @@ -3025,6 +3027,46 @@ because '"' will turn to '"' which no longer be recognized by the :from_html filter, because the entity names in HTML codes are case-sensitive. +Instead of a filter name, the syntax (fun NAME) can be used. This +denotes that the function called NAME is to be used as a filter. +This is discussed in the next section Function Filters below. + +.SS Function Filters + +A function can be used as a filter. For this to be possible, the function must +conform to certain rules: + +.IP 1. +The function must take exactly two arguments. + +.IP 2. +When the function is called, the first argument will be bound to a string, +and the second argument will be unbound. The function must produce a string +value by binding it to the second argument. + +For instance, the following is a valid filter function: + + @(define foo_to_bar (in out) + @ (next :string in) + @ (cases) + foo + @ (bind out "bar") + @ (or) + @ (bind out in) + @ (end) + @(end) + +This function binds the out parameter to "bar" if the in parameter +is "foo", otherwise it binds the out parameter to a copy of the in parameter. +This is a simple filter. + +To use the filter, use the syntax (fun foo_to_bar) in place of a filter name. +For instance in the bind directive: + + @(bind "foo" "bar" :lfilt (fun foo_to_bar)) + +The above should succeed since the left side is filtered from "foo" +to "bar", so that there is a match. .SS The Deffilter Directive |