Skip to content

Commit 5a089d1

Browse files
committed
fix anyChar position administration
1 parent ef1fb7b commit 5a089d1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Text/Parsing/StringParser/CodePoints.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ anyChar :: Parser Char
5151
anyChar = Parser \{ substr, posFromStart } ->
5252
case SCP.codePointAt 0 substr of
5353
Just cp -> case toChar cp of
54-
Just chr -> Right { result: chr, suffix: { substr: SCP.drop 1 substr, posFromStart: posFromStart + 1 } }
54+
Just chr -> Right { result: chr, suffix: { substr: SCP.drop 1 substr, posFromStart: posFromStart + SCU.length (SCP.singleton cp) } }
5555
Nothing -> Left { pos: posFromStart, error: "CodePoint " <> show cp <> " is not a character" }
5656
Nothing -> Left { pos: posFromStart, error: "Unexpected EOF" }
5757
where

test/CodePoints.purs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ parseFail p input = isLeft $ runParser p input
7272
expectResult :: forall a. Eq a => a -> Parser a -> String -> Boolean
7373
expectResult res p input = runParser p input == Right res
7474

75+
expectPosition :: forall a. Int -> Parser a -> String -> Boolean
76+
expectPosition pos (Parser p) input =
77+
case p { substr: input, posFromStart: 0 } of
78+
Right r -> r.suffix.posFromStart == pos
79+
Left _ -> false
80+
7581
testCodePoints :: Effect Unit
7682
testCodePoints = do
7783

@@ -113,6 +119,8 @@ testCodePoints = do
113119
assert $ expectResult "\x458CA" (string "\x458CA" <* char ']' <* eof) "\x458CA]"
114120
assert $ expectResult "\x458CA" (string "\x458CA" <* string ")" <* eof) "\x458CA)"
115121
assert $ expectResult '\xEEE2' (char '\xEEE2' <* eof) "\xEEE2"
122+
assert $ expectPosition 1 anyChar "\xEEE2"
123+
assert $ expectPosition 2 anyChar "\x458CA"
116124

117125
log "Running overflow tests (may take a while)"
118126

0 commit comments

Comments
 (0)