From c01b04cbeb3be96fd4e65103526872392d79886f Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 12 Apr 2014 18:21:28 +1000 Subject: Changes to allow for thuestates that aren't mere strings --- src/Thue/Interpreter.hs | 4 ++-- src/Thue/Parser.hs | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Thue/Interpreter.hs b/src/Thue/Interpreter.hs index c53bff9..7c41718 100644 --- a/src/Thue/Interpreter.hs +++ b/src/Thue/Interpreter.hs @@ -34,9 +34,9 @@ interpret state rules gen = do (before, after) = fromJust (extractInfix (original ruleToApply) state) state' <- case (replacement ruleToApply) of - ":::" -> getLine >>= (\x -> return (before ++ x ++ after)) + ":::" -> getLine >>= return . toThueState >>= (\x -> return (before ++ x ++ after)) - '~':xs -> putStr xs >> return (before ++ after) + '~':xs -> return (fromThueState xs) >>= putStr >> return (before ++ after) x -> return (before ++ x ++ after) diff --git a/src/Thue/Parser.hs b/src/Thue/Parser.hs index 2ee41ae..10e9334 100644 --- a/src/Thue/Parser.hs +++ b/src/Thue/Parser.hs @@ -3,7 +3,9 @@ module Thue.Parser ( ThueRule(..), ThueState, - parseThue + parseThue, + toThueState, + fromThueState ) where import Control.Applicative( some ) @@ -31,6 +33,16 @@ parseThue = parse thue "error" +toThueState :: String -> ThueState +toThueState = id + + + +fromThueState :: ThueState -> String +fromThueState = id + + + thue = do rs <- many rule @@ -58,7 +70,7 @@ initialState = do return (concat s) -ruleState = some ruleStateChar +ruleState = some ruleStateChar >>= return . toThueState ruleStateChar = noneOf "\n\r:" @@ -66,7 +78,7 @@ ruleStateChar = noneOf "\n\r:" "state character" -state = many stateChar +state = many stateChar >>= return . toThueState stateChar = noneOf "\n\r" -- cgit