Bookmark

OpenURL

Abstract

Abstract. Pattern matching is a programming language feature for selecting a handler based on the structure of data while binding names to sub-structures. By combining selection and binding, pattern matching facilitates many common tasks such as date normalization, red-black tree manipulation, conversion of XML documents, or decoding TCP/IP packets. Matchete is a language extension to Java that unifies different approaches to pattern matching: regular expressions, structured term patterns, XPath, and bit-level patterns. Matchete naturally allows nesting of these different patterns to form composite patterns. We present the Matchete syntax and describe a prototype implementation.

Citations

...ype compiler performs no optimizations, we leave this to future work. 2 Related Work Structured term pattern matching is a central feature of functional programming languages. In languages such as ML =-=[22]-=- or Haskell [17], instances of algebraic data types can be constructed and deconstructed using the same constructors. The simplicity and elegance of the approach is tied to having a relatively simple ...

...complished by the evaluation order rules from Section 3.1 and the type conversion rules from Section 3.2. 4 Examples Red–black trees. Fig. 4 shows part of a Matchete implementation of red–black trees =-=[13,24]-=-. The method uses the deconstructor to disassemble a node into its components, and then reassembles black interior nodes so that the data structure invariant is maintained: each red node must have two...

...complished by the evaluation order rules from Section 3.1 and the type conversion rules from Section 3.2. 4 Examples Red–black trees. Fig. 4 shows part of a Matchete implementation of red–black trees =-=[13,24]-=-. The method uses the deconstructor to disassemble a node into its components, and then reassembles black interior nodes so that the data structure invariant is maintained: each red node must have two...

...forms no optimizations, we leave this to future work. 2 Related Work Structured term pattern matching is a central feature of functional programming languages. In languages such as ML [22] or Haskell =-=[17]-=-, instances of algebraic data types can be constructed and deconstructed using the same constructors. The simplicity and elegance of the approach is tied to having a relatively simple data model in wh...

...n of an XML document that specify sets of nodes [3]. XPath is the primary matching mechanism of XSLT, and Matchete supports XPath directly. Several recent languages treat XML as semi-structured terms =-=[2,8,15,16,18,19,21]-=-. These languages support patterns similar to structured term patterns in functional languages, in some cases augmented by Kleene closure over sibling tree nodes. Matchete also supports structured ter...

...n of an XML document that specify sets of nodes [3]. XPath is the primary matching mechanism of XSLT, and Matchete supports XPath directly. Several recent languages treat XML as semi-structured terms =-=[2,8,15,16,18,19,21]-=-. These languages support patterns similar to structured term patterns in functional languages, in some cases augmented by Kleene closure over sibling tree nodes. Matchete also supports structured ter...

...ave investigated extensions to object-oriented languages that allow pattern matching over abstract data types. Views are implicit coercions between data types that are applied during pattern matching =-=[27]-=-. Active patterns [26] for F# generalize views to functions that deconstruct values into an option type—either values if the input value can be deconstructed or . Active patterns can be used just like...

...sions directly in the language. Bit-level data manipulation has traditionally been the domain of low-level languages such as C. Some recent work takes a type-based approach for parsing bit-level data =-=[1,4,7]-=-. The Erlang programming language, on the other hand, allows specifying bitlevel patterns directly. Erlang’s patterns are widely used for network protocols, and are optimized [14]. Matchete follows th...

...used to support other kinds of pattern matching by supplying an expansion to the primitive matching forms [29]. Tom is a preprocessor that adds structured term pattern matching to Java, C, and Eiffel =-=[23]-=-. OOMatch [25] and JMatch [20] are Java extensions. OOMatch allows pattern declaration in method parameters and resembles Matchete in its treatment of extractors. JMatch provides invertible methods an...

...n of an XML document that specify sets of nodes [3]. XPath is the primary matching mechanism of XSLT, and Matchete supports XPath directly. Several recent languages treat XML as semi-structured terms =-=[2,8,15,16,18,19,21]-=-. These languages support patterns similar to structured term patterns in functional languages, in some cases augmented by Kleene closure over sibling tree nodes. Matchete also supports structured ter...

...n of an XML document that specify sets of nodes [3]. XPath is the primary matching mechanism of XSLT, and Matchete supports XPath directly. Several recent languages treat XML as semi-structured terms =-=[2,8,15,16,18,19,21]-=-. These languages support patterns similar to structured term patterns in functional languages, in some cases augmented by Kleene closure over sibling tree nodes. Matchete also supports structured ter...

