summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCamil Staps2018-02-06 13:10:07 +0100
committerCamil Staps2018-02-06 13:10:07 +0100
commitef30a120eac17e1d85743e16d76a61518cd801fe (patch)
tree708ac3a8fd4cf88ea89358d190d7e105f4efa28f /src
parentCreate Test File from Assignment 1, read test file in Main.hs (diff)
Fix block comments; strip whitespace
Diffstat (limited to 'src')
-rw-r--r--src/SPL/Parse.hs9
1 files changed, 5 insertions, 4 deletions
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)