diff --git a/fcore/make-text-builder.sml b/fcore/make-text-builder.sml new file mode 100644 index 0000000..074308d --- /dev/null +++ b/fcore/make-text-builder.sml @@ -0,0 +1,31 @@ +signature MAKE_TEXT_BUILDER = +sig + type state + type env + + type pos_data = + {chr: char, strIdx: int, absIdx: int, hd: string, tl: string list} + + val folder: pos_data * env * state -> state + val stopFold: state -> bool +end + +functor MakeTextBuilder(Fn: MAKE_TEXT_BUILDER) = +struct + fun buildLoop (strIdx, absIdx, hd, tl, env, state) = + if Fn.stopFold state then + state + else if strIdx = String.size hd then + case tl of + hd :: tl => buildLoop (0, absIdx, hd, tl, env, state) + | [] => state + else + let + val chr = String.sub (hd, strIdx) + val posData = + {chr = chr, strIdx = strIdx, absIdx = absIdx, hd = hd, tl = tl} + val state = Fn.folder (posData, env, state) + in + buildLoop (strIdx + 1, absIdx + 1, hd, tl, env, state) + end +end diff --git a/shf.mlb b/shf.mlb index d3d8e0c..a1fafd7 100644 --- a/shf.mlb +++ b/shf.mlb @@ -17,6 +17,7 @@ fcore/app-type.sml fcore/app-with.sml fcore/text-constants.sml +fcore/make-text-builder.sml ann "allowVectorExps true" in