[squeak-dev] Parse specified number of elements with OMeta

Frank Shearar frank.shearar at gmail.com
Thu Dec 6 16:10:29 UTC 2012


On 6 December 2012 06:15, Yoshiki Ohshima <Yoshiki.Ohshima at acm.org> wrote:
> There may have been many similar attempts, but come to think of it,
> adding a simple higher-order rule to OMeta that applies the given rule
> for a given number of times is just straightforward.  For example, if
> you want to only parse a string that represents fully padded
> hexadecimal digits for a 8 or 4 byte quantity, you can write:
>
> hex16or8 =
>   numberOf(#hex. 16)
> | numberOf(#hex. 8)
>
> where #hex is something like:
>
> hex :c =
>    ?[(c between $0 and: $9) or: [c between: $A and: $F]

I think you're missing a trailing ] there.

> The numberOf rule looks like:
>
> numberOf :rule :count =
>     [0]:c [OrderedCollection new]:xs
>     ([c+1]:c ?[c <= count] apply(rule):x [xs add: x])*
>     ?[c = (count + 1)] -> [xs]

I may be misremembering my OMeta grammar, but I thought you'd need
some |s between those. Or is it that [0] binds to :count (calling it
c), which makes the initial collection. Then we apply some number of
times (the *) the rule that runs :rule, and finally we have a semantic
action returning the final collection?

frank


More information about the Squeak-dev mailing list