Hi List,
There is my first email on haskell-cafe, I must admit haskell is a amazing language even though I found it hard to program.
I'm trying to use Parsec to parse a text file something like:
format 1)
HEADER
BODY
format 2)
BODY
BODY = many DATA_FIELDS
I must distinguish the format is either 1) or 2), because I need process them differently. So I'm trying to use lookAhead & <|>, something like:
format1Header = do
HEADER_parser1
HEADER_parser2
return ..
format2Header = do
-- whatever
return ..
headerVersion = do
version <- (lookAhead format1Header) <|> (lookAhead format2Header)
return version
Howerver if format1Header parser failed headerVersion just return failure without trying format2Header parser.
Full source code is attached, you can load the source then just run ``main''
Is there anything I'm fundamentally wrong with lookAhead and <|> in Parsec? How can I get headerVersion works as expected?
Thank you
Baojun