hint 0.2.4 → 0.2.4.1
raw patch · 4 files changed
+36/−5 lines, 4 files
Files
- Changes +3/−0
- hint.cabal +1/−1
- src/Hint/Eval.hs +20/−3
- unit-tests/run-unit-tests.hs +12/−1
Changes view
@@ -1,3 +1,6 @@+- ver 0.2.4.1+ * BUGFIX: No longer fails on expressions ending in a -- comment+ - ver 0.2.4 * setInstalledModsAreInScopeQualified added * Now depends on ghc-paths (no longer needs a custom cabal script)
hint.cabal view
@@ -1,5 +1,5 @@ name: hint-version: 0.2.4+version: 0.2.4.1 description: This library defines an @Interpreter@ monad. It allows to load Haskell modules, browse them, type-check and evaluate strings with Haskell
src/Hint/Eval.hs view
@@ -8,10 +8,11 @@ import qualified GHC import qualified GHC.Exts ( unsafeCoerce# ) - import Data.Typeable hiding ( typeOf ) import qualified Data.Typeable ( typeOf ) +import Data.Char+ import Hint.Base import Hint.Parsers import Hint.Sandbox@@ -38,7 +39,7 @@ -- kind of errors failOnParseError parseExpr e --- let expr_typesig = concat ["(", e, ") :: ", show $ myTypeOf witness]+ let expr_typesig = concat [parens e," :: ",show $ myTypeOf witness] expr_val <- mayFail $ GHC.compileExpr ghc_session expr_typesig -- return (GHC.Exts.unsafeCoerce# expr_val :: a)@@ -59,4 +60,20 @@ -- instance for t. eval :: String -> Interpreter String eval expr = interpret show_expr (as :: String)- where show_expr = unwords ["Prelude.show", "(", expr, ") "]+ where show_expr = "Prelude.show" ++ (parens expr)+++-- Conceptually, @parens s = "(" ++ s ++ ")"@, where s is some valid haskell+-- expression. In practice, it is harder than this.+-- Observe that if @s@ ends with a trailing comment, then @parens s@ would+-- be a malformed expression. The straightforward solution for this is to+-- put the closing parenthesis in a different line. However, now we are+-- messing with the layout rules and we don't know where @s@ is going to+-- be used!+-- Solution: @parens s = "(let {foo = " ++ s +++-- " ;} in foo)@ where foo does not occur in s+parens :: String -> String+parens s = concat ["(let {", foo, " = ", s, "\n",+ " ;} in ", foo, ")"]+ where foo = "foo_1" ++ filter isDigit s+ -- same trick as in Sandbox.safeBndFor
unit-tests/run-unit-tests.hs view
@@ -86,11 +86,22 @@ where mod_text = unlines ["module T(f) where", "f = g", "g = id"] mod_file = "TEST_PrivateSymbolsInScope.hs" +test_comments_in_expr :: H.InterpreterSession -> HUnit.Test+test_comments_in_expr s = testCase "comments_in_expr" [] $ do+ H.withSession s $ do+ H.reset+ H.setImports ["Prelude"]+ let expr = "length $ concat [[1,2],[3]] -- bla"+ H.typeChecks expr @@? "comment on expression"+ H.eval expr+ H.interpret expr (H.as :: Int)+ return () common_tests :: H.InterpreterSession -> [HUnit.Test] common_tests s = [test_reload_modified s, test_lang_exts s,- test_work_in_main s]+ test_work_in_main s,+ test_comments_in_expr s] non_sb_tests :: H.InterpreterSession -> HUnit.Test