
I am a new Parsec user, and having some trouble with a relatively
simple parser.
The grammar I want to parse contains tags (not html) marked by
angle brackets (e.g., "<some tag>"), with arbitrary text (no angle
brackets allowed) optionally in between tags.
Tags may not nest, but the input must begin and end with a tag.
Whitespace may occur anywhere (beginning/end of input,
inside/between tags, etc.), and is optional.
I think my problem may be a lack of using "try", but I'm not sure
where.
At runtime I get:
Error parsing file: "...\sampleTaggedContent.txt" (line 4, column 1):
unexpected end of input
expecting "<"
The input was:
<tag1>stuff
-- Parsers: taggedContent = do optionalWhiteSpace aTag many tagOrContent aTag eof return "Parse complete."
tagOrContent = aTag <|> someContent > "tagOrContent"
aTag = do tagBegin xs <- many (noneOf [tagEndChar]) tagEnd optionalWhiteSpace return ()
someContent = do manyTill anyChar tagBegin return ()
optionalWhiteSpace = spaces -- i.e., any of " \v\f\t\r\n" tagBegin = char tagBeginChar tagEnd = char tagEndChar
-- Etc: tagBeginChar = '<' tagEndChar = '>'
--------