Happy !

NicVolanschi / Matchbox

Project infos

License LGPLv3
Tags pattern matching, custom notations
Creation date 2018-09-04
Website http://mypatterns.free.fr

Monticello registration

About Matchbox

Matchbox is a library for pattern matching, in user-defined notations. It allows to recognize and decompose arbitrary data structures using pattern matching. The predefined syntax for patterns is the STON notation extended with variables, which use the % symbol. The STON notation involves an optional class name, followed by either a record or array notation. The record notation extracts selected fields by name. The array notation extracts selected fields in order based on their fixed positions. The predefined notation can be redefined on any object type by overriding its matches:at:subst: method. The main entry point is the Object>>matches: method. On successful match, it returns a substitution; otherwise, it returns nil. Examples:

(10@20) matches: '{#x:%,#y:%}' --> an OrderedCollection(10 20).

(10@20) matches: 'Point[%,%]' --> an OrderedCollection(10 20).

(10@20 extent: 20@20) matches: 'Rectangle{#corner:Point[%],#origin:Point{#y:%}}' --> an OrderedCollection(30 20)

#(1 2 3) matches: '[%,%]' --> an OrderedCollection(1 2).