-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathre.spf
482 lines (381 loc) · 12.3 KB
/
re.spf
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
\ File: re.spf
\ Author: VoidVolker
\ Description: dotnet regex plugin
MODULE: RE_MODULE
WINAPI: Options.Compiled re.dll
WINAPI: Options.CultureInvariant re.dll
WINAPI: Options.ECMAScript re.dll
WINAPI: Options.ExplicitCapture re.dll
WINAPI: Options.IgnoreCase re.dll
WINAPI: Options.IgnorePatternWhitespace re.dll
WINAPI: Options.Multiline re.dll
WINAPI: Options.None re.dll
WINAPI: Options.RightToLeft re.dll
WINAPI: Options.Singleline re.dll
WINAPI: InfiniteMatchTimeout re.dll
EXPORT
WARNING @ WARNING OFF
Options.Compiled CONSTANT Options.Compiled
Options.CultureInvariant CONSTANT Options.CultureInvariant
Options.ECMAScript CONSTANT Options.ECMAScript
Options.ExplicitCapture CONSTANT Options.ExplicitCapture
Options.IgnoreCase CONSTANT Options.IgnoreCase
Options.IgnorePatternWhitespace CONSTANT Options.IgnorePatternWhitespace
Options.Multiline CONSTANT Options.Multiline
Options.None CONSTANT Options.None
Options.RightToLeft CONSTANT Options.RightToLeft
Options.Singleline CONSTANT Options.Singleline
InfiniteMatchTimeout CONSTANT InfiniteMatchTimeout
WARNING !
WINAPI: Regex.Matches re.dll
WINAPI: Regex.MatchesT re.dll
WINAPI: Regex.MatchesA re.dll
WINAPI: Regex.Matches_startat re.dll
WINAPI: Regex.Matches_startatT re.dll
WINAPI: Regex.Matches_startatA re.dll
WINAPI: Matches re.dll
WINAPI: MatchesT re.dll
WINAPI: MatchesA re.dll
WINAPI: Matches_opt re.dll
WINAPI: Matches_optT re.dll
WINAPI: Matches_optA re.dll
WINAPI: Matches_opt_time re.dll
WINAPI: Matches_opt_timeT re.dll
WINAPI: Matches_opt_timeA re.dll
WINAPI: Matches.For re.dll
WINAPI: Matches.Free re.dll
WINAPI: Regex.Free re.dll
WINAPI: Regex re.dll
WINAPI: RegexT re.dll
WINAPI: RegexA re.dll
WINAPI: Regex_opt re.dll
WINAPI: Regex_optT re.dll
WINAPI: Regex_optA re.dll
WINAPI: Regex_opt_time re.dll
WINAPI: Regex_opt_timeT re.dll
WINAPI: Regex_opt_timeA re.dll
WINAPI: Regex.MatchTimeout re.dll
WINAPI: Regex.Options re.dll
WINAPI: Regex.RightToLeft re.dll
WINAPI: Regex.GetGroupNames re.dll
WINAPI: GroupNames.For re.dll
WINAPI: GroupNames.ForU re.dll
WINAPI: GroupNames.ForT re.dll
WINAPI: GroupNames.ForA re.dll
WINAPI: GroupNames.toArrU re.dll
WINAPI: GroupNames.toArrT re.dll
WINAPI: GroupNames.toArrA re.dll
WINAPI: Regex.GetGroupNumbers re.dll
WINAPI: GroupNumbers.For re.dll
WINAPI: GroupNumbers.toArr re.dll
WINAPI: Regex.IsMatch re.dll
WINAPI: Regex.IsMatchT re.dll
WINAPI: Regex.IsMatchA re.dll
WINAPI: Regex.IsMatch_str_int re.dll
WINAPI: Regex.IsMatch_str_intT re.dll
WINAPI: Regex.IsMatch_str_intA re.dll
WINAPI: IsMatch re.dll
WINAPI: IsMatchT re.dll
WINAPI: IsMatchA re.dll
WINAPI: IsMatch_opt re.dll
WINAPI: IsMatch_optT re.dll
WINAPI: IsMatch_optA re.dll
WINAPI: IsMatch_opt_time re.dll
WINAPI: IsMatch_opt_timeT re.dll
WINAPI: IsMatch_timeA re.dll
WINAPI: Regex.Match re.dll
WINAPI: Regex.MatchT re.dll
WINAPI: Regex.MatchA re.dll
WINAPI: Regex.Match_int re.dll
WINAPI: Regex.Match_intT re.dll
WINAPI: Regex.Match_intA re.dll
WINAPI: Regex.Match_int_int re.dll
WINAPI: Regex.Match_int_intT re.dll
WINAPI: Regex.Match_int_intA re.dll
WINAPI: Match re.dll
WINAPI: MatchT re.dll
WINAPI: MatchA re.dll
WINAPI: Match_opt re.dll
WINAPI: Match_optT re.dll
WINAPI: Match_optA re.dll
WINAPI: Match_opt_time re.dll
WINAPI: Match_opt_timeT re.dll
WINAPI: Match_opt_timeA re.dll
WINAPI: Match.Next re.dll
WINAPI: Match.Groups re.dll
WINAPI: Match.Success re.dll
WINAPI: Match.Index re.dll
WINAPI: Match.Value re.dll
WINAPI: Match.ValueU re.dll
WINAPI: Match.ValueT re.dll
WINAPI: Match.ValueA re.dll
WINAPI: Group.Captures re.dll
WINAPI: Group.Index re.dll
WINAPI: Group.Length re.dll
WINAPI: Group.Success re.dll
WINAPI: Group.Value re.dll
WINAPI: Group.ValueU re.dll
WINAPI: Group.ValueT re.dll
WINAPI: Group.ValueA re.dll
WINAPI: Capture.Index re.dll
WINAPI: Capture.Length re.dll
WINAPI: Capture.Value re.dll
WINAPI: Capture.ValueU re.dll
WINAPI: Capture.ValueT re.dll
WINAPI: Capture.ValueA re.dll
WINAPI: Match.Groups.Pos re.dll
WINAPI: Match.Groups.Str re.dll
WINAPI: Match.Groups.StrT re.dll
WINAPI: Match.Groups.StrA re.dll
WINAPI: Match.Groups.For re.dll
WINAPI: Group.Captures.For re.dll
WINAPI: Value.Free re.dll
WINAPI: Match.Free re.dll
WINAPI: Group.Free re.dll
WINAPI: Capture.Free re.dll
WINAPI: Groups.Pos.Free re.dll
WINAPI: Groups.Str.Free re.dll
WINAPI: Regex.Replace_cb re.dll
WINAPI: Regex.Replace_cbT re.dll
WINAPI: Regex.Replace_cbA re.dll
WINAPI: Regex.Replace_cb_count re.dll
WINAPI: Regex.Replace_cb_countT re.dll
WINAPI: Regex.Replace_cb_countA re.dll
WINAPI: Regex.Replace re.dll
WINAPI: Regex.ReplaceT re.dll
WINAPI: Regex.ReplaceA re.dll
WINAPI: Regex.Replace_count re.dll
WINAPI: Regex.Replace_countT re.dll
WINAPI: Regex.Replace_countA re.dll
WINAPI: Regex.Replace_count_startat re.dll
WINAPI: Regex.Replace_count_startatT re.dll
WINAPI: Regex.Replace_count_startatA re.dll
WINAPI: Replace_cb re.dll
WINAPI: Replace_cbT re.dll
WINAPI: Replace_cbA re.dll
WINAPI: Replace_cb_opt re.dll
WINAPI: Replace_cb_optT re.dll
WINAPI: Replace_cb_optA re.dll
WINAPI: Replace_cb_opt_time re.dll
WINAPI: Replace_cb_opt_timeT re.dll
WINAPI: Replace_cb_opt_timeA re.dll
WINAPI: Replace re.dll
WINAPI: ReplaceT re.dll
WINAPI: ReplaceA re.dll
WINAPI: Replace_opt re.dll
WINAPI: Replace_optT re.dll
WINAPI: Replace_optA re.dll
WINAPI: Replace_opt_time re.dll
WINAPI: Replace_opt_timeT re.dll
WINAPI: Replace_opt_timeA re.dll
WINAPI: Regex.Split re.dll
WINAPI: Regex.SplitT re.dll
WINAPI: Regex.SplitA re.dll
WINAPI: Regex.Split_count re.dll
WINAPI: Regex.Split_countT re.dll
WINAPI: Regex.Split_countA re.dll
WINAPI: Regex.Split_count_startat re.dll
WINAPI: Regex.Split_count_startatT re.dll
WINAPI: Regex.Split_count_startatA re.dll
WINAPI: Split re.dll
WINAPI: SplitT re.dll
WINAPI: SplitA re.dll
WINAPI: Split_opt re.dll
WINAPI: Split_optT re.dll
WINAPI: Split_optA re.dll
WINAPI: Split_opt_time re.dll
WINAPI: Split_opt_timeT re.dll
WINAPI: Split_opt_timeA re.dll
WINAPI: Split.For re.dll
WINAPI: Split.ForU re.dll
WINAPI: Split.ForT re.dll
WINAPI: Split.ForA re.dll
WINAPI: Split.toArrU re.dll
WINAPI: Split.toArrT re.dll
WINAPI: Split.toArrA re.dll
WINAPI: Split.Free re.dll
\ ----------------------------------------------------------------------------------------------------
: S>UZ \ ( a u -- a_unicode )
S>UNICODE DROP
;
\ ----------------------------------------------------------------------------------------------------
\ Regex Options
0 VALUE reCompilationOptions
\ 0
\ CELL -- -Regex
\ CELL -- -ReOptions
\ CELL -- -RePattern
\ CONSTANT /Regex
: ReDefOptions
Options.Compiled TO reCompilationOptions
;
: ReAddOption \ ( RegexOption -- )
reCompilationOptions OR TO reCompilationOptions
;
: ReCompiled \ ( -- )
Options.Compiled ReAddOption
; IMMEDIATE
: ReCultureInvariant \ ( -- )
Options.CultureInvariant ReAddOption
; IMMEDIATE
: ReECMAScript \ ( -- )
Options.ECMAScript ReAddOption
; IMMEDIATE
: ReExplicitCapture \ ( -- )
Options.ExplicitCapture ReAddOption
; IMMEDIATE
: ReIgnoreCase \ ( -- )
Options.IgnoreCase ReAddOption
; IMMEDIATE
: ReIgnorePatternWhitespace \ ( -- )
Options.IgnorePatternWhitespace ReAddOption
; IMMEDIATE
: ReMultiline \ ( -- )
Options.Multiline ReAddOption
; IMMEDIATE
: ReNone \ ( -- )
Options.None TO reCompilationOptions
; IMMEDIATE
: ReRightToLeft \ ( -- )
Options.RightToLeft ReAddOption
; IMMEDIATE
: ReSingleline \ ( -- )
Options.Singleline ReAddOption
; IMMEDIATE
\ Additional Options
: ReMaxTime
;
: ReStartPos
;
: ReEndPos
;
: ReCount
;
\ ----------------------------------------------------------------------------------------------------
\ Regex creation
: UREGEX \ ( a_utf u -- regex )
DROP ReDefOptions SWAP Regex_opt
ReDefOptions
;
: REGEX \ ( a u -- regex )
S>UNICODE DROP reCompilationOptions SWAP Regex_opt
ReDefOptions
;
: OPT-REGEX \ ( a u options -- regex )
-ROT
S>UNICODE DROP Regex_opt
;
: OPT-UREGEX \ ( a u options -- regex )
NIP SWAP Regex_opt
;
\ --------------------------------------------------
\ Regex builder
\ i = IgnoreCase
\ m = Multiline
\ n = ExplicitCapture
\ s = Singleline
\ x = IgnorePatternWhitespace
\ r = RightToLeft
\ e = ECMAScript
\ c = CultureInvariant
\ /pattern/imnsxrec
\ /pattern/
\ S" /pattern/imnsxre" IsRegex?
\ S" /pattern/"
: IsRegex? \ ( a u -- true | false )
DUP 3 < IF 2DROP FALSE EXIT THEN
OVER C@ [CHAR] / <> IF 2DROP FALSE EXIT THEN \ a u
1 -1 D+
S" /" BACK-SEARCH NIP NIP
;
: ParseOptions \ ( a u -- a1 u1 options )
DUP IFNOT NIP EXIT THEN \ a 0 -> exit
OVER SWAP 0 0 2SWAP \ a 0 0 a u
OVER + 1- DO
I C@ CASE
[CHAR] i OF Options.IgnoreCase OR ENDOF
[CHAR] m OF Options.Multiline OR ENDOF
[CHAR] n OF Options.ExplicitCapture OR ENDOF
[CHAR] s OF Options.Singleline OR ENDOF
[CHAR] x OF Options.IgnorePatternWhitespace OR ENDOF
[CHAR] r OF Options.RightToLeft OR ENDOF
[CHAR] e OF Options.ECMAScript OR ENDOF
[CHAR] c OF Options.CultureInvariant OR ENDOF
[CHAR] / OF \ a 0 opt
-ROT DROP \ opt a
I OVER \ opt a a1 a
- \ opt a u1
ROT \ a u1 opt
LEAVE
ENDOF
DUP OF ABORT" Unknow regex option" ENDOF
ENDCASE
-1 +LOOP
;
: BuildRegex \ ( a1 u1 -- regex )
1 -1 D+
ParseOptions \ a1 u2 options
OPT-REGEX
;
WARNING @ WARNING OFF
: NOTFOUND ( a u -- )
2DUP 2>R ['] NOTFOUND CATCH
IF
2DROP
2R@ IsRegex? IF 2R@ BuildRegex ELSE -2003 THROW THEN
THEN
RDROP RDROP
;
WARNING !
\ ----------------------------------------------------------------------------------------------------
\ IsMatch
: ReIsMatch \ ( a u regex -- ? )
-ROT S>UNICODE DROP SWAP Regex.IsMatch
;
: ReIsMatchU \ ( a u regex -- ? )
NIP Regex.IsMatch
;
: ReIsMatchZ \ ( az regex -- ? )
Regex.IsMatch
;
\ ----------------------------------------------------------------------------------------------------
\ Match
: ReMatch \ ( a u regex -- match )
;
: MatchValue \ ( match -- a u )
;
: MatchNext \ ( match1 -- match2 )
;
\ ----------------------------------------------------------------------------------------------------
\ Matches
: ReMatches \ ( a u regex -- Matches )
;
: ForMatches( \ ( Matches -- )
;
: )ForMatches
;
: ForGroups( \ ( Groups -- )
;
: )ForGroups
;
: ForCaptures( \ ( Captures -- )
;
: )ForCaptures
;
\ ----------------------------------------------------------------------------------------------------
\ Replace
: ReReplace \ ( a1 u1 a2 u2 regex -- a u )
;
: ReReplace( \ ( a1 u1 a2 u2 regex -- )
;
: )ReReplace
;
\ ----------------------------------------------------------------------------------------------------
\ Split
: ReSplit \ ( a1 u1 regex -- ????? )
;
: ReSplit( \ ( a1 u1 regex -- )
;
: )ReSplit
;
;MODULE