File tree Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -285,19 +285,25 @@ module ParserMonad =
285
285
/// Run a parser within a bounded section of the input stream.
286
286
let inline boundRepeat ( n : ^T ) ( p : ParserMonad < 'a >) : ParserMonad < 'a array > =
287
287
288
-
289
- let rec loop i ( data : 'a array ) =
290
- parseMidi {
291
- if i < n then
292
- let! r = p
293
- data.[ int i] <- r
294
- return ! ( loop ( i + LanguagePrimitives.GenericOne) data)
295
- }
296
- parseMidi {
297
- let data = Array.zeroCreate ( int n) // can't use array expression inside a CE (at least as is)
298
- do ! loop LanguagePrimitives.GenericZero data
299
- return data
300
- }
288
+ ParserMonad( fun data state ->
289
+ let result = Array.zeroCreate ( int n)
290
+ let mutable lastState = state
291
+ let errors = ResizeArray()
292
+ for i in LanguagePrimitives.GenericZero .. n do
293
+ match apply1 p data lastState with
294
+ | Ok ( item, state) ->
295
+ lastState <- state
296
+ result.[ int i] <- item
297
+ | Error e ->
298
+ errors.Add ( i, e)
299
+
300
+ if Seq.isEmpty errors then
301
+ let message =
302
+ errors |> Seq.map ( sprintf " %A " ) |> String.concat System.Environment.NewLine
303
+ Error ( ParseError( lastState.Position , ErrMsg.Other( message)))
304
+ else
305
+ Ok ( result, lastState)
306
+ )
301
307
302
308
/// Apply the parser for /count/ times, derive the final answer
303
309
/// from the intermediate list with the supplied function.
Original file line number Diff line number Diff line change @@ -93,8 +93,6 @@ module ReadFile =
93
93
94
94
let textEvent textType =
95
95
parseMidi {
96
- let! a = assertWord8 2 uy
97
- let! b = peek
98
96
let! text = getVarlenText
99
97
return TextEvent( textType, text)
100
98
}
You can’t perform that action at this time.
0 commit comments