Commit 9a3bff64 authored by Andrew Gibiansky's avatar Andrew Gibiansky

Merge branch 'master' of github.com:gibiansky/IHaskell

parents cc5f8953 df8fd579
...@@ -14,25 +14,14 @@ module IHaskell.Eval.Parser ( ...@@ -14,25 +14,14 @@ module IHaskell.Eval.Parser (
PragmaType(..), PragmaType(..),
) where ) where
-- Hide 'unlines' to use our own 'joinLines' instead. import ClassyPrelude hiding (head, liftIO, maximumBy)
import ClassyPrelude hiding (head, tail, liftIO, unlines, maximumBy)
import Data.List (findIndex, maximumBy, maximum, inits) import Data.List (maximumBy, inits)
import Data.String.Utils (startswith, strip, split) import Data.String.Utils (startswith, strip, split)
import Data.List.Utils (subIndex) import Prelude (head, tail)
import Prelude (init, last, head, tail)
import Control.Monad (msum) import Control.Monad (msum)
import Bag
import ErrUtils hiding (ErrMsg)
import FastString
import GHC hiding (Located) import GHC hiding (Located)
import GhcMonad
import Lexer
import OrdList
import Outputable hiding ((<>))
import SrcLoc hiding (Located)
import StringBuffer
import Language.Haskell.GHC.Parser import Language.Haskell.GHC.Parser
import IHaskell.Eval.Util import IHaskell.Eval.Util
...@@ -93,8 +82,9 @@ parseString codeString = do ...@@ -93,8 +82,9 @@ parseString codeString = do
-- Return to previous flags. When parsing, flags can be set to make -- Return to previous flags. When parsing, flags can be set to make
-- sure parsing works properly. But we don't want those flags to be -- sure parsing works properly. But we don't want those flags to be
-- set during evaluation until the right time. -- set during evaluation until the right time.
setSessionDynFlags flags _ <- setSessionDynFlags flags
return result return result
otherwise -> error "parseString failed, output was neither Parsed nor Failure"
where where
parseChunk :: GhcMonad m => String -> LineNumber -> m (Located CodeBlock) parseChunk :: GhcMonad m => String -> LineNumber -> m (Located CodeBlock)
parseChunk chunk line = Located line <$> handleChunk chunk line parseChunk chunk line = Located line <$> handleChunk chunk line
...@@ -124,10 +114,6 @@ parseString codeString = do ...@@ -124,10 +114,6 @@ parseString codeString = do
isPragma :: String -> Bool isPragma :: String -> Bool
isPragma = startswith "{-#" . strip isPragma = startswith "{-#" . strip
-- Number of lines in this string.
nlines :: String -> Int
nlines = length . lines
activateExtensions :: GhcMonad m => CodeBlock -> m () activateExtensions :: GhcMonad m => CodeBlock -> m ()
activateExtensions (Directive SetExtension ext) = void $ setExtension ext activateExtensions (Directive SetExtension ext) = void $ setExtension ext
activateExtensions (Directive SetDynFlag flags) = activateExtensions (Directive SetDynFlag flags) =
...@@ -193,6 +179,7 @@ parseCodeChunk code startLine = do ...@@ -193,6 +179,7 @@ parseCodeChunk code startLine = do
tryParser string (blockType, parser) = case parser string of tryParser string (blockType, parser) = case parser string of
Parsed res -> Parsed (blockType res) Parsed res -> Parsed (blockType res)
Failure err loc -> Failure err loc Failure err loc -> Failure err loc
otherwise -> error "tryParser failed, output was neither Parsed nor Failure"
parsers :: DynFlags -> [(String -> CodeBlock, String -> ParseOutput String)] parsers :: DynFlags -> [(String -> CodeBlock, String -> ParseOutput String)]
parsers flags = parsers flags =
...@@ -297,7 +284,4 @@ getModuleName moduleSrc = do ...@@ -297,7 +284,4 @@ getModuleName moduleSrc = do
case unLoc <$> hsmodName (unLoc mod) of case unLoc <$> hsmodName (unLoc mod) of
Nothing -> error "Module must have a name." Nothing -> error "Module must have a name."
Just name -> return $ split "." $ moduleNameString name Just name -> return $ split "." $ moduleNameString name
otherwise -> error "getModuleName failed, output was neither Parsed nor Failure"
-- Not the same as 'unlines', due to trailing \n
joinLines :: [String] -> String
joinLines = intercalate "\n"
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