on master help sign in
Fix issue #397. Core issue was that scanning for infix declarations was not clever about strings.
commit34913d5340884053bde7b279a5b5bd1d4e1202f3 authorEvan Czaplicki <info@elm-lang.org> dateThu 19 Dec 2013, 10:41 (13 years ago) parentac6c5bc
2 files changed+23−23
compiler/Parse/Helpers.hs+21−2 compiler/Parse/Literal.hs+2−21
compiler/Parse/Helpers.hs+21−2
@@ -274,7 +274,8 @@ ignoreUntil :: IParser a -> IParser (Maybe a)
274274ignoreUntil end = go
275275 where
276276 ignore p = const () <$> p
277− filler = choice [ ignore multiComment
277+ filler = choice [ ignore str
278+ , ignore multiComment
278279 , ignore (markdown (\_ _ -> mzero))
279280 , ignore anyChar
280281 ]
@@ -317,4 +318,22 @@ markdown interpolation = try (string "[markdown|") >> closeMarkdown "" []
317318 , uncurry closeMarkdown =<< interpolation md stuff
318319 , do c <- anyChar
319320 closeMarkdown (md ++ [c]) stuff
320− ]
321+ ]
322+
323+str :: IParser String
324+str = choice [ quote >> dewindows <$> manyTill (backslashed <|> anyChar) quote
325+ , liftM dewindows . expecting "string" . betwixt '"' '"' . many $
326+ backslashed <|> satisfy (/='"')
327+ ]
328+ where
329+ quote = try (string "\"\"\"")
330+
331+ -- Remove \r from strings to fix generated JavaScript
332+ dewindows [] = []
333+ dewindows cs =
334+ let (pre, suf) = break (`elem` ['\r','\n']) cs
335+ in pre ++ case suf of
336+ ('\r':'\n':rest) -> '\n' : dewindows rest
337+ ('\n':rest) -> '\n' : dewindows rest
338+ ('\r':rest) -> '\n' : dewindows rest
339+ _ -> []
compiler/Parse/Literal.hs+2−21
@@ -8,7 +8,7 @@ import Text.Parsec.Indent
88import Parse.Helpers
99import SourceSyntax.Literal
1010
11−literal = num <|> str <|> chr
11+literal = num <|> (Str <$> str) <|> chr
1212
1313num :: IParser Literal
1414num = fmap toLit (preNum <?> "number")
@@ -24,23 +24,4 @@ num = fmap toLit (preNum <?> "number")
2424
2525chr :: IParser Literal
2626chr = Chr <$> betwixt '\'' '\'' (backslashed <|> satisfy (/='\''))
27− <?> "character"
28−
29−str :: IParser Literal
30−str = choice [ quote >> str <$> manyTill (backslashed <|> anyChar) quote
31− , liftM Str . expecting "string" . betwixt '"' '"' . many $
32− backslashed <|> satisfy (/='"')
33− ]
34− where
35− quote = try (string "\"\"\"")
36− str = Str . dewindows
37−
38− -- Remove \r from strings to fix generated JavaScript
39− dewindows [] = []
40− dewindows cs =
41− let (pre, suf) = break (`elem` ['\r','\n']) cs
42− in pre ++ case suf of
43− ('\r':'\n':rest) -> '\n' : dewindows rest
44− ('\n':rest) -> '\n' : dewindows rest
45− ('\r':rest) -> '\n' : dewindows rest
46− _ -> []
27+ <?> "character"