@@ -320,31 +320,33 @@ splitCapCombinator
320
320
=> ParserT String m a
321
321
-> ParserT String m { carry :: Maybe CodePoint ,rlist :: List (Tuple String a ),arraySize :: Int }
322
322
323
- splitCapCombinator sep = tailRecM accum {lastPosIndex: 0 , carry:Nothing ,rlist:Nil ,arraySize:0 }
323
+ splitCapCombinator sep = tailRecM accum {carry:Nothing ,rlist:Nil ,arraySize:0 }
324
324
where
325
- accum :: { lastPosIndex :: Int ,carry :: Maybe CodePoint ,rlist :: List (Tuple String a ),arraySize :: Int } -> ParserT String m (Step { lastPosIndex :: Int ,carry :: Maybe CodePoint ,rlist :: List (Tuple String a ),arraySize :: Int } { carry :: Maybe CodePoint ,rlist :: List (Tuple String a ),arraySize :: Int } )
326
- accum {lastPosIndex,carry,rlist,arraySize} = do
327
- optionMaybe (try $ anyTill sep) >>= case _ of
328
- Just (Tuple unmatched matched) -> do
329
- Position {index:posIndex} <- position
325
+ posSep = do
326
+ Position {index:posIndex1} <- position
327
+ x <- sep
328
+ Position {index:posIndex2} <- position
329
+ pure $ posIndex1 /\ x /\ posIndex2
330
+ accum :: { carry :: Maybe CodePoint ,rlist :: List (Tuple String a ),arraySize :: Int } -> ParserT String m (Step { carry :: Maybe CodePoint ,rlist :: List (Tuple String a ),arraySize :: Int } { carry :: Maybe CodePoint ,rlist :: List (Tuple String a ),arraySize :: Int } )
331
+ accum {carry,rlist,arraySize} = do
332
+ optionMaybe (try $ anyTill posSep) >>= case _ of
333
+ Just (Tuple unmatched (posIndex1 /\ matched /\ posIndex2)) -> do
330
334
let
331
335
carry_unmatched = case carry of
332
336
Nothing -> unmatched
333
337
Just cp -> CodePoint .singleton cp <> unmatched
334
- if posIndex == lastPosIndex then do
338
+ if posIndex2 == posIndex1 then do
335
339
-- sep succeeded but consumed no input, so advance by one codepoint and
336
340
-- carry the codepoint over to cons to the next unmatched
337
341
carryNext <- optionMaybe anyCodePoint
338
342
pure $ Loop
339
- { lastPosIndex: posIndex+1
340
- , carry: carryNext
343
+ { carry: carryNext
341
344
, rlist: (Tuple carry_unmatched matched : rlist)
342
345
, arraySize: if String .null carry_unmatched then arraySize + 1 else arraySize + 2
343
346
}
344
347
else
345
348
pure $ Loop
346
- { lastPosIndex: posIndex
347
- , carry: Nothing
349
+ { carry: Nothing
348
350
, rlist: (Tuple carry_unmatched matched : rlist)
349
351
, arraySize: if String .null carry_unmatched then arraySize + 1 else arraySize + 2
350
352
}
0 commit comments