uebung2017_2/src/AreaCode.hs
Yannick Gottschalk 22717263bb Revert "Added Aufgabe 4"
This reverts commit aab564e716339cd99bd3f660780a6d8b26c728eb.
2017-04-30 23:45:31 +02:00

28 lines
640 B
Haskell

module AreaCode (AreaCode,separateAreaCode) where
import qualified Data.Attoparsec.Text as A
import Data.Attoparsec.Combinator
import qualified Data.Text as T
type Number = String
type Name = String
type AreaCode = String
{-Area Code Parser-}
separateAreaCode :: Number -> (AreaCode,Number)
separateAreaCode nr =
case A.parse parseAreaCode (T.pack nr) of
A.Done s ac -> (ac, T.unpack s)
_ -> ("",nr)
parseAreaCode :: A.Parser String
parseAreaCode = do
many' (A.char ' ')
A.char '('
ac <- many1 $ A.satisfy (A.inClass "0123456789")
A.char ')'
many' (A.char ' ')
return ac