|
|
1.1 root 1: .so tmac.ilib
2: .TH PATTERNS 2 "The University of Arizona \- 7/29/84"
3: .SH NAME
4: patterns \- SNOBOL4-style pattern matching
5: .SH DESCRIPTION
6: These procedures are adapted from TR 80-25 and TR 81-6. They
7: provide procedural equivalents for most SNOBOL4 patterns and
8: some extensions.
9: .SH SYNOPSIS
10: .nf
11: .sp 1
12: .ta 1.5i
13: \*MAnchor() &ANCHOR = 1 \fR if \*MMode := Anchor
14: Any(s) ANY(S)
15: Apply(s,\*bp) S ? P
16: Arb() ARB
17: Arbno(p) ARBNO(P)
18: Arbx(i) ARB(I)
19: Bal() BAL
20: Break(s) BREAK(S)
21: Breakx(s) BREAKX(S)
22: Cat(p1,\*bp2) P1 P2
23: Discard(p) /P
24: Exog(s) \eS
25: Find(s) FIND(S)
26: Float() &ANCHOR = 0 \fR if \*MMode := Float
27: Len(i) LEN(I)
28: Limit(p,\*bi) P \e i
29: Locate(p) LOCATE(P)
30: Marb() \fRlongest-first\*M ARB
31: Mode() \fRAnchored or unanchored matching (see \*MAnchor\fR and \*MFloat\fR)\*M
32: Notany(s) NOTANY(S)
33: Pos(i) POS(I)
34: Replace(p,\*bs) P \(== S
35: Rpos(i) RPOS(I)
36: Rtab(i) RTAB(I)
37: Span(s) SPAN(S)
38: String(s) S
39: Succeed() SUCCEED
40: Tab(i) TAB(I)
41: Xform(f,\*bp) F(P)
42: .ft R
43: .fi
44: .LP
45: In addition to the procedures above, the following expressions can be
46: used:
47: .nf
48: .sp 1
49: \*Mp1() | p2() P1 | P2
50: v <\- p() P . V \fR(approximate)\*M
51: v := p() P $ V \fR(approximate)\*M
52: fail FAIL
53: =s S\fR (in place of \*MString(s)\fR)\*M
54: p1() || p2() P1 P2 \fR(in place of \*MCat(p1,\*bp2)\fR)\*M
55: .ft R
56: .sp 1
57: .fi
58: .LP
59: Using this system, most SNOBOL4 patterns can be satisfactorily transliterated
60: into Icon procedures and expressions. For example, the pattern
61: .DS
62: SPAN("0123456789") $ N "H" LEN(*N) $ LITERAL
63: .DE
64: can be transliterated into
65: .DS
66: (n <\- Span('0123456789')) || ="H" || (literal <\- Len(n))
67: .DE
68: Concatenation of components is necessary to preserve the pattern-matching properties
69: of SNOBOL4.
70: See the documents listed below for details and limitations.
71: .SH CAVEATS
72: Simulating SNOBOL4 pattern matching using the procedures above
73: is inefficient.
74: .SH SEE ALSO
75: Ralph E. Griswold. \fIPattern Matching in Icon\fR,
76: TR 80-25, The University of Arizona, 1980.
77: .LP
78: Ralph E. Griswold. \fIModels of String Pattern Matching\fR,
79: TR 81-6,
80: Department of Computer Science, The University of Arizona, 1981.
81: .LP
82: Ralph E. Griswold. ``Implementing SNOBOL4 Pattern Matching in Icon'',
83: \fIComputer Languages\fR, Vol. 8, No. 8 (1983), pp. 77-92.
84: .SH AUTHOR
85: Ralph E. Griswold
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.