Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- GameLogic.Language restructurization.

  • Loading branch information...
commit 5b6ae0f70523df76e051f52f2567ff8addac4e26 1 parent 3d56a4b
@graninas authored
View
4 Amoeba/GameLogic/Language/Parsers/Common.hs → Amoeba/GameLogic/Language/Parsing/Common.hs
@@ -1,7 +1,7 @@
-module GameLogic.Language.Parsers.Common where
+module GameLogic.Language.Parsing.Common where
import Middleware.Parsing.Facade as P
-import GameLogic.Language.Parsers.RawToken
+import GameLogic.Language.RawToken
import Control.Monad (liftM)
View
6 Amoeba/GameLogic/Language/Parsers/ItemParser.hs → Amoeba/GameLogic/Language/Parsing/ItemParser.hs
@@ -1,7 +1,7 @@
-module GameLogic.Language.Parsers.ItemParser where
+module GameLogic.Language.Parsing.ItemParser where
-import GameLogic.Language.Parsers.RawToken
-import GameLogic.Language.Parsers.Common
+import GameLogic.Language.Parsing.Common
+import GameLogic.Language.RawToken
import Middleware.Parsing.Facade as P
View
11 Amoeba/GameLogic/Language/Parsers/RawParser.hs → Amoeba/GameLogic/Language/Parsing/RawParser.hs
@@ -1,9 +1,10 @@
-module GameLogic.Language.Parsers.RawParser where
+module GameLogic.Language.Parsing.RawParser where
-import GameLogic.Language.Parsers.RawToken
-import GameLogic.Language.Parsers.WorldParser
-import GameLogic.Language.Parsers.ItemParser
-import GameLogic.Language.Parsers.Common
+import GameLogic.Language.Parsing.WorldParser
+import GameLogic.Language.Parsing.ItemParser
+import GameLogic.Language.Parsing.Common
+
+import GameLogic.Language.RawToken
import Middleware.Parsing.Facade as P
View
6 Amoeba/GameLogic/Language/Parsers/WorldParser.hs → Amoeba/GameLogic/Language/Parsing/WorldParser.hs
@@ -1,7 +1,7 @@
-module GameLogic.Language.Parsers.WorldParser where
+module GameLogic.Language.Parsing.WorldParser where
-import GameLogic.Language.Parsers.RawToken
-import GameLogic.Language.Parsers.Common
+import GameLogic.Language.Parsing.Common
+import GameLogic.Language.RawToken
import Middleware.Parsing.Facade as P
View
2  Amoeba/GameLogic/Language/Parsers/RawToken.hs → Amoeba/GameLogic/Language/RawToken.hs
@@ -1,4 +1,4 @@
-module GameLogic.Language.Parsers.RawToken where
+module GameLogic.Language.RawToken where
type Caption = String
type Name = String
View
21 Amoeba/GameLogic/Language/Translating/Actions.hs
@@ -0,0 +1,21 @@
+module GameLogic.Language.Translating.Actions where
+
+import GameLogic.Language.RawToken
+import GameLogic.Language.Translating.Runtime
+
+import Prelude hiding (log)
+
+
+(/>) trigger act = \token -> if trigger token
+ then act token
+ else return $ "Token not triggered: " ++ show token
+
+
+skip, addItem :: RawToken -> Trans String
+skip t = do
+ log $ "Skip for: " ++ show t
+ return ""
+
+addItem t = do
+ log $ "Adding object template for: " ++ show t
+ return ""
View
25 Amoeba/GameLogic/Language/Translating/Runtime.hs
@@ -0,0 +1,25 @@
+module GameLogic.Language.Translating.Runtime where
+
+import qualified Data.Map as M
+
+import Control.Monad.State
+import Control.Monad.Trans
+import Control.Monad.Trans.Either as E
+
+
+data TransRt = TransRt { trtNextId :: State TransRt Int
+ , trtItemMap :: M.Map String String -- TODO
+ , trtWorldConstructor :: String -- TODO
+ , trtLog :: [String]
+ }
+
+type Trans a = EitherT String (State TransRt) a
+
+
+log s = do
+ ctx <- get
+ let newCtx = ctx { trtLog = (trtLog ctx ++ [s]) }
+ put newCtx
+
+
+initialRt idCounter = TransRt idCounter M.empty "Empty" []
View
11 Amoeba/GameLogic/Language/Translating/Scheme.hs
@@ -0,0 +1,11 @@
+module GameLogic.Language.Translating.Scheme where
+
+import GameLogic.Language.Translating.Triggers
+import GameLogic.Language.Translating.Actions
+
+
+
+scheme = [ onComment /> skip
+ , onEmpty /> skip
+ , onItem /> addItem
+ ]
View
56 Amoeba/GameLogic/Language/Translator.hs → Amoeba/GameLogic/Language/Translating/Translator.hs
@@ -1,11 +1,14 @@
-module GameLogic.Language.Translator where
+module GameLogic.Language.Translating.Translator where
+
+import GameLogic.Language.Parsing.RawParser as RP
+import GameLogic.Language.RawToken as RT
-import GameLogic.Language.Parsers.RawParser as RP
-import GameLogic.Language.Parsers.RawToken as RT
import qualified GameLogic.Runtime.World as W
import qualified GameLogic.Data.Facade as D
-import qualified Data.Map as M
+import GameLogic.Language.Translating.Scheme
+import GameLogic.Language.Translating.Runtime
+
import Prelude hiding (log)
import Control.Monad.State
@@ -46,13 +49,6 @@ World "Pandora"
(15, 15): Object "Karyon" "Player2"
-}
-data TransRt = TransRt { trtNextId :: State TransRt Int
- , trtItemMap :: M.Map String String -- TODO
- , trtWorldConstructor :: String -- TODO
- , trtLog :: [String]
- }
-
-type Trans a = EitherT String (State TransRt) a
nextId :: Int -> State TransRt Int
nextId prevId = do
@@ -61,43 +57,9 @@ nextId prevId = do
put $ ctx { trtNextId = nextId nId }
return nId
+indexingRt = initialRt (nextId 1)
-initialRt = TransRt (nextId 1) M.empty "Empty" []
-
-
-
-(/>) trigger act = \token -> if trigger token
- then act token
- else return $ "Token not triggered: " ++ show token
-
-log s = do
- ctx <- get
- let newCtx = ctx { trtLog = (s : trtLog ctx) }
- put newCtx
-
--- actions:
-skip, addItem :: RawToken -> Trans String
-skip t = do
- log $ "Skip for: " ++ show t
- return ""
-addItem t = do
- log $ "Adding object template for: " ++ show t
- return ""
-
--- triggers:
-onComment (RT.Comment _) = True
-onComment _ = False
-onEmpty RT.EmptyToken = True
-onEmpty _ = False
-onItem (Item n props) = True
-onItem _ = False
-
-scheme = [ onComment /> skip
- , onEmpty /> skip
- , onItem /> addItem
- ]
-
apply sc t = mapM_ ($ t) sc
translate _ [] = return ()
@@ -107,7 +69,7 @@ translate sc (t:ts) = do
translateToWorld [] = Left "There are no tokens."
-translateToWorld tokens = return $ execState (runEitherT (translate scheme tokens)) initialRt
+translateToWorld tokens = return $ execState (runEitherT (translate scheme tokens)) indexingRt
toWorld rawString = do
ts <- RP.parseRawTokens rawString :: Either String [RawToken]
View
11 Amoeba/GameLogic/Language/Translating/Triggers.hs
@@ -0,0 +1,11 @@
+module GameLogic.Language.Translating.Triggers where
+
+import GameLogic.Language.RawToken
+
+
+onComment (Comment _) = True
+onComment _ = False
+onEmpty EmptyToken = True
+onEmpty _ = False
+onItem (Item n props) = True
+onItem _ = False
View
8 Amoeba/Test/ParsingTest.hs
@@ -7,10 +7,10 @@ import Test.QuickCheck.Monadic (assert, monadicIO, run)
import Test.QuickCheck.All
import Control.Monad (liftM)
-import GameLogic.Language.Parsers.RawToken
-import GameLogic.Language.Parsers.ItemParser
-import GameLogic.Language.Parsers.WorldParser
-import GameLogic.Language.Parsers.RawParser
+import GameLogic.Language.Parsing.ItemParser
+import GameLogic.Language.Parsing.WorldParser
+import GameLogic.Language.Parsing.RawParser
+import GameLogic.Language.RawToken
-- 'ARF' stands for 'Amoeba Raw File' or 'Amoeba Raw Format' if you wish.
View
4 Amoeba/Test/TranslatingTest.hs
@@ -1,7 +1,7 @@
module Main where
-import GameLogic.Language.Parsers.RawToken
-import GameLogic.Language.Translator
+import GameLogic.Language.RawToken
+import GameLogic.Language.Translating.Translator
import GameLogic.Runtime.World
import Control.Monad (liftM)
Please sign in to comment.
Something went wrong with that request. Please try again.