module ArithLexer where
import Prelude hiding (lex)
import Parser
data Token = Lpar | Rpar
| Plus | Minus
| Star | Slash
| Number Integer
deriving (Show, Eq)
type TokenP = CharP Token
lex :: CharP a -> CharP a
lex p = p `followedBy` spaces
lpar, rpar, plus, minus, star, slash, num :: TokenP
lpar = lex (char '(') >> return Lpar
rpar = lex (char ')') >> return Rpar
plus = lex (char '+') >> return Plus
minus = lex (char '-') >> return Minus
star = lex (char '*') >> return Star
slash = lex (char '/') >> return Slash
num = lex (many1 digit) >>= return . Number . read
tokenize :: CharP [Token]
tokenize = spaces >> many token
where token = lpar <|> rpar <|> plus <|> minus <|> star <|> slash <|> num