next up previous
Next: The ``Once''-Rule Up: Non-Standard Language Constructs of Previous: Constructor Terms

Regular Expressions

3mm In practice, strings are widely used as a common data format for exchanging information between different systems. XASM therefore provides a special kind of pattern matching based on regular expressions as they are used in UNIX (e.g. in the ``sed'' program) as well as in many scripting languages like Perl [32] and Tcl [25]. The regular expression pattern matching is invoked using the $\PMEQ$ operator like for pattern matching with constructor terms. If both operands of the $\PMEQ$ operator are strings, then the right operand is interpreted as regular expression and the left operand as string being match against the regular expression. For example, the regular expression pattern matching expression


\begin{asm}
s \PMEQ \verb*+'^[A-Z]'+
\end{asm}

evaluates to true, if s is a string starting with a capital letter.

In regular expressions, parenthesis ``$\backslash$(..$\backslash$)'' can be used to mark certain parts of the expression that correspond to sub-strings of the left-hand-side string, if the pattern matching has been successful. For that, Xasm provide a special form of regular expression pattern matching: If the left-hand-term of a pattern matching expression evaluates to a string object s and the right-hand-term evaluates to a tuple the first argument of which represents a string object r and the remaining arguments are pattern matching variables $\&v_1,\ldots,\&v_n$, the string s is matched against the regular expression r and the sub-matches are put into the pattern matching variables $\&v_1,\ldots,\&v_n$, if the match has been successful.


\begin{asm}
\IF \verb*+''AnyString''+ \PMEQ (\verb*+'^\(.\)\(.*\)$'+,\&hd,\&tl) \THEN
\ldots
\ENDIF
\end{asm}

In this example, the regular expression contains two sub-matches, the first one matches the string "A", the second one the string "nyString".[*]The submatches can be accessed in the then-part of the conditional rules as values of the pattern matching variables &hd and &tl.


next up previous
Next: The ``Once''-Rule Up: Non-Standard Language Constructs of Previous: Constructor Terms
Philipp Kutter 2002-03-18