Skip to content

Commit 8d3c4e4

Browse files
sjakobimergify[bot]
authored andcommitted
Allow megaparsec-8 (#1582)
This also officially removes support for megaparsec-6.5 – the build had been broken before though.
1 parent 7d01d46 commit 8d3c4e4

File tree

8 files changed

+17
-41
lines changed

8 files changed

+17
-41
lines changed

cabal.project

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
packages: ./dhall ./dhall-bash ./dhall-json ./dhall-yaml ./dhall-lsp-server ./dhall-nix
22

3-
-- While hnix doesn't allow prettyprinter > 1.3
3+
-- TODO: Remove this once hnix has a compatible release:
44
-- https://github.com/haskell-nix/hnix/issues/524
5-
allow-newer: hnix:prettyprinter
5+
allow-newer: hnix:prettyprinter, hnix:megaparsec

dhall-lsp-server/dhall-lsp-server.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ library
5858
, hslogger >= 1.2.10 && < 1.4
5959
, lens >= 4.16.1 && < 4.19
6060
, lens-family-core >= 1.2.3 && < 2.1
61-
, megaparsec >= 7.0.2 && < 7.1
61+
, megaparsec >= 7.0.2 && < 8.1
6262
, mtl >= 2.2.2 && < 2.3
6363
, network-uri >= 2.6.1.0 && < 2.7
6464
, prettyprinter >= 1.5.1 && < 1.6

dhall-lsp-server/src/Dhall/LSP/Backend/Parsing.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ getImportHash (Src left _ text) =
139139
return (Src begin end tokens)
140140

141141
setSourcePos :: SourcePos -> Parser ()
142-
setSourcePos src = Megaparsec.updateParserState
143-
(\(Megaparsec.State s o (Megaparsec.PosState i o' _ t l)) ->
144-
Megaparsec.State s o (Megaparsec.PosState i o' src t l))
142+
setSourcePos src =
143+
Megaparsec.updateParserState $ \state ->
144+
let posState = (Megaparsec.statePosState state) { Megaparsec.pstateSourcePos = src }
145+
in state { Megaparsec.statePosState = posState }
145146

146147
getImportLink :: Src -> Src
147148
getImportLink src@(Src left _ text) =

dhall/dhall.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ Library
439439
haskeline >= 0.7.2.1 && < 0.8 ,
440440
hashable >= 1.2 && < 1.4 ,
441441
lens-family-core >= 1.0.0 && < 2.1 ,
442-
megaparsec >= 6.5.0 && < 7.1 ,
442+
megaparsec >= 7 && < 8.1 ,
443443
memory >= 0.14 && < 0.16,
444444
mtl >= 2.2.1 && < 2.3 ,
445445
network-uri >= 2.6 && < 2.7 ,

dhall/src/Dhall/Parser.hs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ exprA = completeExpression
5050

5151
-- | A parsing error
5252
data ParseError = ParseError {
53-
#if MIN_VERSION_megaparsec(7, 0, 0)
5453
unwrap :: Text.Megaparsec.ParseErrorBundle Text Void
55-
#else
56-
unwrap :: Text.Megaparsec.ParseError Char Void
57-
#endif
5854
, input :: Text
5955
}
6056

@@ -78,11 +74,7 @@ censor parseError =
7874

7975
instance Show ParseError where
8076
show (ParseError {..}) =
81-
#if MIN_VERSION_megaparsec(7, 0, 0)
8277
"\n\ESC[1;31mError\ESC[0m: Invalid input\n\n" <> Text.Megaparsec.errorBundlePretty unwrap
83-
#else
84-
"\n\ESC[1;31mError\ESC[0m: Invalid input\n\n" <> Text.Megaparsec.parseErrorPretty unwrap
85-
#endif
8678

8779
instance Exception ParseError
8880

dhall/src/Dhall/Parser/Combinators.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import qualified Dhall.Map
2929
import qualified Dhall.Pretty
3030
import qualified Dhall.Set
3131
import qualified Text.Megaparsec
32-
#if !MIN_VERSION_megaparsec(7, 0, 0)
33-
import qualified Text.Megaparsec.Char as Text.Megaparsec (satisfy)
34-
#endif
3532
import qualified Text.Megaparsec.Char
3633
import qualified Text.Parser.Char
3734
import qualified Text.Parser.Combinators
@@ -126,9 +123,13 @@ instance MonadPlus Parser where
126123
-- {-# INLINE mplus #-}
127124

128125
instance Text.Megaparsec.MonadParsec Void Text Parser where
126+
#if MIN_VERSION_megaparsec(8, 0, 0)
127+
parseError e = Parser (Text.Megaparsec.parseError e)
128+
#else
129129
failure u e = Parser (Text.Megaparsec.failure u e)
130130

131131
fancyFailure e = Parser (Text.Megaparsec.fancyFailure e)
132+
#endif
132133

133134
label l (Parser p) = Parser (Text.Megaparsec.label l p)
134135

@@ -196,11 +197,7 @@ instance Text.Parser.Char.CharParsing Parser where
196197

197198
notChar = Text.Megaparsec.Char.char
198199

199-
#if MIN_VERSION_megaparsec(7, 0, 0)
200200
anyChar = Text.Megaparsec.anySingle
201-
#else
202-
anyChar = Text.Megaparsec.Char.anyChar
203-
#endif
204201

205202
string = fmap Data.Text.unpack . Text.Megaparsec.Char.string . fromString
206203

dhall/src/Dhall/Parser/Expression.hs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ import qualified Data.Text
3232
import qualified Data.Text.Encoding
3333
import qualified Dhall.Crypto
3434
import qualified Text.Megaparsec
35-
#if !MIN_VERSION_megaparsec(7, 0, 0)
36-
import qualified Text.Megaparsec.Char as Text.Megaparsec
37-
#endif
3835

3936
import Dhall.Parser.Combinators
4037
import Dhall.Parser.Token
@@ -43,31 +40,19 @@ import Dhall.Parser.Token
4340
getSourcePos :: Text.Megaparsec.MonadParsec e s m =>
4441
m Text.Megaparsec.SourcePos
4542
getSourcePos =
46-
#if MIN_VERSION_megaparsec(7, 0, 0)
4743
Text.Megaparsec.getSourcePos
48-
#else
49-
Text.Megaparsec.getPosition
50-
#endif
5144
{-# INLINE getSourcePos #-}
5245

5346
-- | Get the current source offset (in tokens)
5447
getOffset :: Text.Megaparsec.MonadParsec e s m => m Int
55-
#if MIN_VERSION_megaparsec(7, 0, 0)
5648
getOffset = Text.Megaparsec.stateOffset <$> Text.Megaparsec.getParserState
57-
#else
58-
getOffset = Text.Megaparsec.stateTokensProcessed <$> Text.Megaparsec.getParserState
59-
#endif
6049
{-# INLINE getOffset #-}
6150

6251
-- | Set the current source offset
6352
setOffset :: Text.Megaparsec.MonadParsec e s m => Int -> m ()
64-
#if MIN_VERSION_megaparsec(7, 0, 0)
65-
setOffset o = Text.Megaparsec.updateParserState $ \(Text.Megaparsec.State s _ pst) ->
66-
Text.Megaparsec.State s o pst
67-
#else
68-
setOffset o = Text.Megaparsec.updateParserState $ \(Text.Megaparsec.State s p _ stw) ->
69-
Text.Megaparsec.State s p o stw
70-
#endif
53+
setOffset o = Text.Megaparsec.updateParserState $ \state ->
54+
state
55+
{ Text.Megaparsec.stateOffset = o }
7156
{-# INLINE setOffset #-}
7257

7358
{-| Wrap a `Parser` to still match the same text but return only the `Src`

stack.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ extra-deps:
2525
- aeson-yaml-1.0.5.0@sha256:5786f021c1e088d6a5aa259120ec5b1f22bb1757f4427c1a87e0513d00f17f31,1975
2626
- prettyprinter-1.5.1@sha256:fca87c3e2611d3499a0341a59857e9b424a23f31646e4737d535a18582284f96,5375
2727
- atomic-write-0.2.0.7@sha256:3b626dfbc288cd070f1ac31b1c15ddd49822a923778ffe21f92b2116ffc72dc3,4584
28+
- megaparsec-8.0.0
2829
nix:
2930
packages:
3031
- ncurses
3132
- zlib
3233

33-
# hnix doesn't allow prettyprinter >= 1.3
34+
# hnix-0.6.1 doesn't allow prettyprinter >= 1.3 and megaparsec >= 8
3435
# https://github.com/haskell-nix/hnix/issues/524
3536
allow-newer: true

0 commit comments

Comments
 (0)