Commit 717d650a authored by Vaibhav Sagar's avatar Vaibhav Sagar

ghc-parser: update

parent 8669a873
...@@ -30,7 +30,10 @@ import Data.Char (isAlphaNum) ...@@ -30,7 +30,10 @@ import Data.Char (isAlphaNum)
import Bag import Bag
import DynFlags (parseDynamicFilePragma) import DynFlags (parseDynamicFilePragma)
#if MIN_VERSION_ghc(8,10,0)
#else
import ErrUtils hiding (ErrMsg) import ErrUtils hiding (ErrMsg)
#endif
import FastString import FastString
#if MIN_VERSION_ghc(8,4,0) #if MIN_VERSION_ghc(8,4,0)
import GHC hiding (Located, Parsed, parser) import GHC hiding (Located, Parsed, parser)
...@@ -133,23 +136,37 @@ runParser flags (Parser parser) str = ...@@ -133,23 +136,37 @@ runParser flags (Parser parser) str =
toParseOut $ unP parser parseState toParseOut $ unP parser parseState
where where
toParseOut :: ParseResult a -> ParseOutput a toParseOut :: ParseResult a -> ParseOutput a
#if MIN_VERSION_ghc(8,4,0) #if MIN_VERSION_ghc(8,10,0)
toParseOut (PFailed pstate) =
let realSpan = last_loc pstate
errMsg = printErrorBag $ snd $ (messages pstate) flags
ln = srcLocLine $ SrcLoc.realSrcSpanStart realSpan
col = srcLocCol $ SrcLoc.realSrcSpanStart realSpan
in Failure errMsg $ Loc ln col
#elif MIN_VERSION_ghc(8,4,0)
toParseOut (PFailed _ spn@(RealSrcSpan realSpan) err) = toParseOut (PFailed _ spn@(RealSrcSpan realSpan) err) =
let errMsg = printErrorBag $ unitBag $ mkPlainErrMsg flags spn err
ln = srcLocLine $ SrcLoc.realSrcSpanStart realSpan
col = srcLocCol $ SrcLoc.realSrcSpanStart realSpan
in Failure errMsg $ Loc ln col
#else #else
toParseOut (PFailed spn@(RealSrcSpan realSpan) err) = toParseOut (PFailed spn@(RealSrcSpan realSpan) err) =
#endif
let errMsg = printErrorBag $ unitBag $ mkPlainErrMsg flags spn err let errMsg = printErrorBag $ unitBag $ mkPlainErrMsg flags spn err
ln = srcLocLine $ SrcLoc.realSrcSpanStart realSpan ln = srcLocLine $ SrcLoc.realSrcSpanStart realSpan
col = srcLocCol $ SrcLoc.realSrcSpanStart realSpan col = srcLocCol $ SrcLoc.realSrcSpanStart realSpan
in Failure errMsg $ Loc ln col in Failure errMsg $ Loc ln col
#endif
#if MIN_VERSION_ghc(8,4,0) #if MIN_VERSION_ghc(8,10,0)
#elif MIN_VERSION_ghc(8,4,0)
toParseOut (PFailed _ spn err) = toParseOut (PFailed _ spn err) =
let errMsg = printErrorBag $ unitBag $ mkPlainErrMsg flags spn err
in Failure errMsg $ Loc 0 0
#else #else
toParseOut (PFailed spn err) = toParseOut (PFailed spn err) =
#endif
let errMsg = printErrorBag $ unitBag $ mkPlainErrMsg flags spn err let errMsg = printErrorBag $ unitBag $ mkPlainErrMsg flags spn err
in Failure errMsg $ Loc 0 0 in Failure errMsg $ Loc 0 0
#endif
toParseOut (POk _parseState result) = toParseOut (POk _parseState result) =
Parsed result Parsed result
......
...@@ -24,12 +24,15 @@ library ...@@ -24,12 +24,15 @@ library
-- other-modules: -- other-modules:
-- other-extensions: -- other-extensions:
build-depends: base >=4.9 && < 5, build-depends: base >=4.9 && < 5,
ghc >=8.0 && <8.9 ghc >=8.0 && <8.11
if impl(ghc >= 8.0) && impl(ghc < 8.4) if impl(ghc >= 8.0) && impl(ghc < 8.4)
hs-source-dirs: generic-src src-8.0 hs-source-dirs: generic-src src-8.0
else else
hs-source-dirs: generic-src src-8.4 if impl(ghc >= 8.4) && impl(ghc < 8.10)
hs-source-dirs: generic-src src-8.4
else
hs-source-dirs: generic-src src-8.10
default-language: Haskell2010 default-language: Haskell2010
module Language.Haskell.GHC.HappyParser
( fullStatement
, fullImport
, fullDeclaration
, fullExpression
, fullTypeSignature
, fullModule
) where
import Parser
import SrcLoc
-- compiler/hsSyn
import GHC.Hs
-- compiler/utils
import OrdList
-- compiler/parser
import Lexer
import RdrHsSyn (runECP_P)
fullStatement :: P (Maybe (LStmt GhcPs (LHsExpr GhcPs)))
fullStatement = parseStmt
fullImport :: P (LImportDecl GhcPs)
fullImport = parseImport
fullDeclaration :: P (OrdList (LHsDecl GhcPs))
fullDeclaration = fmap unitOL parseDeclaration
fullExpression :: P (LHsExpr GhcPs)
fullExpression = runECP_P =<< parseExpression
fullTypeSignature :: P (Located (OrdList (LHsDecl GhcPs)))
fullTypeSignature = fmap (noLoc . unitOL) parseTypeSignature
fullModule :: P (Located (HsModule GhcPs))
fullModule = parseModule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment