summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-02-13 02:02:11 +1100
committerJed Barber <jjbarber@y7mail.com>2014-02-13 02:02:11 +1100
commitab757822c75aa71bd725126d9511fcb678f6e5e3 (patch)
tree3e42f31ead0af187cdc88475ad8ead733ddc7671
parent96d6b8ebd32166f5d72420e94060de4792da999b (diff)
Added better error messages in parsers
-rw-r--r--Fractran/Parser.hs6
-rw-r--r--Thue/Parser.hs8
2 files changed, 10 insertions, 4 deletions
diff --git a/Fractran/Parser.hs b/Fractran/Parser.hs
index 6d6cd86..95aa954 100644
--- a/Fractran/Parser.hs
+++ b/Fractran/Parser.hs
@@ -39,7 +39,8 @@ intPair = do
return (numerator,denominator)
-slash = char '/'
+slash = char '/'
+ <?> "slash character"
initVal = do
@@ -59,7 +60,8 @@ positiveNumber = do
return (read (firstDigit:rest))
-nonZeroDigit = oneOf "123456789"
+nonZeroDigit = oneOf "123456789"
+ <?> "non-zero digit"
whiteSpace = many (oneOf "\t\n\r ")
diff --git a/Thue/Parser.hs b/Thue/Parser.hs
index d7b0719..2ee41ae 100644
--- a/Thue/Parser.hs
+++ b/Thue/Parser.hs
@@ -49,7 +49,8 @@ rule = do
separatorLine = whiteSpace >> separator >> whiteSpace >> eol
-separator = string "::="
+separator = string "::="
+ <?> "rule separator"
initialState = do
@@ -62,12 +63,14 @@ ruleState = some ruleStateChar
ruleStateChar = noneOf "\n\r:"
<|> try (char ':' >> notFollowedBy (string ":=") >> return ':')
+ <?> "state character"
state = many stateChar
-stateChar = noneOf "\n\r"
+stateChar = noneOf "\n\r"
+ <?> "state character"
whiteSpace = many (oneOf "\t ")
@@ -77,4 +80,5 @@ eol = try (string "\r\n")
<|> try (string "\n\r")
<|> try (string "\r")
<|> try (string "\n")
+ <?> "end of line"