From ef30a120eac17e1d85743e16d76a61518cd801fe Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 6 Feb 2018 13:10:07 +0100 Subject: Fix block comments; strip whitespace --- src/SPL/Parse.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/SPL') diff --git a/src/SPL/Parse.hs b/src/SPL/Parse.hs index 2616d8c..e74d9cb 100644 --- a/src/SPL/Parse.hs +++ b/src/SPL/Parse.hs @@ -58,7 +58,8 @@ data Token lex :: (Monad m, Alternative m) => String -> m [Token] lex [] = pure [] -lex s = (item s <|> ident s <|> int s <|> char s <|> bool s <|> comment s) >>= +lex (c:s) | isSpace c = lex s +lex s = (comment s <|> item s <|> ident s <|> int s <|> char s <|> bool s) >>= \(t,s') -> lex s' >>= \ts -> pure (t:ts) where ident :: (Alternative m) => String -> m (Token, String) @@ -88,9 +89,9 @@ lex s = (item s <|> ident s <|> int s <|> char s <|> bool s <|> comment s) >>= (cs, s') = span (/= '\n') s comment ('/':'*':s) = pure (TBlockComment cs, s') where - (cs, s') = spanList (\case - ('*':'/':s) -> True - _ -> False) s + (cs, _:_:s') = spanList (\case + ('*':'/':s) -> False + _ -> True) s comment _ = empty item :: (Alternative m) => String -> m (Token, String) -- cgit v1.2.3