Pattern Matching

Patterns can match against streams of any objects. There are many primitive pattern expressions that can be combined together to form more complex patterns.

Patterns can be declared using the pattern keyword and matching is invoked using the match and with keywords.

var p = pattern any+ // matches one or more of anything
var m = match "xyz" with p // match the characters in the provided string using the pattern p
print(m) // xyz


Name Syntax
And x y z
Or x | y | z
Character 'x'
String "xyz"
Number 7 or 7.11 or 0xFF
Range "a".."z" or 0..100
Bool true or false
Array [ x y z ]
Object x { y = z }
Any any
Default default
Fail fail
Reference x or self.x or super.x
Variable x:X
One or More x+
Zero or More x*
Zero or One x?
Not !x
Group ( x ( y z ) )
Production x -> y
  • The any keyword matches exactly one of anything in the stream, if the stream is empty it returns fail.
  • The default pattern always matches, even if the stream is empty, and consumes nothing from the stream. It is especially useful for the last pattern in an Or clause.

Last edited Nov 24, 2012 at 5:15 PM by justinc, version 2


No comments yet.