[Haskell-cafe] Troubles understanding Parsec Error Handling
Roman Cheplyaka
roma at ro-che.info
Thu May 31 22:00:53 CEST 2012
* Matthias Hörmann <mhoermann at gmail.com> [2012-05-31 10:40:31+0200]
> I noticed there are still some other problems in the code. In particular it
> doesn't work as intended in cases
> like this one:
>
> parseTest (do; r1 <- anyOf ["Hello", "Hallo", "Foo", "HallofFame"]; r2 <-
> string "fbla"; return (r1, r2)) "Hallofbla"
>
> where it should (according to my goal) return no parse error but instead
> accept "Hallo" and allow the string parser
> to consume the rejected suffix but I will try to fix that.
This looks more like a job for regular expressions.
E.g. using the regex-applicative package:
> let anyOf = foldr1 (<|>) . map string
> let re = (,) <$> anyOf ["Hello", "Hallo", "Foo", "HallofFame"] <*> string "fbla"
> "Hallofbla" =~ re
Just ("Hallo","fbla")
Theoretically regular expressions also do the kind of optimization that
you achieve with a trie, but this particular engine doesn't. Nevertheless,
it may be a good base for your own engine.
--
Roman I. Cheplyaka :: http://ro-che.info/
More information about the Haskell-Cafe
mailing list