mirror of
https://github.com/IHaskell/IHaskell.git
synced 2025-04-18 12:26:08 +00:00
Merge pull request #330 from cje/th
Permit use of inline template haskell
This commit is contained in:
commit
021e3bf013
@ -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,9 +705,28 @@ evalCommand output (Expression expr) state = do
|
||||
let widgetExpr = printf "(IHaskell.Display.Widget (%s))" expr :: String
|
||||
isWidget <- attempt $ exprType widgetExpr
|
||||
|
||||
write $ "Can Display: " ++ show canRunDisplay
|
||||
write $ " Is Widget: " ++ show canRunDisplay
|
||||
-- Check if this is a template haskell declaration
|
||||
let declExpr = printf "((id :: DecsQ -> DecsQ) (%s))" expr::String
|
||||
isTHDeclaration <- attempt $ exprType declExpr
|
||||
|
||||
write $ "Can Display: " ++ show canRunDisplay
|
||||
write $ "Is Widget: " ++ show isWidget
|
||||
write $ "Is Declaration: " ++ show isTHDeclaration
|
||||
|
||||
if isTHDeclaration
|
||||
-- If it typechecks as a DecsQ, we do not want to display the DecsQ,
|
||||
-- we just want the declaration made.
|
||||
then do
|
||||
write $ "Suppressing display for template haskell declaration"
|
||||
GHC.runDecls expr
|
||||
return EvalOut {
|
||||
evalStatus = Success,
|
||||
evalResult = mempty,
|
||||
evalState = state,
|
||||
evalPager = "",
|
||||
evalComms = []
|
||||
}
|
||||
else do
|
||||
if canRunDisplay
|
||||
then do
|
||||
-- Use the display. As a result, `it` is set to the output.
|
||||
@ -716,7 +736,6 @@ evalCommand output (Expression expr) state = do
|
||||
if isWidget
|
||||
then registerWidget out
|
||||
else return out
|
||||
|
||||
else do
|
||||
-- Evaluate this expression as though it's just a statement.
|
||||
-- The output is bound to 'it', so we can then use it.
|
||||
|
Loading…
x
Reference in New Issue
Block a user