[squeak-dev] Parse specified number of elements with OMeta
Yoshiki Ohshima
Yoshiki.Ohshima at acm.org
Thu Dec 6 06:15:37 UTC 2012
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]
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]
--
-- Yoshiki
More information about the Squeak-dev
mailing list
|