...sions directly in the language. Bit-level data manipulation has traditionally been the domain of low-level languages such as C. Some recent work takes a type-based approach for parsing bit-level data =-=[1,4,7]-=-. The Erlang programming language, on the other hand, allows specifying bitlevel patterns directly. Erlang’s patterns are widely used for network protocols, and are optimized [14]. Matchete follows th...

...o Java bytecode, and executed on a Java virtual machine together with the Matchete runtime library. 5.1 Background: Rats! and xtc The Matchete parser is generated by Rats!, a packrat parser generator =-=[11]-=-. Rats! has a module system for grammars, which permits Matchete to reuse and extend the Java grammar without copy-and-paste. Instead, the Matchete grammar simply includes the Java grammar as a module...

...rward syntax and semantics. This should be contrasted with many recent efforts that focus on a particular pattern matching style, for example, functional-style patterns in an object-oriented language =-=[5,19,20]-=-. In Matchete, functional-style term patterns, Perl-style regular expressions, XPath expressions, and Erlang-style bit-level patterns can contain one another, and use the same small set of primitive p...

...rward syntax and semantics. This should be contrasted with many recent efforts that focus on a particular pattern matching style, for example, functional-style patterns in an object-oriented language =-=[5,19,20]-=-. In Matchete, functional-style term patterns, Perl-style regular expressions, XPath expressions, and Erlang-style bit-level patterns can contain one another, and use the same small set of primitive p...

...n of an XML document that specify sets of nodes [3]. XPath is the primary matching mechanism of XSLT, and Matchete supports XPath directly. Several recent languages treat XML as semi-structured terms =-=[2,8,15,16,18,19,21]-=-. These languages support patterns similar to structured term patterns in functional languages, in some cases augmented by Kleene closure over sibling tree nodes. Matchete also supports structured ter...

...rward syntax and semantics. This should be contrasted with many recent efforts that focus on a particular pattern matching style, for example, functional-style patterns in an object-oriented language =-=[5,19,20]-=-. In Matchete, functional-style term patterns, Perl-style regular expressions, XPath expressions, and Erlang-style bit-level patterns can contain one another, and use the same small set of primitive p...

...sions to object-oriented languages that allow pattern matching over abstract data types. Views are implicit coercions between data types that are applied during pattern matching [27]. Active patterns =-=[26]-=- for F# generalize views to functions that deconstruct values into an option type—either values if the input value can be deconstructed or . Active patterns can be used just like regular structural pa...

...sions directly in the language. Bit-level data manipulation has traditionally been the domain of low-level languages such as C. Some recent work takes a type-based approach for parsing bit-level data =-=[1,4,7]-=-. The Erlang programming language, on the other hand, allows specifying bitlevel patterns directly. Erlang’s patterns are widely used for network protocols, and are optimized [14]. Matchete follows th...

...t other kinds of pattern matching by supplying an expansion to the primitive matching forms [29]. Tom is a preprocessor that adds structured term pattern matching to Java, C, and Eiffel [23]. OOMatch =-=[25]-=- and JMatch [20] are Java extensions. OOMatch allows pattern declaration in method parameters and resembles Matchete in its treatment of extractors. JMatch provides invertible methods and constructors...

...n of an XML document that specify sets of nodes [3]. XPath is the primary matching mechanism of XSLT, and Matchete supports XPath directly. Several recent languages treat XML as semi-structured terms =-=[2,8,15,16,18,19,21]-=-. These languages support patterns similar to structured term patterns in functional languages, in some cases augmented by Kleene closure over sibling tree nodes. Matchete also supports structured ter...

...about ease of debugging Matchete code. When a match statement does not work as the programmer expected, they need to pinpoint the defect. Matchete uses functionality provided with xtc to inject SMAPs =-=[6]-=- into class files, which allow Java debuggers such as Eclipse or Jdb to work at the level of the original Matchete source code.s7 Conclusions Matchete: Paths through the Pattern Matching Jungle 165 Th...

... for objects. PLT Scheme’s match form allows adding new pattern matching macros, which can be used to support other kinds of pattern matching by supplying an expansion to the primitive matching forms =-=[29]-=-. Tom is a preprocessor that adds structured term pattern matching to Java, C, and Eiffel [23]. OOMatch [25] and JMatch [20] are Java extensions. OOMatch allows pattern declaration in method parameter...