on master help sign in
Strip \r from multiline strings
commit9821e12a4ce96c78a3f94395874cd734b83541d2 authorEvan Czaplicki <info@elm-lang.org> dateWed 7 Aug 2013, 09:12 (13 years ago) parentcc81b1e
1 file changed+17−5
compiler/Parse/Literal.hs+17−5
compiler/Parse/Literal.hs+17−5
@@ -19,13 +19,25 @@ num = fmap toLit (preNum <?> "number")
1919 string "."
2020 ('.':) <$> many1 digit
2121
22+chr :: IParser Literal
23+chr = Chr <$> betwixt '\'' '\'' (backslashed <|> satisfy (/='\''))
24+ <?> "character"
25+
2226str :: IParser Literal
23−str = choice [ let quote = try (string "\"\"\"")
24− in quote >> Str <$> manyTill (backslashed <|> anyChar) quote
27+str = choice [ quote >> str <$> manyTill (backslashed <|> anyChar) quote
2528 , liftM Str . expecting "string" . betwixt '"' '"' . many $
2629 backslashed <|> satisfy (/='"')
2730 ]
31+ where
32+ quote = try (string "\"\"\"")
33+ str = Str . dewindows
2834
29−chr :: IParser Literal
30−chr = Chr <$> betwixt '\'' '\'' (backslashed <|> satisfy (/='\''))
31− <?> "character"
35+ -- Remove \r from strings to fix generated JavaScript
36+ dewindows [] = []
37+ dewindows cs =
38+ let (pre, suf) = break (`elem` ['\r','\n']) cs
39+ in pre ++ case suf of
40+ ('\r':'\n':rest) -> '\n' : dewindows rest
41+ ('\n':rest) -> '\n' : dewindows rest
42+ ('\r':rest) -> '\n' : dewindows rest
43+ _ -> []