Hi Haskellers!

I'm currently trying to write an assembler for Knuths MMIXAL language.
Currently, I'm writing the parser using attoparsec, and have one
question:

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 '"')))
              <?> "constant"

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

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to