Re: [code] Doing folds with weird syntax.

From: Mitchell <m.att.foicica.com>
Date: Sun, 10 Nov 2013 23:02:51 -0500 (EST)

Hi Michael,

On Sun, 10 Nov 2013, Michael Richter wrote:

> I'm finishing up my lexer for the Mercury language. I've hit a bit of a
> snag in doing fold support.
>
> In Mercury, for example, a type declaration looks like this:
>
> :- type tree234(K, V)
> ---> empty
> ; two(K, V, tree234(K, V), tree234(K, V))
> ; three(K, V, K, V, tree234(K, V), tree234(K, V), tree234(K, V))
> ; four(K, V, K, V, K, V, tree234(K, V), tree234(K, V),
> tree234(K, V), tree234(K, V)).
>
> You would fold on the *type* keyword as well as the *--->* operator. In
> both instances, however, you terminate on the *same period*. I can't
> figure out how I'd do this for folding. Further, in the first case you're
> folding on a *keyword* (type) but ending on an *operator* (.) which, again,
> I can't figure out how to provide the magic incantations for.

Do *type* and *--->* always exist in pairs? Does *period* only exist after
*type* and *--->*? If so, you can assign a -2 level to your *period*.
Something like:

M._foldsymbols = {
   _patterns = {'%l+', '%-%-%->', '%.'},
   [l.KEYWORD] = {type = 1},
   [l.OPERATOR] = {['--->'] = 1, ['.'] = -2}
}

You can start in a keyword and end in an operator, no problem. All the
folding code does is see if something matches in `_patterns` and then
figure out what matched by iterating through the token tables.

I hope that helps,
Mitchell

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Sun 10 Nov 2013 - 23:02:51 EST

This archive was generated by hypermail 2.2.0 : Mon 11 Nov 2013 - 06:26:28 EST