@@ -133,39 +133,29 @@ let xmlBoilerPlateString = @"<?xml version=""1.0"" encoding=""utf-8""?>
133133</root>"
134134
135135
136+ type HoleType = string
136137
137138
138139// The kinds of 'holes' we can do
139- type HoleType =
140- | Int // %d
141- | String // %s
142- | Float // %f
143-
144- let HoleTypeToString this =
145- match this with
146- | HoleType.Int -> " System.Int32"
147- | HoleType.String -> " System.String"
148- | HoleType.Float -> " System.Double"
149-
150- let ComputeHoles filename lineNum ( txt : string ) : HoleType [] * string =
140+ let ComputeHoles filename lineNum ( txt : string ) : ResizeArray < HoleType > * string =
151141 // takes in a %d%s kind of string, returns array of HoleType and {0}{1} kind of string
152142 let mutable i = 0
153143 let mutable holeNumber = 0
154- let mutable holes = [] // reverse order
144+ let mutable holes = ResizeArray () // order
155145 let sb = new System.Text.StringBuilder()
156146 let AddHole holeType =
157147 sb.Append( sprintf " {%d }" holeNumber) |> ignore
158148 holeNumber <- holeNumber + 1
159- holes <- holeType :: holes
149+ holes.Add ( holeType)
160150 while i < txt.Length do
161151 if txt.[ i] = '%' then
162152 if i+ 1 = txt.Length then
163153 Err( filename, lineNum, " (at end of string) % must be followed by d, f, s, or %" )
164154 else
165155 match txt.[ i+ 1 ] with
166- | 'd' -> AddHole HoleType.Int
167- | 'f' -> AddHole HoleType.Float
168- | 's' -> AddHole HoleType .String
156+ | 'd' -> AddHole " System.Int32 "
157+ | 'f' -> AddHole " System.Double "
158+ | 's' -> AddHole " System .String"
169159 | '%' -> sb.Append( '%' ) |> ignore
170160 | c -> Err( filename, lineNum, sprintf " '%%%c ' is not a valid sequence, only %%d %%f %%s or %%%%" c)
171161 i <- i + 2
@@ -176,7 +166,7 @@ let ComputeHoles filename lineNum (txt:string) : HoleType[] * string =
176166 | c -> sb.Append c |> ignore
177167 i <- i + 1
178168 //printfn "holes.Length = %d, lineNum = %d" holes.Length //lineNum txt
179- ( holes |> List.rev |> List.toArray , sb.ToString())
169+ ( holes, sb.ToString())
180170
181171let Unquote ( s : string ) =
182172 if s.StartsWith " \" " && s.EndsWith " \" " then s.Substring( 1 , s.Length - 2 )
@@ -221,7 +211,7 @@ let ParseLine filename lineNum (txt:string) =
221211 with
222212 e -> Err( filename, lineNum, sprintf " Error calling System.String.Format (note that curly braces must be escaped, and there cannot be trailing space on the line): >>>%s <<< -- %s " ( txt.Substring i) e.Message)
223213 let holes , netFormatString = ComputeHoles filename lineNum str
224- ( lineNum, ( errNum, ident), str, holes, netFormatString)
214+ ( lineNum, ( errNum, ident), str, holes.ToArray () , netFormatString)
225215
226216let stringBoilerPlatePrefix = @"
227217open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
@@ -399,7 +389,7 @@ let RunMain(filename, outFilename, outXmlFilenameOpt, projectNameOpt) =
399389 else
400390 formalArgs.Append " , " |> ignore
401391 actualArgs.Append " " |> ignore
402- formalArgs.Append( sprintf " a%d : %s " ! n ( HoleTypeToString hole) ) |> ignore
392+ formalArgs.Append( sprintf " a%d : %s " ! n hole) |> ignore
403393 actualArgs.Append( sprintf " a%d " ! n) |> ignore
404394 n := ! n + 1
405395 formalArgs.Append " )" |> ignore
@@ -408,9 +398,9 @@ let RunMain(filename, outFilename, outXmlFilenameOpt, projectNameOpt) =
408398 let justPercentsFromFormatString =
409399 ( holes |> Array.fold ( fun acc holeType ->
410400 acc + match holeType with
411- | HoleType.Int -> " ,,,%d "
412- | HoleType.Float -> " ,,,%f "
413- | HoleType .String -> " ,,,%s " ) " " ) + " ,,,"
401+ | " System.Int32 " -> " ,,,%d "
402+ | " System.Double " -> " ,,,%f "
403+ | " System .String" -> " ,,,%s " ) " " ) + " ,,,"
414404 let errPrefix = match optErrNum with
415405 | None -> " "
416406 | Some n -> sprintf " %d , " n
0 commit comments