diff options
Diffstat (limited to 'thue.hs')
-rw-r--r-- | thue.hs | 59 |
1 files changed, 59 insertions, 0 deletions
@@ -0,0 +1,59 @@ + +import Text.Combinators.Parsec + + + +data ThueProgram = ThueProgram { substitutionRules :: [Rule] + , initialState :: State } + deriving (Show) + + +data Rule = Rule { original :: State + , replacement :: State } + deriving (Show) + + +type State = String + + + + +parseThue :: String -> Either ParseError ThueProgram +parseThue = parse thue "error" + + + + +thue = do + rs <- many ruleLine + separatorLine + i <- stateLine + return (ThueProgram rs i) + + +ruleLine = do + r <- rule + eol + return r + + +rule = do + o <- state + separator + r <- state + return (Rule o r) + + +separatorLine = separator >> eol +separator = string "::=" + + +stateLine = do + s <- state + eol + return s + + +state = + + |