|
|
1.1 root 1:
2:
3:
4: PATTERNS(2) Icon Program Library PATTERNS(2)
5:
6:
7:
8: NNNNAAAAMMMMEEEE
9: patterns - SNOBOL4-style pattern matching
10:
11: DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
12: These procedures are adapted from TR 80-25 and TR 81-6. They
13: provide procedural equivalents for most SNOBOL4 patterns and
14: some extensions.
15:
16: SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
17: AAAAnnnncccchhhhoooorrrr(((()))) &&&&AAAANNNNCCCCHHHHOOOORRRR ==== 1111 if MMMMooooddddeeee ::::==== AAAAnnnncccchhhhoooorrrr
18: AAAAnnnnyyyy((((ssss)))) AAAANNNNYYYY((((SSSS))))
19: AAAAppppppppllllyyyy((((ssss,,,,pppp)))) SSSS ???? PPPP
20: AAAArrrrbbbb(((()))) AAAARRRRBBBB
21: AAAArrrrbbbbnnnnoooo((((pppp)))) AAAARRRRBBBBNNNNOOOO((((PPPP))))
22: AAAArrrrbbbbxxxx((((iiii)))) AAAARRRRBBBB((((IIII))))
23: BBBBaaaallll(((()))) BBBBAAAALLLL
24: BBBBrrrreeeeaaaakkkk((((ssss)))) BBBBRRRREEEEAAAAKKKK((((SSSS))))
25: BBBBrrrreeeeaaaakkkkxxxx((((ssss)))) BBBBRRRREEEEAAAAKKKKXXXX((((SSSS))))
26: CCCCaaaatttt((((pppp1111,,,,pppp2222)))) PPPP1111 PPPP2222
27: DDDDiiiissssccccaaaarrrrdddd((((pppp)))) ////PPPP
28: EEEExxxxoooogggg((((ssss)))) \\\\SSSS
29: FFFFiiiinnnndddd((((ssss)))) FFFFIIIINNNNDDDD((((SSSS))))
30: FFFFllllooooaaaatttt(((()))) &&&&AAAANNNNCCCCHHHHOOOORRRR ==== 0000 if MMMMooooddddeeee ::::==== FFFFllllooooaaaatttt
31: LLLLeeeennnn((((iiii)))) LLLLEEEENNNN((((IIII))))
32: LLLLiiiimmmmiiiitttt((((pppp,,,,iiii)))) PPPP \\\\ iiii
33: LLLLooooccccaaaatttteeee((((pppp)))) LLLLOOOOCCCCAAAATTTTEEEE((((PPPP))))
34: MMMMaaaarrrrbbbb(((()))) longest-first AAAARRRRBBBB
35: MMMMooooddddeeee(((()))) Anchored or unanchored matching (see AAAAnnnncccchhhhoooorrrr and FFFFllllooooaaaatttt)
36: NNNNoooottttaaaannnnyyyy((((ssss)))) NNNNOOOOTTTTAAAANNNNYYYY((((SSSS))))
37: PPPPoooossss((((iiii)))) PPPPOOOOSSSS((((IIII))))
38: RRRReeeeppppllllaaaacccceeee((((pppp,,,,ssss)))) PPPP =_=_=_=_ SSSS
39: RRRRppppoooossss((((iiii)))) RRRRPPPPOOOOSSSS((((IIII))))
40: RRRRttttaaaabbbb((((iiii)))) RRRRTTTTAAAABBBB((((IIII))))
41: SSSSppppaaaannnn((((ssss)))) SSSSPPPPAAAANNNN((((SSSS))))
42: SSSSttttrrrriiiinnnngggg((((ssss)))) SSSS
43: SSSSuuuucccccccceeeeeeeedddd(((()))) SSSSUUUUCCCCCCCCEEEEEEEEDDDD
44: TTTTaaaabbbb((((iiii)))) TTTTAAAABBBB((((IIII))))
45: XXXXffffoooorrrrmmmm((((ffff,,,,pppp)))) FFFF((((PPPP))))
46:
47: In addition to the procedures above, the following expres-
48: sions can be used:
49:
50: pppp1111(((()))) |||| pppp2222(((()))) PPPP1111 |||| PPPP2222
51: vvvv <<<<---- pppp(((()))) PPPP .... VVVV (approximate)
52: vvvv ::::==== pppp(((()))) PPPP $$$$ VVVV (approximate)
53: ffffaaaaiiiillll FFFFAAAAIIIILLLL
54: ====ssss SSSS (in place of SSSSttttrrrriiiinnnngggg((((ssss)))))
55: pppp1111(((()))) |||||||| pppp2222(((()))) PPPP1111 PPPP2222 (in place of CCCCaaaatttt((((pppp1111,,,,pppp2222)))))
56:
57:
58: Using this system, most SNOBOL4 patterns can be satisfac-
59: torily transliterated into Icon procedures and expressions.
60:
61:
62:
63: Version 5.9 The University of Arizona - 7/29/84 1
64:
65:
66:
67:
68:
69:
70: PATTERNS(2) Icon Program Library PATTERNS(2)
71:
72:
73:
74: For example, the pattern
75:
76: SPAN("0123456789") $ N "H" LEN(*N) $ LITERAL
77:
78: can be transliterated into
79:
80: (n <- Span('0123456789')) || ="H" || (literal <- Len(n))
81:
82: Concatenation of components is necessary to preserve the
83: pattern-matching properties of SNOBOL4. See the documents
84: listed below for details and limitations.
85:
86: CCCCAAAAVVVVEEEEAAAATTTTSSSS
87: Simulating SNOBOL4 pattern matching using the procedures
88: above is inefficient.
89:
90: SSSSEEEEEEEE AAAALLLLSSSSOOOO
91: Ralph E. Griswold. _P_a_t_t_e_r_n _M_a_t_c_h_i_n_g _i_n _I_c_o_n, TR 80-25, The
92: University of Arizona, 1980.
93:
94: Ralph E. Griswold. _M_o_d_e_l_s _o_f _S_t_r_i_n_g _P_a_t_t_e_r_n _M_a_t_c_h_i_n_g, TR
95: 81-6, Department of Computer Science, The University of
96: Arizona, 1981.
97:
98: Ralph E. Griswold. ``Implementing SNOBOL4 Pattern Matching
99: in Icon'', _C_o_m_p_u_t_e_r _L_a_n_g_u_a_g_e_s, Vol. 8, No. 8 (1983), pp.
100: 77-92.
101:
102: AAAAUUUUTTTTHHHHOOOORRRR
103: Ralph E. Griswold
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129: Version 5.9 The University of Arizona - 7/29/84 2
130:
131:
132:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.