+ lexWord :: String TokenValue -> Parser Char LexItem
+ lexWord s tv = list (fromString s) >>| pure (LexToken (textSize s) tv)
+
+ lexKw :: String TokenValue -> Parser Char LexItem
+ lexKw kw tv = lexWord kw tv <* check (not o isIdentChar)
+
+ lexUntilNL = top until (eof <|> (item '\n' >>| pure Void))
+
+ lexComment :: Parser Char LexItem
+ lexComment = list (fromString "//") >>| lexUntilNL
+ >>= \chars->pure LexNL
+
+ lexBlockComment :: Parser Char LexItem
+ lexBlockComment = list (fromString "/*")
+ >>| (top until (list (fromString "*/")))
+ >>= \chars->pure $ widthHeight chars 0 0
+ where
+ widthHeight :: [Char] Int Int -> LexItem
+ widthHeight [] l c = LexSpace l c
+ widthHeight ['\n':xs] l _ = widthHeight xs (l+1) 0
+ widthHeight [x:xs] l c = widthHeight xs l (c+1)
+
+ lexNumber :: Parser Char LexItem
+ lexNumber = toString <$> some (satisfy isDigit)
+ >>= \si->pure $ LexToken (textSize si) (NumberToken $ toInt si)
+
+ lexIdentifier :: Parser Char LexItem
+ lexIdentifier = toString <$> some (satisfy isIdentChar)
+ >>= \si->pure $ LexToken (textSize si) (IdentToken si)
+