.so tmac.ilib
.TH PATTERNS 2 "The University of Arizona \- 7/29/84"
.SH NAME
patterns \- SNOBOL4-style pattern matching
.SH DESCRIPTION
These procedures are adapted from TR 80-25 and TR 81-6. They
provide procedural equivalents for most SNOBOL4 patterns and
some extensions.
.SH SYNOPSIS
.nf
.sp 1
.ta 1.5i
\*MAnchor()	&ANCHOR = 1 \fR if \*MMode := Anchor
Any(s)	ANY(S)
Apply(s,\*bp)	S ? P
Arb()	ARB
Arbno(p)	ARBNO(P)
Arbx(i)	ARB(I)
Bal()	BAL
Break(s)	BREAK(S)
Breakx(s)	BREAKX(S)
Cat(p1,\*bp2)	P1 P2
Discard(p)	/P
Exog(s)	\eS
Find(s)	FIND(S)
Float()	&ANCHOR = 0 \fR if \*MMode := Float
Len(i)	LEN(I)
Limit(p,\*bi)	P \e i
Locate(p)	LOCATE(P)
Marb()	\fRlongest-first\*M ARB
Mode()	\fRAnchored or unanchored matching (see \*MAnchor\fR and \*MFloat\fR)\*M
Notany(s)	NOTANY(S)
Pos(i)	POS(I)
Replace(p,\*bs)	P \(== S
Rpos(i)	RPOS(I)
Rtab(i)	RTAB(I)
Span(s)	SPAN(S)
String(s)	S
Succeed()	SUCCEED
Tab(i)	TAB(I)
Xform(f,\*bp)	F(P)
.ft R
.fi
.LP
In addition to the procedures above, the following expressions can be
used:
.nf
.sp 1
\*Mp1() | p2()	P1 | P2
v <\- p()	P . V \fR(approximate)\*M
v := p()	P $ V \fR(approximate)\*M
fail	FAIL
=s		S\fR (in place of \*MString(s)\fR)\*M
p1() || p2()	P1 P2 \fR(in place of \*MCat(p1,\*bp2)\fR)\*M
.ft R
.sp 1
.fi
.LP
Using this system, most SNOBOL4 patterns can be satisfactorily transliterated
into Icon procedures and expressions. For example, the pattern
.DS
SPAN("0123456789") $ N "H" LEN(*N) $ LITERAL
.DE
can be transliterated into
.DS
(n <\- Span('0123456789')) || ="H" || (literal <\- Len(n))
.DE
Concatenation of components is necessary to preserve the pattern-matching properties
of SNOBOL4.
See the documents listed below for details and limitations.
.SH CAVEATS
Simulating SNOBOL4 pattern matching using the procedures above
is inefficient.
.SH SEE ALSO
Ralph E. Griswold. \fIPattern Matching in Icon\fR,
TR 80-25, The University of Arizona, 1980.
.LP
Ralph E. Griswold. \fIModels of String Pattern Matching\fR,
TR 81-6,
Department of Computer Science, The University of Arizona, 1981.
.LP
Ralph E. Griswold. ``Implementing SNOBOL4 Pattern Matching in Icon'',
\fIComputer Languages\fR, Vol. 8, No. 8 (1983), pp. 77-92.
.SH AUTHOR
Ralph E. Griswold