J'ai un fichier contenant un grand nombre de format de données suivantes:Haskell parsec EOF
Dan Clark’s Profile Photo
Member Name
Dan Clark 2nd degree connection 2nd
Member Occupation
Founder and Headmaster at Some Company, LLC
Nina blalba’s Profile Photo
Member Name
Nina blabla 2nd degree connection 2nd
Member Occupation
Consultant - GAmes executive search
Mon analyseur pour analyser le fichier ci-dessus:
module Main where
import Control.Applicative
import Control.Monad
import Text.ParserCombinators.Parsec hiding (many, (<|>))
data Contact = Contact {
name :: String,
occupation :: String,
company :: String
} deriving Show
matchContact :: Parser Contact
matchContact = do
name <- many anyChar
char '\''
string "s Profile Photo"
char '\n'
string "Member Name"
char '\n'
string name
many anyChar
char '\n'
string "Member Occupation"
char '\n'
job <- many anyChar
try $ string " at "
company <- many anyChar
try (char '\n')
return $ Contact name job company
main = do
c <- parseFromFile (many matchContact <* eof) "contacts.txt"
print c
Il y a beaucoup de questions telles que les données ne sont pas ordinaire. Mais le plus urgent est que je rencontre toujours dans l'erreur à la dernière ligne du fichier d'entrée:
Left "contacts.txt" (line 8670, column 12):
unexpected end of input
expecting "'"
Comment résoudre ce problème?