summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2019-04-21 16:32:37 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-11 19:26:49 -0400
commit34a13ce4cc287aa60124c05cd9c017e586f9c244 (patch)
tree186d3c64ed5be618ba6b03db6683816d45aff390
parente4a0905679ebb6796e09a7c45cfddb4291781cd9 (diff)
forward port to megaparsec-7
-rw-r--r--lambdacube-compiler.cabal1
-rw-r--r--src/LambdaCube/Compiler/Lexer.hs20
2 files changed, 21 insertions, 0 deletions
diff --git a/lambdacube-compiler.cabal b/lambdacube-compiler.cabal
index 6d47d950..693ed41b 100644
--- a/lambdacube-compiler.cabal
+++ b/lambdacube-compiler.cabal
@@ -119,6 +119,7 @@ library
119 119
120executable lc 120executable lc
121 hs-source-dirs: tool 121 hs-source-dirs: tool
122 other-modules: Paths_lambdacube_compiler
122 main-is: Compiler.hs 123 main-is: Compiler.hs
123 default-language: Haskell2010 124 default-language: Haskell2010
124 125
diff --git a/src/LambdaCube/Compiler/Lexer.hs b/src/LambdaCube/Compiler/Lexer.hs
index 29b88930..3281fdb0 100644
--- a/src/LambdaCube/Compiler/Lexer.hs
+++ b/src/LambdaCube/Compiler/Lexer.hs
@@ -8,6 +8,7 @@
8{-# LANGUAGE NoMonomorphismRestriction #-} 8{-# LANGUAGE NoMonomorphismRestriction #-}
9{-# LANGUAGE TypeFamilies #-} 9{-# LANGUAGE TypeFamilies #-}
10{-# LANGUAGE RankNTypes #-} 10{-# LANGUAGE RankNTypes #-}
11{-# LANGUAGE CPP #-}
11module LambdaCube.Compiler.Lexer 12module LambdaCube.Compiler.Lexer
12 ( module LambdaCube.Compiler.Lexer 13 ( module LambdaCube.Compiler.Lexer
13 , module ParseUtils 14 , module ParseUtils
@@ -43,7 +44,11 @@ toSPos :: SourcePos -> SPos
43toSPos p = SPos (fromIntegral $ unPos $ sourceLine p) (fromIntegral $ unPos $ sourceColumn p) 44toSPos p = SPos (fromIntegral $ unPos $ sourceLine p) (fromIntegral $ unPos $ sourceColumn p)
44 45
45getSPos :: Parse r w SPos 46getSPos :: Parse r w SPos
47#if MIN_VERSION_megaparsec(7,0,0)
48getSPos = toSPos <$> getSourcePos
49#else
46getSPos = toSPos <$> getPosition 50getSPos = toSPos <$> getPosition
51#endif
47 52
48-------------------------------------------------------------------------------- literals 53-------------------------------------------------------------------------------- literals
49 54
@@ -121,10 +126,25 @@ parseState fi di = (ParseEnv fi di ExpNS (SPos 0 0), either (error "impossible")
121--type Parse r w = ReaderT (ParseEnv r) (WriterT [w] (StateT SPos (Parsec String))) 126--type Parse r w = ReaderT (ParseEnv r) (WriterT [w] (StateT SPos (Parsec String)))
122type Parse r w = RWST (ParseEnv r) [w] SPos (Parsec (ErrorFancy Void) String) 127type Parse r w = RWST (ParseEnv r) [w] SPos (Parsec (ErrorFancy Void) String)
123 128
129#if MIN_VERSION_megaparsec(7,0,0)
130newtype ParseError = ParseErr (P.ParseErrorBundle (String) (ErrorFancy Void))
131instance ShowErrorComponent (ErrorFancy Void) where
132 showErrorComponent (ErrorFail s) = s
133 -- fail has been used in parser monad
134 showErrorComponent (ErrorIndentation ordering row col) = "Indentation error " ++ show (ordering,row,col)
135 -- Incorrect indentation error: desired ordering between reference level and actual level, reference indentation level, actual indentation level
136 showErrorComponent _ = "CustomError"
137 -- ErrorCustom e -- Custom error data, can be conveniently disabled by indexing ErrorFancy by Void
138#else
124newtype ParseError = ParseErr (P.ParseError (Token String) (ErrorFancy Void)) 139newtype ParseError = ParseErr (P.ParseError (Token String) (ErrorFancy Void))
140#endif
125 141
126instance Show ParseError where 142instance Show ParseError where
143#if MIN_VERSION_megaparsec(7,0,0)
144 show (ParseErr e) = errorBundlePretty e
145#else
127 show (ParseErr e) = parseErrorPretty e 146 show (ParseErr e) = parseErrorPretty e
147#endif
128 148
129runParse :: Parse r w a -> ParseState r -> Either ParseError (a, [w]) 149runParse :: Parse r w a -> ParseState r -> Either ParseError (a, [w])
130runParse p (env, st) = left ParseErr . snd . flip runParser' st $ evalRWST p env (error "spos") 150runParse p (env, st) = left ParseErr . snd . flip runParser' st $ evalRWST p env (error "spos")