on master help sign in
Better error when bad backslashing is used in strings
commit07187bd81136eb121cb53819feda3473cee71e96 authorEvan Czaplicki <info@elm-lang.org> dateMon 11 Nov 2013, 01:20 (13 years ago) parent9b55e95
1 file changed+10−2
compiler/Parse/Helpers.hs+10−2
compiler/Parse/Helpers.hs+10−2
@@ -14,6 +14,7 @@ import SourceSyntax.PrettyPrint
1414import SourceSyntax.Declaration (Assoc)
1515import Text.Parsec hiding (newline,spaces,State)
1616import Text.Parsec.Indent
17+import Text.Read (readMaybe)
1718
1819reserveds = [ "if", "then", "else"
1920 , "case", "of"
@@ -50,8 +51,15 @@ iParseWithTable sourceName table aParser input =
5051 runIndent sourceName $ runParserT aParser table sourceName input
5152
5253backslashed :: IParser Char
53−backslashed = do { char '\\'; c <- anyChar
54− ; return . read $ ['\'','\\',c,'\''] }
54+backslashed = do
55+ char '\\'
56+ c <- anyChar
57+ case readMaybe ['\'','\\',c,'\''] of
58+ Just chr -> return chr
59+ Nothing ->
60+ fail $ "Did not recognize character '\\" ++ [c] ++
61+ "'. If the backslash is meant to be a character of its own, " ++
62+ "it should be escaped like this: \"\\\\" ++ [c] ++ "\""
5563
5664var :: IParser String
5765var = makeVar (letter <|> char '_' <?> "variable")