diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-02-03 19:57:13 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-02-03 19:57:13 +1100 |
commit | b9af0635a21b0cdb92be8a92f25c7cf5439774a6 (patch) | |
tree | 42bc9264ee575544b77a93027307deb6352d967d | |
parent | ea025cffb61b81f42a344818427742934dadd67a (diff) |
Started writing Thue parser
-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 = + + |