[Haskell-cafe] A simple attoparsec question
fuzxxl at gmail.com
Tue Mar 1 22:15:38 CET 2011
I'm currently trying to write an assembler for Knuths MMIXAL language.
Currently, I'm writing the parser using attoparsec, and have one
In MMIXAL, a string literal starts with a ", followed by an arbitrary
amount of arbitrary characters excluding the newline character and
finished with another ". For example: "Hello, World!" is a string, "ſ"
is a string too, but "\n" (\n is a newline) isn't. Here's the parser,
which parses a s tring and other kinds of constants:
parseConstant = Reference <$> try parseLocLabel
<|> PlainNum <$> decimal
<|> char '#' *> fmap PlainNum hexadecimal
<|> char '\'' *> (CharLit <$> notChar '\n') <* char '\''
<|> try $ (char '"' *> (StringLit . B.pack <$>
manyTill (notChar '\n') (char '"')))
The problem is, that attoparsec just silently fails on this kind of
strings and tries other parsers afterwards, which leads to strange
results. Is there a way to force the whole parser to fail, even if
there's an alternative parser afterwards?
I hope, you understand my question.
Yours, Robert Clausecker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 490 bytes
Desc: This is a digitally signed message part
More information about the Haskell-Cafe