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
system-argv0 -any,
system-filepath -any,
tar -any,
template-haskell -any,
text >=0.11,
transformers -any,
unix >= 2.6,
......
......@@ -20,6 +20,7 @@ import Data.Char as Char
import Data.Dynamic
import Data.Typeable
import qualified Data.Serialize as Serialize
import qualified Language.Haskell.TH as TH
import System.Directory
import Filesystem.Path.CurrentOS (encodeString)
import System.Posix.IO
......@@ -704,8 +705,20 @@ evalCommand output (Expression expr) state = do
let widgetExpr = printf "(IHaskell.Display.Widget (%s))" expr :: String
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 $ " 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
then do
......@@ -716,7 +729,18 @@ evalCommand output (Expression expr) state = do
if isWidget
then registerWidget out
else return out
else do
if isDeclaration
-- We do not want to display the DecsQ, we just want the
-- declaration made.
then do write $ "Suppressing display for template haskell declaration"
return EvalOut {
evalStatus = Success,
evalResult = mempty,
evalState = state,
evalPager = "",
evalComms = []
}
else do
-- Evaluate this expression as though it's just a statement.
-- The output is bound to 'it', so we can then use it.
......
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