Mercurial > repos > rhope
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/countstring.rhope Wed Apr 29 02:58:03 2009 -0400 @@ -0,0 +1,106 @@ + +Blueprint Count String +{ + Text + Line + Column +} + +Count String[text:out] +{ + out <- Count String At Pos[text, 0, 0] +} + +Count String At Pos[text,line,col:out] +{ + out <- [[[Build["Count String"]]Text <<[text]]Line <<[line]]Column <<[col] +} + +Slice@Count String[string,index:left,right] +{ + + If[[index] = [0]] + { + left <- [string]Text <<[""] + right <- Val[string] + }{ + ltext,rtext <- [[string]Text >>]Slice[index] + left <- [string]Text <<[ltext] + parts <- [ltext]Split["\n"] + last line <- [[parts]Length] - [1] + rline <- [[string]Line >>] + [last line] + prercol <- [[parts]Index[last line]]Length + If[[last line] > [0]] + { + rcol <- Val[prercol] + }{ + rcol <- [prercol] + [[string]Column >>] + } + right <- Count String At Pos[rtext, rline, rcol] + } +} + +Length@Count String[string:out] +{ + out <- Length[[string]Text >>] +} + +Append@Count String[left,right:out] +{ + If[[[left]Length] > [0]] + { + out <- [left]Text << [ [To String[left]]Append[To String[right]] ] + }{ + out <- right + } +} + +=@Count String[left,right:out] +{ + out <- [To String[left]] = [To String[right]] +} + +Get DString@Count String[string, delims:after,before,delim,nomatch] +{ + ,,delim,nomatch <- [[string]Text >>]Get DString[delims] + { + If[[dlines] > [0]] + { + cols <- Val[dcols] + }{ + If[[blines] > [0]] + { + cols <- [bcols] + [dcols] + }{ + cols <- [[bcols] + [dcols]] + [[string]Column >>] + } + } + after <- Count String At Pos[~, [[blines]+[dlines]] + [[string]Line >>], cols] + }{ + before <- [string]Text <<[~] + bparts <- [~]Split["\n"] + preblines <- [[bparts]Length] - [1] + If[[preblines] > [-1]] + { + blines <- Val[preblines] + bcols <- Length[[bparts]Index[blines]] + }{ + bcols <- 0 + blines <- 0 + } + }{ + dparts <- [~]Split["\n"] + dlines <- [[dparts]Length] - [1] + dcols <- Length[[dparts]Index[dlines]] + } +} + +To String@Count String[string:out] +{ + out <- [string]Text >> +} + +Empty@Count String[string:out] +{ + out <- Count String[""] +}