summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-02-07 03:53:53 +1100
committerJed Barber <jjbarber@y7mail.com>2014-02-07 03:53:53 +1100
commitad324af3fa36961bf04361056fee6c2aff81a0a5 (patch)
tree35df013f5812a0e40b96edb64130ee2456bf5666
parent2a281ed2606e18459189a60cab9c18a659ab74e3 (diff)
Completed Thue parser
-rw-r--r--thue.hs49
1 files changed, 31 insertions, 18 deletions
diff --git a/thue.hs b/thue.hs
index 8c56a2e..b76056e 100644
--- a/thue.hs
+++ b/thue.hs
@@ -3,8 +3,8 @@ import Text.Combinators.Parsec
-data ThueProgram = ThueProgram { substitutionRules :: [Rule]
- , initialState :: State }
+data ThueProgram = ThueProgram { thueRules :: [Rule]
+ , thueInitialState :: State }
deriving (Show)
@@ -25,35 +25,48 @@ parseThue = parse thue "error"
thue = do
- rs <- many ruleLine
+ rs <- many rule
separatorLine
- i <- stateLine
+ i <- initialState
+ eof
return (ThueProgram rs i)
-ruleLine = do
- r <- rule
- eol
- return r
-
-
rule = do
- o <- state
+ o <- ruleState
separator
r <- state
+ eol
return (Rule o r)
-separatorLine = separator >> eol
+separatorLine = whiteSpace >> separator >> whiteSpace >> eol
separator = string "::="
-stateLine = do
- s <- state
- eol
- return s
+initialState = do
+ s <- state `sepEndBy` eol
+ return (concat s)
-state =
-
+ruleState = many ruleStateChar
+
+
+ruleStateChar = noneOf "\n\r:"
+ <|> try (do { char ':'; notFollowedBy (string ":="); return ':'})
+
+state = many stateChar
+
+
+stateChar = noneOf "\n\r"
+
+
+whiteSpace = many (oneOf "\t ")
+
+
+eol = try (string "\r\n")
+ <|> try (string "\n\r")
+ <|> try (string "\r")
+ <|> try (string "\n")
+