calculator-0.1.5.2: src/Calculator/Parser/Base.hs
module Calculator.Parser.Base where
--------------------------------------------------------------------------------
import Calculator.Prim.Base (Number)
--------------------------------------------------------------------------------
import Control.Monad (liftM2)
import Control.Applicative ((<$>))
import Text.ParserCombinators.Parsec
--------------------------------------------------------------------------------
parseNumber :: Parser Number
parseNumber = read <$> do
dec <- many1 digit
flt <- option "" (liftM2 (:) (char '.') (many1 digit))
return $ if null flt
then dec
else dec ++ flt
--------------------------------------------------------------------------------
parseId :: Parser String
parseId = (liftM2 (:) letter (many (letter <|> digit)))
--------------------------------------------------------------------------------