summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-02-08 03:25:14 +1100
committerJed Barber <jjbarber@y7mail.com>2014-02-08 03:25:14 +1100
commita1965bf332d3259fb3e2e9d152a42ab37d61841e (patch)
tree115e775e32d251a52a200cea4e48fd71389c0be5
parent8185bf07227e83d94f534db0d8a6f9e539b6ce34 (diff)
Added I/O to Thue interpreter
-rw-r--r--Thue/Interpreter.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/Thue/Interpreter.hs b/Thue/Interpreter.hs
index 6022038..cbf58a4 100644
--- a/Thue/Interpreter.hs
+++ b/Thue/Interpreter.hs
@@ -11,7 +11,7 @@ import Parser
-thue :: ThueProgram -> ThueState
+thue :: ThueProgram -> IO ThueState
thue program =
let rules = thueRules program
state = thueInitialState program
@@ -21,17 +21,23 @@ thue program =
-interpret :: ThueState -> [ThueRule] -> StdGen -> ThueState
-interpret state rules gen =
+interpret :: ThueState -> [ThueRule] -> StdGen -> IO ThueState
+interpret state rules gen = do
let possibleRules = rules `applicableTo` state
ruleToApply = possibleRules !! num
(num, gen') = nextInRange 0 (length possibleRules - 1) gen
(before, after) = fromJust (extractInfix (original ruleToApply) state)
- state' = before ++ (replacement ruleToApply) ++ after
- in if (possibleRules == []) then state else interpret state' rules gen'
+ state' <- case (replacement ruleToApply) of
+ ":::" -> getLine >>= (\x -> return (before ++ x ++ after))
+
+ '~':xs -> putStrLn xs >> return (before ++ after)
+
+ x -> return (before ++ x ++ after)
+
+ if (possibleRules == []) then return state else interpret state' rules gen'