txr-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Txr-users] Gather question


From: Kaz Kylheku
Subject: Re: [Txr-users] Gather question
Date: Fri, 27 Jan 2012 09:41:36 -0800
User-agent: Roundcube Webmail/0.4

On Fri, 27 Jan 2012 12:30:23 -0000, "Eric" <address@hidden> wrote:
> The gather directive is for these situations. It specifies multiple
> clauses which all have to match somewhere in the data, but in any order. "
> 
> I take this as meaning that all clauses have to match, in which case, what
> if some are optional?

Gather is based on a process of elimination of successfully matching
clauses. As it marches through the data, in any iteration, it
removes those clauses which match, and then keeps going with
just the remaining ones.

Suppose we have this:

@(gather)
bread
mustard
ham
@(or)
@(maybe)
entire
multi-line
sandwich
@(end)
@(end)

This has four clauses: the single-liners bread, mustard and ham, and
then
the multi-liner set off by or. The multi-linter is wrapped inside
a maybe, making it optional. The maybe directive always succeeds,
even if its contents do not match anything. So what happens is that
this clause gets eliminated in the first iteration. That is not
particularly useful.

For more control of the process, I recommend variables. Introducing
:vars into gather changes its behavior. It no longer looks to
eliminate all the clauses, but to fill all the required variables.

@(next :env)
@(gather :vars (user (term "vt100")))
address@hidden
address@hidden
JUNK
@(end)

The USER= line *must* be found because there is no default value for
the user variable. If is not found, gather fails.

The TERM= line, if found, will capture a value for term, but if it
is not found, there is no failure. The term variable will get the
default value "vt100".

The JUNK line doesn't add any restriction because it is not
connected to a required variable.


Cheers ...






reply via email to

[Prev in Thread] Current Thread [Next in Thread]