Skip to content

Commit cd23610

Browse files
committed
WIP zero-width pattern tests pass
1 parent 0253ec0 commit cd23610

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/Parsing/String/Replace.purs

+13-11
Original file line numberDiff line numberDiff line change
@@ -320,31 +320,33 @@ splitCapCombinator
320320
=> ParserT String m a
321321
-> ParserT String m {carry::Maybe CodePoint,rlist::List (Tuple String a),arraySize::Int}
322322

323-
splitCapCombinator sep = tailRecM accum {lastPosIndex:0,carry:Nothing,rlist:Nil,arraySize:0}
323+
splitCapCombinator sep = tailRecM accum {carry:Nothing,rlist:Nil,arraySize:0}
324324
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
330334
let
331335
carry_unmatched = case carry of
332336
Nothing -> unmatched
333337
Just cp -> CodePoint.singleton cp <> unmatched
334-
if posIndex == lastPosIndex then do
338+
if posIndex2 == posIndex1 then do
335339
-- sep succeeded but consumed no input, so advance by one codepoint and
336340
-- carry the codepoint over to cons to the next unmatched
337341
carryNext <- optionMaybe anyCodePoint
338342
pure $ Loop
339-
{ lastPosIndex: posIndex+1
340-
, carry: carryNext
343+
{ carry: carryNext
341344
, rlist: (Tuple carry_unmatched matched : rlist)
342345
, arraySize: if String.null carry_unmatched then arraySize + 1 else arraySize + 2
343346
}
344347
else
345348
pure $ Loop
346-
{ lastPosIndex: posIndex
347-
, carry: Nothing
349+
{ carry: Nothing
348350
, rlist: (Tuple carry_unmatched matched : rlist)
349351
, arraySize: if String.null carry_unmatched then arraySize + 1 else arraySize + 2
350352
}

0 commit comments

Comments
 (0)