Mercurial > repos > rhope
comparison countstring.rhope @ 2:73e978d590c7
Adding WIP compiler code
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 29 Apr 2009 02:58:03 -0400 |
parents | |
children | 0a4682be2db2 |
comparison
equal
deleted
inserted
replaced
1:b3f71490858c | 2:73e978d590c7 |
---|---|
1 | |
2 Blueprint Count String | |
3 { | |
4 Text | |
5 Line | |
6 Column | |
7 } | |
8 | |
9 Count String[text:out] | |
10 { | |
11 out <- Count String At Pos[text, 0, 0] | |
12 } | |
13 | |
14 Count String At Pos[text,line,col:out] | |
15 { | |
16 out <- [[[Build["Count String"]]Text <<[text]]Line <<[line]]Column <<[col] | |
17 } | |
18 | |
19 Slice@Count String[string,index:left,right] | |
20 { | |
21 | |
22 If[[index] = [0]] | |
23 { | |
24 left <- [string]Text <<[""] | |
25 right <- Val[string] | |
26 }{ | |
27 ltext,rtext <- [[string]Text >>]Slice[index] | |
28 left <- [string]Text <<[ltext] | |
29 parts <- [ltext]Split["\n"] | |
30 last line <- [[parts]Length] - [1] | |
31 rline <- [[string]Line >>] + [last line] | |
32 prercol <- [[parts]Index[last line]]Length | |
33 If[[last line] > [0]] | |
34 { | |
35 rcol <- Val[prercol] | |
36 }{ | |
37 rcol <- [prercol] + [[string]Column >>] | |
38 } | |
39 right <- Count String At Pos[rtext, rline, rcol] | |
40 } | |
41 } | |
42 | |
43 Length@Count String[string:out] | |
44 { | |
45 out <- Length[[string]Text >>] | |
46 } | |
47 | |
48 Append@Count String[left,right:out] | |
49 { | |
50 If[[[left]Length] > [0]] | |
51 { | |
52 out <- [left]Text << [ [To String[left]]Append[To String[right]] ] | |
53 }{ | |
54 out <- right | |
55 } | |
56 } | |
57 | |
58 =@Count String[left,right:out] | |
59 { | |
60 out <- [To String[left]] = [To String[right]] | |
61 } | |
62 | |
63 Get DString@Count String[string, delims:after,before,delim,nomatch] | |
64 { | |
65 ,,delim,nomatch <- [[string]Text >>]Get DString[delims] | |
66 { | |
67 If[[dlines] > [0]] | |
68 { | |
69 cols <- Val[dcols] | |
70 }{ | |
71 If[[blines] > [0]] | |
72 { | |
73 cols <- [bcols] + [dcols] | |
74 }{ | |
75 cols <- [[bcols] + [dcols]] + [[string]Column >>] | |
76 } | |
77 } | |
78 after <- Count String At Pos[~, [[blines]+[dlines]] + [[string]Line >>], cols] | |
79 }{ | |
80 before <- [string]Text <<[~] | |
81 bparts <- [~]Split["\n"] | |
82 preblines <- [[bparts]Length] - [1] | |
83 If[[preblines] > [-1]] | |
84 { | |
85 blines <- Val[preblines] | |
86 bcols <- Length[[bparts]Index[blines]] | |
87 }{ | |
88 bcols <- 0 | |
89 blines <- 0 | |
90 } | |
91 }{ | |
92 dparts <- [~]Split["\n"] | |
93 dlines <- [[dparts]Length] - [1] | |
94 dcols <- Length[[dparts]Index[dlines]] | |
95 } | |
96 } | |
97 | |
98 To String@Count String[string:out] | |
99 { | |
100 out <- [string]Text >> | |
101 } | |
102 | |
103 Empty@Count String[string:out] | |
104 { | |
105 out <- Count String[""] | |
106 } |