[ANN] new release of MEPS parser combinator

squeakdev1 at reider.net squeakdev1 at reider.net
Sat Nov 3 15:53:45 UTC 2007


A new release of MEPS is available on SqueakMap. MEPS is a parser
combinator for squeak that allows parsers to be combined and evaluated
through a set of matching extension methods in PositionableStreams eg:

'foobar' readStream match: 'foo' and: 'bar' regex
  action:[:r | FooBarNode foo:r first bar: r second ].

where 'foo' and ('bar' regex) are parsers defined on the fly. This
release provides additional ways to combine parsers separate from
their invocation.

The following example creates a parser of a Smalltalk method temp declaration:

whitespace := '\s*' regex.
id := '\a\w*' regex.
ids := (whitespace , id ! [ : r | r second]) zeroOrMore .
temps := '|' meps , ids , whitespace , '|' ! [:list | list second].
temps << '| foo bar |'   "anOrderedCollection('foo' 'bar')"

(This example is somewhat contrived because in a real Smalltalk
parser, tokenizing and parsing would occur in separate phases (each of
which could be created using MEPS)).

In ids, a whitespace parser is combined (#,) with an identifier
parser. Then #! yields a parser with an action that transforms {ws,id}
to id, which is then used in a repetition parser created by
#zeroOrMore.

temps << | foo bar |' is equivalent to
 '| foo bar |' readStream match:temps action:[:r|r].

ids could have been written equivalently as:
ids := [:input | input
              matchZeroOrMore: [:in2 |
                      in2
                              match: whitespace
                              and: id
                              action: [ : r | r second]]
              action:[:r |r ]].

(Note: in this release, block parsers no longer have to capture the
input stream).

See http://squeak.reider.net/MEPS/meps.html for more examples.



More information about the Squeak-dev mailing list