[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Txr-users] use regex in filter?
From: |
苏灵 |
Subject: |
Re: [Txr-users] use regex in filter? |
Date: |
Sat, 13 Jul 2013 01:04:28 +0800 |
2013/7/12 Kaz Kylheku <address@hidden>
>
>
> On Thu, 11 Jul 2013 19:11:07 +0800, 苏灵 <address@hidden> wrote:
> > I am new to TXR. Txr is a powerful tool that make things simple.
> > filter is amazing, but when i want to use regex in filter to do some
> > replacement, i don't know how to implement.
> > Is it possible to use regex in filter? If it is ,how?
>
> Not currently. The filter stuff has its own algorithm based on tries.
> This would
> have to be extended to encompass regexes. I have some ideas how to do
> that;
> maybe I can make it a priority for the next release.
At your convenience. TXR is already a powerful language,
I can do the same thing in another way. It is just instinctive to
use "filter" to do some replacements. I think it is necessary to
make the powerful TXR more simple, and more elegant.
> There is already a hybridization going on in the trie data structure in
> that a node of the tree can be a function which takes over the matching
> from that node downward. This allows the :fromhtml filter to work,
> which
> has to be able to recognize sequences of digits for the character
> escape
> which takes the form: &#<digits>;
>
> Regex filtering can be done using TXR Lisp, via the regsub function,
> but that's not satisfactory if you want to replace multiple regexes
> with multiple replacements.
>
> A pattern-matching function can be used for filtering also. Look for
> the section "Function Filters" in the manual. The idea is that you can
> write a two-argument pattern function which analyzes the first argument
> and binds the second one to some output. This can then be used in
> filters
> with the (:fun <function-name>) syntax. But this has to handle the
> complete
> text in one call, performing all necessary replacements on it.
I am just trying this way tonight. But the codes turn out a little messy.
>
> > BTW, some directives is not easy to understand, more example will
> > help.
>
> That's right; the goal so far had been just to make the documentation
> complete
> in terms of feature coverage. Examples are lacking in many places.
>
I am still reading the documentation. Sometimes, it is difficult to
understand the philosophy of txr. More example is necessary.
I am planing to translate the documentation to Chinese, at least partially.