-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't compare source names when deciding "longer match" in mergeError. #175 would be a better fix, but that would require a major bump.
- Loading branch information
Showing
6 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
-- this should run in constant memory | ||
module Main (main) where | ||
|
||
import Text.Parsec | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-- this should be fast | ||
module Main (main) where | ||
|
||
import Control.DeepSeq (NFData (..)) | ||
import System.CPUTime (getCPUTime) | ||
import Text.Printf (printf) | ||
import Test.Tasty (defaultMain) | ||
import Test.Tasty.HUnit (testCaseSteps, assertBool) | ||
|
||
import Text.Parsec | ||
import Text.Parsec.String (Parser) | ||
|
||
main :: IO () | ||
main = defaultMain $ testCaseSteps "issue-171" $ \info -> do | ||
time0 <- getCPUTime | ||
check $ concat $ replicate 100000 "a " | ||
time1 <- getCPUTime | ||
let diff = (time1 - time0) `div` 1000000000 | ||
info $ printf "%d milliseconds\n" diff | ||
assertBool "" (diff < 100) | ||
|
||
parser :: Parser [String] | ||
parser = many (char 'a' <|> char 'b') `sepBy` char ' ' | ||
|
||
check :: String -> IO () | ||
check s = putStrLn $ either onError (const "") $ parse parser {- important: pass input as SourceName -} s s | ||
|
||
onError :: ParseError -> String | ||
onError err = rnf (show err) `seq` "error" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Main (main) where | ||
|
||
import Text.Parsec | ||
import Text.Parsec.Error | ||
import Text.Parsec.String (Parser) | ||
import Text.Parsec.Pos (newPos) | ||
|
||
import Test.Tasty (defaultMain) | ||
import Test.Tasty.HUnit (assertFailure, testCaseSteps, (@?=)) | ||
|
||
main :: IO () | ||
main = defaultMain $ testCaseSteps "issue175" $ \info -> do | ||
case parse p "" "x" of | ||
Right _ -> assertFailure "Unexpected success" | ||
-- with setPosition the "longest match" is arbitrary | ||
-- megaparsec tracks consumed tokens separately, but we don't. | ||
-- so our position is arbitrary. | ||
Left err -> do | ||
info $ show err | ||
errorPos err @?= newPos "aaa" 9 1 -- can be arbitrary | ||
length (errorMessages err) @?= 2 | ||
|
||
p :: Parser Char | ||
p = p1 <|> p2 where | ||
p1 = setPosition (newPos "aaa" 9 1) >> char 'a' | ||
p2 = setPosition (newPos "zzz" 1 1) >> char 'b' |