This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
/
Cursor-builtins.pir
262 lines (228 loc) · 5.61 KB
/
Cursor-builtins.pir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# Copyright (C) 2009, The Perl Foundation.
# $Id$
=head1 NAME
Regex::Cursor-builtins - builtin regexes for Cursor objects
=cut
.include 'cclass.pasm'
.namespace ['Regex';'Cursor']
.sub 'before' :method
.param pmc regex :optional
.local pmc cur
.local int pos
(cur, pos) = self.'!cursor_start'()
if null regex goto fail
$P0 = cur.regex()
unless $P0 goto fail
cur.'!cursor_pass'(pos, 'before')
fail:
.return (cur)
.end
.sub 'ident' :method
.local pmc cur
.local int pos, eos
.local string tgt
(cur, pos, tgt) = self.'!cursor_start'()
eos = length tgt
$S0 = substr tgt, pos, 1
if $S0 == '_' goto ident_1
$I0 = is_cclass .CCLASS_ALPHABETIC, tgt, pos
unless $I0 goto fail
ident_1:
pos = find_not_cclass .CCLASS_WORD, tgt, pos, eos
cur.'!cursor_pass'(pos, 'ident')
fail:
.return (cur)
.end
.sub 'wb' :method
.local pmc cur
.local int pos, eos
.local string tgt
(cur, pos, tgt) = self.'!cursor_start'()
if pos == 0 goto pass
eos = length tgt
if pos == eos goto pass
$I0 = pos - 1
$I1 = is_cclass .CCLASS_WORD, tgt, $I0
$I2 = is_cclass .CCLASS_WORD, tgt, pos
if $I1 == $I2 goto fail
pass:
cur.'!cursor_pass'(pos, 'wb')
fail:
.return (cur)
.end
.sub 'ww' :method
.local pmc cur
.local int pos, eos
.local string tgt
(cur, pos, tgt) = self.'!cursor_start'()
.local pmc debug
debug = getattribute cur, '$!debug'
if null debug goto debug_1
cur.'!cursor_debug'('START', 'ww')
debug_1:
if pos == 0 goto fail
eos = length tgt
if pos == eos goto fail
$I0 = is_cclass .CCLASS_WORD, tgt, pos
unless $I0 goto fail
$I1 = pos - 1
$I0 = is_cclass .CCLASS_WORD, tgt, $I1
unless $I0 goto fail
pass:
cur.'!cursor_pass'(pos, 'ww')
if null debug goto done
cur.'!cursor_debug'('PASS', 'ww')
goto done
fail:
if null debug goto done
cur.'!cursor_debug'('FAIL', 'ww')
done:
.return (cur)
.end
.sub 'ws' :method
.local pmc cur
.local int pos, eos
.local string tgt
(cur, pos, tgt) = self.'!cursor_start'()
eos = length tgt
if pos >= eos goto pass
if pos == 0 goto ws_scan
$I0 = is_cclass .CCLASS_WORD, tgt, pos
unless $I0 goto ws_scan
$I1 = pos - 1
$I0 = is_cclass .CCLASS_WORD, tgt, $I1
if $I0 goto fail
ws_scan:
pos = find_not_cclass .CCLASS_WHITESPACE, tgt, pos, eos
pass:
cur.'!cursor_pass'(pos, 'ws')
fail:
.return (cur)
.end
.sub '!cclass' :anon
.param pmc self
.param string name
.param int cclass
.local pmc cur
.local int pos
.local string tgt
(cur, pos, tgt) = self.'!cursor_start'()
.local pmc debug
debug = getattribute cur, '$!debug'
if null debug goto debug_1
cur.'!cursor_debug'('START', name)
debug_1:
$I0 = is_cclass cclass, tgt, pos
unless $I0 goto fail
inc pos
pass:
cur.'!cursor_pass'(pos, name)
if null debug goto done
cur.'!cursor_debug'('PASS', name)
goto done
fail:
if null debug goto done
cur.'!cursor_debug'('FAIL', name)
done:
.return (cur)
.end
.sub 'alpha' :method
.local pmc cur
.local int pos
.local string tgt
(cur, pos, tgt) = self.'!cursor_start'()
.local pmc debug
debug = getattribute cur, '$!debug'
if null debug goto debug_1
cur.'!cursor_debug'('START', 'alpha')
debug_1:
$I0 = is_cclass .CCLASS_ALPHABETIC, tgt, pos
if $I0 goto pass
$I0 = length tgt
if pos >= $I0 goto fail
$S0 = substr tgt, pos, 1
if $S0 != '_' goto fail
pass:
inc pos
cur.'!cursor_pass'(pos, 'alpha')
if null debug goto done
cur.'!cursor_debug'('PASS', 'alpha')
goto done
fail:
if null debug goto done
cur.'!cursor_debug'('FAIL', 'alpha')
done:
.return (cur)
.end
.sub 'upper' :method
.tailcall '!cclass'(self, 'upper', .CCLASS_UPPERCASE)
.end
.sub 'lower' :method
.tailcall '!cclass'(self, 'lower', .CCLASS_LOWERCASE)
.end
.sub 'digit' :method
.tailcall '!cclass'(self, 'digit', .CCLASS_NUMERIC)
.end
.sub 'xdigit' :method
.tailcall '!cclass'(self, 'xdigit', .CCLASS_HEXADECIMAL)
.end
.sub 'print' :method
.tailcall '!cclass'(self, 'print', .CCLASS_PRINTING)
.end
.sub 'graph' :method
.tailcall '!cclass'(self, 'graph', .CCLASS_GRAPHICAL)
.end
.sub 'cntrl' :method
.tailcall '!cclass'(self, 'cntrl', .CCLASS_CONTROL)
.end
.sub 'punct' :method
.tailcall '!cclass'(self, 'punct', .CCLASS_PUNCTUATION)
.end
.sub 'alnum' :method
.tailcall '!cclass'(self, 'alnum', .CCLASS_ALPHANUMERIC)
.end
.sub 'space' :method
.tailcall '!cclass'(self, 'space', .CCLASS_WHITESPACE)
.end
.sub 'blank' :method
.tailcall '!cclass'(self, 'blank', .CCLASS_BLANK)
.end
.sub 'FAILGOAL' :method
.param string goal
.local string dba
$P0 = getinterp
$P0 = $P0['sub';1]
dba = $P0
have_dba:
.local string message
message = concat "Unable to parse ", dba
message .= ", couldn't find final "
message .= goal
message .= ' at line '
$P0 = getattribute self, '$!target'
$P1 = get_hll_global ['HLL'], 'Compiler'
$I0 = self.'pos'()
$I0 = $P1.'lineof'($P0, $I0)
inc $I0
$S0 = $I0
message .= $S0
have_line:
die message
.end
.sub 'DEBUG' :method
.param pmc arg :optional
.param int has_arg :opt_flag
if has_arg goto have_arg
arg = get_global '$!TRUE'
have_arg:
setattribute self, '$!debug', arg
.return (1)
.end
=head1 AUTHORS
Patrick Michaud <pmichaud@pobox.com> is the author and maintainer.
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: