Go to Google Groups Home    Qilang
Re: segment matching variables in Qi-YACC (for Snorgers ;))

Mark Tarver <dr.mtar...@ukonline.co.uk>

As of now, the second <<L>> would bind over the first.  No identity would be
created.  you would have to have

(defcc <f>
 <<L1>> <numbers> <<L2>> := (if (= <<L1>> <<L2>>) ..... #\Escape);)

----- Original Message -----
From: "snorgers" <stefan.ta...@spray.se>
To: "Qilang" <Qilang@googlegroups.com>
Sent: Friday, June 26, 2009 8:42 PM
Subject: Re: segment matching variables in Qi-YACC (for Snorgers ;))

Hi Mark,

Cool this looks like a natural building block, but what do you think
about patterns like

(defcc <f>
 <<L>> <numbers> <<L>> := ...)

They is nice to have for situations like
<string-prefix> <<boundary>> <endl> <<String>> <<boundary>> := (COERCE
<<String>> STRING);

/Stefan

On 26 June, 11:37, Mark Tarver <dr.mtar...@ukonline.co.uk> wrote:
> Here is a sugaring on top of Qi that enables you to have segment
> matching variables in Qi-YACC. <<...>> is a stuff matcher.

> (defcc <grab-numbers>
> <<X>> <numbers> <<Y>> := <numbers>;)

> (defcc <numbers>
> <number> <numbers>;
> <number>;)

> (defcc <number>
> -*- := (if (number? -*-) [-*-] #\Escape);)

> (defcc <grab-my-name>
> <<X>> :name <<Y>> := <<Y>>;)

> Examples:

> (compile <grab-my-name> [ghhghg 7 8 :name Mark Tarver])
> [Mark Tarver]

> (compile <grab-numbers> [just some numbers 1 2 3/4 tum te tum])
> [1 2 3/4]

> The code is 85 lines.

> Mark