Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solid-pp: Use errorBundlePrettyForGhcPreProcessors #87

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cabal.project.freeze
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ constraints: any.Cabal ==3.12.1.0,
any.lukko ==0.1.2,
lukko +ofd-locking,
any.markdown-unlit ==0.6.0,
any.megaparsec ==9.6.1,
any.megaparsec ==9.7.0,
megaparsec -dev,
any.memory ==0.18.0,
memory +support_bytestring +support_deepseq,
Expand Down Expand Up @@ -272,7 +272,7 @@ constraints: any.Cabal ==3.12.1.0,
splitmix -optimised-mixer,
any.stack ==3.1.1,
stack -developer-mode -disable-git-info -disable-stack-upload -hide-dependency-versions -integration-tests -static -supported-build,
any.static-bytes ==0.1.0,
any.static-bytes ==0.1.1,
any.stm ==2.5.3.1,
any.stm-chans ==3.0.0.9,
any.streaming-commons ==0.2.2.6,
Expand Down Expand Up @@ -335,4 +335,4 @@ constraints: any.Cabal ==3.12.1.0,
zip-archive -executable,
any.zlib ==0.7.1.0,
zlib -bundled-c-zlib +non-blocking-ffi +pkg-config
index-state: hackage.haskell.org 2024-09-09T02:04:10Z
index-state: hackage.haskell.org 2024-11-24T13:26:28Z
2 changes: 1 addition & 1 deletion solid-pp/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies:
- ghc-boot
- text
- bytestring
- megaparsec
- megaparsec >= 9.7.0
- parser-combinators

build-tools: alex
Expand Down
6 changes: 3 additions & 3 deletions solid-pp/solid-pp.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion solid-pp/src/Solid/PP/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ parse parser language extensions line original current = do
stream :: TokenStream
stream = TokenStream original.contents result.tokens
case P.parse parser original.name stream of
Left err -> Left $ errorBundlePretty err
Left err -> Left $ errorBundlePrettyForGhcPreProcessors err
Right r -> Right r

token :: (Token -> Maybe a) -> Parser a
Expand Down
18 changes: 4 additions & 14 deletions solid-pp/test/Solid/PP/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,7 @@ spec = do
it "reports an error" $ do
parseModule "\"foo " `Hspec.shouldBe` Left "main.hs:1:9: error: [GHC-21231]\n lexical error in string/character literal at end of input"
let Left err = parseModule "\"foo { "
err `Hspec.shouldBe` (unpack . unlines) [
"main.hs:1:7:"
, " |"
, "1 | \"foo { "
, " | ^"
, "unterminated string interpolation"
]
err `Hspec.shouldBe` "main.hs:1:7:unterminated string interpolation"

context "unexpected token" $ do
it "reports an error" $ do
Expand All @@ -361,11 +355,7 @@ spec = do
, "some more tokens"
]

err `Hspec.shouldBe` (unpack . unlines) [
"main.hs:2:5:"
, " |"
, "2 | bar ].foo"
, " | ^"
, "unexpected ]"
, "expecting end of input"
err `Hspec.shouldBe` (unpack . T.intercalate "\n") [
"main.hs:2:5: unexpected ]"
, " expecting end of input"
]
42 changes: 7 additions & 35 deletions solid-pp/test/Solid/PPSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,9 @@ spec = do
, ""
, "foo , bar"
]
run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure (List.unlines [
"src.hs:3:5:"
, " |"
, "3 | foo , bar"
, " | ^"
, "unexpected ,"
, "expecting end of input"
run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure (List.intercalate "\n" [
"src.hs:3:5: unexpected ,"
, " expecting end of input"
])

it "takes LINE pragmas into account" $ do
Expand All @@ -224,13 +220,7 @@ spec = do
, "{-# LINE 3 \"src.hs\" #-}"
, "foo = ("
]
run "src.hs" "cur.hs" "dst.hs" `shouldReturn` Failure (List.unlines [
"src.hs:3:8:"
, " |"
, "3 | foo = ("
, " | ^"
, "unexpected end of input"
])
run "src.hs" "cur.hs" "dst.hs" `shouldReturn` Failure "src.hs:3:8:unexpected end of input"

context "when pre-processing imports" $ do
it "implicitly imports well-know modules" $ do
Expand Down Expand Up @@ -519,41 +509,23 @@ spec = do
".foo :: Int"
, ".foo = undefined"
]
run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure (List.unlines [
"src.hs:2:1:"
, " |"
, "2 | .foo = undefined"
, " | ^"
, "invalid method type (arity must be at least 1)"
])
run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure "src.hs:2:1:invalid method type (arity must be at least 1)"

context "with incorrect indentation" $ do
it "reports an error" $ do
writeFile "src.hs" $ unlines [
".foo :: Int -> Int"
, " .foo = undefined"
]
run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure (List.unlines [
"src.hs:2:2:"
, " |"
, "2 | .foo = undefined"
, " | ^"
, "incorrect indentation (got 2, should be equal to 1)"
])
run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure "src.hs:2:2:incorrect indentation (got 2, should be equal to 1)"

context "when method names do not match" $ do
it "reports an error" $ do
writeFile "src.hs" $ unlines [
".foo :: Int -> Int"
, ".bar = undefined"
]
run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure (List.unlines [
"src.hs:2:2:"
, " |"
, "2 | .bar = undefined"
, " | ^"
, "unexpected method name \"bar\", expecting \"foo\""
])
run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure "src.hs:2:2:unexpected method name \"bar\", expecting \"foo\""

context "when pre-processing identifiers" $ do
it "desugars postfix bangs" $ do
Expand Down
Loading