Permalink
Browse files

bug fixes, code cleanup

  • Loading branch information...
1 parent 572e363 commit 3588650733667ba97b30ba7241522ea10d64fc3e @jamessanders committed Apr 26, 2011
Showing with 13 additions and 11 deletions.
  1. +2 −1 src/Text/Twine/Interpreter.hs
  2. +2 −2 src/Text/Twine/Interpreter/Interface.hs
  3. +9 −8 src/Text/Twine/Interpreter/Types.hs
View
3 src/Text/Twine/Interpreter.hs
@@ -194,7 +194,8 @@ doLookup' st (TwineObjectList (x:xs)) = do
doLookup' st (TwineBool True) = return (Just $ TwineString $ pack "True")
doLookup' st (TwineBool False) = return Nothing
-doLookup' st (TwineObject m) = doLookup' st (TwineObjectList [m])
+doLookup' st (TwineObject m) = (getContext m) st >>= return . Just
+
doLookup' st x = error $ "Context not searchable when looking up '" ++ unpack st ++ "' in " ++ show x
------------------------------------------------------------------------
View
4 src/Text/Twine/Interpreter/Interface.hs
@@ -30,14 +30,14 @@ class (Monad m) => TemplateInterface m a | a -> m where
makeIterable _ = return []
makeString _ = return ""
-
instance (Monad m, TemplateInterface m a) => Convertible a (TwineElement m) where
safeConvert a = Right $ TwineObject $ Object {
getContext = (flip property a),
getIterable = makeIterable a,
getString = makeString a
}
+
------------------------------------------------------------------------
bind :: (Monad m, Convertible a (TwineElement m)) => a -> TwineElement m
@@ -72,7 +72,7 @@ instance (Monad m) => TemplateInterface m (TwineElement m) where
instance (Monad m) => TemplateInterface m EmptyContext
-instance (Monad m, Convertible a (TwineElement m), TemplateInterface m a) => Convertible [a] (TwineElement m) where
+instance (Monad m, Convertible a (TwineElement m)) => Convertible [a] (TwineElement m) where
safeConvert = Right . bind . CXListLike . map bind
instance (Monad m) => Convertible Int (TwineElement m) where
View
17 src/Text/Twine/Interpreter/Types.hs
@@ -18,14 +18,15 @@ import Data.Map (Map)
import Data.Convertible.Base
import Data.Monoid
-data TwineElement m = TwineObjectList [Object m]
- | TwineObject (Object m)
- | TwineString ByteString
- | TwineInteger Integer
- | TwineBool Bool
- | TwineNull
- | TwineList [TwineElement m]
- | TwineFunction ([TwineElement m] -> m (TwineElement m))
+data TwineElement m =
+ TwineObjectList [Object m]
+ | TwineObject (Object m)
+ | TwineString ByteString
+ | TwineInteger Integer
+ | TwineBool Bool
+ | TwineNull
+ | TwineList [TwineElement m]
+ | TwineFunction ([TwineElement m] -> m (TwineElement m))
newtype Context m = Context {
unContext :: Map ByteString (TwineElement m)

0 comments on commit 3588650

Please sign in to comment.