fork download
  1. import Data.List
  2. import qualified Text.Parsec.ByteString as PB
  3. import Text.Parsec.Prim
  4. import Text.Parsec.Char
  5. import Text.Parsec.Combinator
  6. import qualified Data.ByteString.Char8 as BS
  7. import Control.Applicative hiding ( ( <|> ) , many )
  8.  
  9. validChars :: PB.Parser Char
  10. validChars = alphaNum <|> oneOf "._"
  11.  
  12. dontCare :: PB.Parser Char
  13. dontCare = oneOf "~!@#$%^&*()<>?,."
  14.  
  15. {--
  16. emailAddress :: PB.Parser String
  17. emailAddress = do
  18.   _ <- many dontCare
  19.   fi <- alphaNum
  20.   se <- validChars
  21.   th <- validChars
  22.   fo <- validChars
  23.   ft <- validChars
  24.   restAddr <- many validChars
  25.   let addr = fi : se : th : fo : ft : restAddr
  26.   char '@'
  27.   dom <- many1 alphaNum
  28.   rest <- try ( string ".com" <|> string ".org"
  29.   <|> string ".edu" ) <|> try ( string ".co.in" )
  30.   _ <- many dontCare
  31.   return $ addr ++ ( '@': dom ++ rest )
  32.  
  33. --}
  34.  
  35. emailAddress :: PB.Parser String
  36. emailAddress = conCatfun <$> ( many dontCare *> alphaNum ) <*> validChars <*>
  37. validChars <*> validChars <*> validChars <*> many alphaNum <*>
  38. ( char '@' *> many1 alphaNum ) <*> ( try ( string ".com" <|>
  39. string ".org" <|> string ".edu" ) <|> try ( string ".co.in" )
  40. <* many dontCare ) where
  41. conCatfun a b c d e f dom rest =
  42. ( a : b : c : d : e : f ) ++ ( '@' : dom ++ rest )
  43.  
  44.  
  45. collectEmail :: BS.ByteString -> String
  46. collectEmail email = case parse emailAddress "" email of
  47. Right addr -> addr
  48. Left err -> ""
  49.  
  50. process :: ( Int , [ String ] ) -> BS.ByteString
  51. process ( k , xs ) = ( BS.pack "Case " ) `BS.append` ( BS.pack . show $ k )
  52. `BS.append` ( BS.pack ": " ) `BS.append` ( BS.pack . show $ k )
  53. `BS.append` ( BS.pack "\n" ) `BS.append` ( BS.pack
  54. ( unlines . filter ( not . null ) $ xs ) )
  55.  
  56. main = BS.interact $ BS.concat . map process . zip [ 1.. ] . map ( map collectEmail .
  57. BS.words ) . tail . BS.lines
  58.  
  59.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.hs:5:8:
    Could not find module `Text.Parsec.Combinator'
    Use -v to see a list of the files searched for.
stdout
Standard output is empty