Mercurial > repos > rhope
annotate pattern.rhope @ 114:25a205094f9b
More performance optimizations
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 13 Oct 2010 01:15:04 +0000 |
parents | a7add4db4a25 |
children | d86df83402f3 |
rev | line source |
---|---|
108
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 Blueprint Empty Pattern |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 Empty Pattern[:out] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 out <- Build[Empty Pattern()] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 Add String@Empty Pattern[pattern,string,idx:out] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 out <- [pattern]_Add String[string,0,idx] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 _Add String@Empty Pattern[pattern,string,n,idx:out] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 If[[n]<[[string]Byte Length]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 out <- [[[[[[Build[Pattern()] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 ]Byte <<[[string]Byte[n]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 ]Left <<[pattern] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 ]Right <<[pattern] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 ]Straight <<[[pattern]_Add String[string, [n]+[1],idx]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 ]Terminal? <<[[n]=[[[string]Byte Length]-[1]]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 ]Index <<[idx] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 }{ |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 out <- pattern |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 Blueprint Pattern |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 Byte |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 Left |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 Right |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 Straight |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 Terminal? |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 Index |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 _Add String@Pattern[pattern,string,n,idx:out] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 If[[n]<[[string]Byte Length]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 b <- [string]Byte[n] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 myb <- [pattern]Byte >> |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 If[[b]<[myb]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 out <- [pattern]Left <<[[[pattern]Left >>]_Add String[string,n,idx]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 }{ |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 If[[b]>[myb]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 out <- [pattern]Right <<[[[pattern]Right >>]_Add String[string,n,idx]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 }{ |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 newpat <- [pattern]Straight <<[[[pattern]Straight >>]_Add String[string,[n]+[1],idx]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 If[[n]=[[[string]Byte Length]-[1]]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 out <- [newpat]Terminal? <<[Yes] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 }{ |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 out <- Val[newpat] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 }{ |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 out <- pattern |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 Add String@Pattern[pattern,string,idx:out] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 out <- [pattern]_Add String[string,0,idx] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 Pattern@List[list:out] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 out <- Fold[Add String[?], Empty Pattern[], list] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 Pattern@List Leaf[list:out] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 out <- Fold[Add String[?], Empty Pattern[], list] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 Pattern@Pattern[p:out] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 out <- p |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 _Match@Empty Pattern[pattern,string,n:num,no match] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 no match <- Yes |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 Match@Empty Pattern[pattern,string:num,no match] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 no match <- Yes |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 Match@Pattern[pattern,string:num,no match,idx] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 num,no match,idx <- [pattern]_Match[string,0] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 _Match@Pattern[pattern,string,n:num,no match,idx] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 b <- [string]Byte[n] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 myb <- [pattern]Byte >> |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 If[[b]=[myb]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 num, ,idx <- [[pattern]Straight >>]_Match[string, [n]+[1]] { } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 ,no match <- If[[pattern]Terminal? >>] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 num <- [n]+[1] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 idx <- Index >>[pattern] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 }{ |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 If[[b]<[myb]] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 { |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 num, no match, idx <- [[pattern]Left >>]_Match[string, n] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 }{ |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 num, no match, idx <- [[pattern]Right >>]_Match[string, n] |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 } |
a7add4db4a25
Improved implementation of Pattern
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 |