summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-02-03 19:57:13 +1100
committerJed Barber <jjbarber@y7mail.com>2014-02-03 19:57:13 +1100
commitb9af0635a21b0cdb92be8a92f25c7cf5439774a6 (patch)
tree42bc9264ee575544b77a93027307deb6352d967d
parentea025cffb61b81f42a344818427742934dadd67a (diff)
Started writing Thue parser
-rw-r--r--thue.hs59
1 files changed, 59 insertions, 0 deletions
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 =
+
+