From b9af0635a21b0cdb92be8a92f25c7cf5439774a6 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Mon, 3 Feb 2014 19:57:13 +1100 Subject: Started writing Thue parser --- thue.hs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 thue.hs diff --git a/thue.hs b/thue.hs new file mode 100644 index 0000000..8c56a2e --- /dev/null +++ b/thue.hs @@ -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 = + + -- cgit