Commit 40cb20de authored by CJ East's avatar CJ East

Initial change to permit use of inline template haskell, to address

issue: https://github.com/gibiansky/IHaskell/issues/236

To verify functionality, paste the following into a code block in
IHaskell.

```
:ext TemplateHaskell
import Language.Haskell.TH
import Control.Lens
data Foo a = Foo { _bar :: Int, _baz :: Int, _quux :: a }
makeLenses ''Foo
:ty baz
```
parent de20c696
...@@ -85,6 +85,7 @@ library ...@@ -85,6 +85,7 @@ library
system-argv0 -any, system-argv0 -any,
system-filepath -any, system-filepath -any,
tar -any, tar -any,
template-haskell -any,
text >=0.11, text >=0.11,
transformers -any, transformers -any,
unix >= 2.6, unix >= 2.6,
......
...@@ -20,6 +20,7 @@ import Data.Char as Char ...@@ -20,6 +20,7 @@ import Data.Char as Char
import Data.Dynamic import Data.Dynamic
import Data.Typeable import Data.Typeable
import qualified Data.Serialize as Serialize import qualified Data.Serialize as Serialize
import qualified Language.Haskell.TH as TH
import System.Directory import System.Directory
import Filesystem.Path.CurrentOS (encodeString) import Filesystem.Path.CurrentOS (encodeString)
import System.Posix.IO import System.Posix.IO
...@@ -78,7 +79,7 @@ data ErrorOccurred = Success | Failure deriving (Show, Eq) ...@@ -78,7 +79,7 @@ data ErrorOccurred = Success | Failure deriving (Show, Eq)
-- | Enable debugging output -- | Enable debugging output
debug :: Bool debug :: Bool
debug = False debug = False
-- | Set GHC's verbosity for debugging -- | Set GHC's verbosity for debugging
ghcVerbosity :: Maybe Int ghcVerbosity :: Maybe Int
...@@ -704,8 +705,20 @@ evalCommand output (Expression expr) state = do ...@@ -704,8 +705,20 @@ evalCommand output (Expression expr) state = do
let widgetExpr = printf "(IHaskell.Display.Widget (%s))" expr :: String let widgetExpr = printf "(IHaskell.Display.Widget (%s))" expr :: String
isWidget <- attempt $ exprType widgetExpr isWidget <- attempt $ exprType widgetExpr
-- Check if this is a declaration
-- let declExpr = printf "((id :: Q [Dec] -> Q [Dec]) (%s))" expr::String
let declExpr = printf "((id :: DecsQ -> DecsQ) (%s))" expr::String
isDeclaration <- attempt $ exprType declExpr
write $ "Can Display: " ++ show canRunDisplay write $ "Can Display: " ++ show canRunDisplay
write $ " Is Widget: " ++ show canRunDisplay write $ " Is Widget: " ++ show isWidget
if isDeclaration
then do
write $ " Is Declaration: " ++ show isDeclaration
(GHC.runDecls expr) >> return ()
else
write $ " Is Declaration:" ++ show isDeclaration
if canRunDisplay if canRunDisplay
then do then do
...@@ -716,20 +729,31 @@ evalCommand output (Expression expr) state = do ...@@ -716,20 +729,31 @@ evalCommand output (Expression expr) state = do
if isWidget if isWidget
then registerWidget out then registerWidget out
else return out else return out
else do else do
-- Evaluate this expression as though it's just a statement. if isDeclaration
-- The output is bound to 'it', so we can then use it. -- We do not want to display the DecsQ, we just want the
evalOut <- evalCommand output (Statement expr) state -- declaration made.
then do write $ "Suppressing display for template haskell declaration"
let out = evalResult evalOut return EvalOut {
showErr = isShowError out evalStatus = Success,
evalResult = mempty,
-- If evaluation failed, return the failure. If it was successful, we evalState = state,
-- may be able to use the IHaskellDisplay typeclass. evalPager = "",
return $ if not showErr || useShowErrors state evalComms = []
then evalOut }
else postprocessShowError evalOut else do
-- Evaluate this expression as though it's just a statement.
-- The output is bound to 'it', so we can then use it.
evalOut <- evalCommand output (Statement expr) state
let out = evalResult evalOut
showErr = isShowError out
-- If evaluation failed, return the failure. If it was successful, we
-- may be able to use the IHaskellDisplay typeclass.
return $ if not showErr || useShowErrors state
then evalOut
else postprocessShowError evalOut
where where
-- Try to evaluate an action. Return True if it succeeds and False if -- Try to evaluate an action. Return True if it succeeds and False if
......
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