Skip to content

Commit

Permalink
fix: reset hint valid offset when hide combinator succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Feb 7, 2024
1 parent 7fb6bcc commit 4f00266
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Text/Gigaparsec/Errors/Combinator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ hide :: Parsec a -> Parsec a
hide (Internal.Parsec p) =
Internal.Parsec $ \st good bad ->
let !origConsumed = Internal.consumed st
good' x st' = good x st' { Internal.hints = Internal.hints st } -- TODO: should this change valid offset?
good' x st' = good x st' {
Internal.hints = Internal.hints st,
Internal.hintsValidOffset = Internal.hintsValidOffset st
}
bad' err st'
| Internal.consumed st' /= origConsumed = bad err st'
| otherwise = Internal.useHints bad (Internal.emptyErr st' 0) st'
Expand Down
6 changes: 6 additions & 0 deletions test/Text/Gigaparsec/ErrorsTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,10 @@ regressionTests = testGroup "thou shalt not regress"
testParse (amend greeting <?> ["greeting"]) "hello world." @?=
Failure (TestError (1, 1) (VanillaError (Just (Raw "h")) [Named "greeting"] [] 1))
]
, testGroup "hide should"
[ testCase "not revive dead hints" do
let p = optional digit <* char ']' <* hide (optional letter) <* eof
testParse p "]1" @?=
Failure (TestError (1, 2) (VanillaError (Just (Raw "1")) [EndOfInput] [] 1))
]
]

0 comments on commit 4f00266

Please sign in to comment.