diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-04-15 15:38:54 +1000 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-04-15 15:38:54 +1000 |
commit | 4a631e9f9d4394ab9edfe2f4976e949470667b79 (patch) | |
tree | 6bf4e2b1c8f142f30e3b400461c8330127f72cd5 /src/Thue | |
parent | 15109461d3fb4734f90c9d2663d1bf6e7dbc7e72 (diff) |
Parser for Thue v2a finished
Diffstat (limited to 'src/Thue')
-rw-r--r-- | src/Thue/Parser.hs | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/Thue/Parser.hs b/src/Thue/Parser.hs index 9d5f30b..288f770 100644 --- a/src/Thue/Parser.hs +++ b/src/Thue/Parser.hs @@ -101,21 +101,50 @@ initialState ver = do return (concat s) -ruleState ver = some (ruleStateChar ver) +ruleState Ver2a = some ruleStatePart >>= return . concat +ruleState Ver1 = some (ruleStateChar Ver1) >>= return . tStr -ruleStateChar ver = - (noneOf "\n\r:" >>= return . TChar) - <|> try (char ':' >> notFollowedBy (string ":=") >> return (TChar ':')) - <?> "state character" +ruleStatePart = + (try (some (ruleStateChar Ver2a) >>= return . tStr)) + <|> quoteString + <?> "thue state" -state ver = many (stateChar ver) +ruleStateChar Ver2a = try escapeChar <|> (noneOf "\\\n\r\":") <|> colon <?> "state character" +ruleStateChar Ver1 = (noneOf "\n\r:") <|> colon <?> "state character" +colon = try (char ':' >> notFollowedBy (string ":=") >> return ':') -stateChar ver = - (noneOf "\n\r" >>= return . TChar) - <?> "state character" +state Ver2a = many statePart >>= return . concat +state Ver1 = many (stateChar Ver1) >>= return . tStr + + +statePart = + (try (some (stateChar Ver2a) >>= return . tStr)) + <|> quoteString + <?> "thue state" + + +stateChar Ver2a = (try escapeChar) <|> (noneOf "\\\n\r\"") <?> "state character" +stateChar Ver1 = (noneOf "\n\r") <?> "state character" + + +escapeChar = char '\\' >> charCode +charCode = + (char 'n' >> return '\n') + <|> (char '"') + <|> (char 'E' >> char 'O' >> char 'T' >> return '\EOT') + <|> (char ':') + <|> (char 'r' >> return '\r') + <|> (char '\\') + + +quoteString = do + char '"' + str <- some (stateChar Ver2a) + char '"' + return (tLitStr str) eol = try (string "\r\n") |