From 110859b9c25b420ff5a6fe9b467a630799d6ce4c Mon Sep 17 00:00:00 2001 From: mrkkrp Date: Thu, 20 Aug 2015 01:08:20 +0600 Subject: [PATCH] =?UTF-8?q?added=20new=20primitive=20combinator=20?= =?UTF-8?q?=E2=80=98hidden=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added new primitive combinator ‘hidden p’ which hides “expected” tokens in error message when parser ‘p’ fails. --- CHANGELOG.md | 3 +++ Text/Megaparsec.hs | 1 + Text/Megaparsec/Prim.hs | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd8882a..22ba692 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,9 @@ * Fixed bug with `notFollowedBy` always succeeded with parsers that don't consume input, see #6. +* Added new primitive combinator `hidden p` which hides “expected” tokens in + error message when parser `p` fails. + * Added comprehensive QuickCheck test suite. * Added benchmarks. diff --git a/Text/Megaparsec.hs b/Text/Megaparsec.hs index a336db6..14f3f50 100644 --- a/Text/Megaparsec.hs +++ b/Text/Megaparsec.hs @@ -65,6 +65,7 @@ module Text.Megaparsec , unexpected , () , label + , hidden , try , lookAhead , notFollowedBy diff --git a/Text/Megaparsec/Prim.hs b/Text/Megaparsec/Prim.hs index 5868579..f9c9404 100644 --- a/Text/Megaparsec/Prim.hs +++ b/Text/Megaparsec/Prim.hs @@ -31,6 +31,7 @@ module Text.Megaparsec.Prim , unexpected , () , label + , hidden , try , lookAhead , notFollowedBy @@ -467,6 +468,12 @@ label p l = ParsecT $ \s cok cerr eok eerr -> eerr' err = eerr $ setErrorMessage (Expected l) err in unParser p s cok' cerr eok' eerr' +-- | @hidden p@ behaves just like parser @p@, but it doesn't show any “expected” +-- tokens in error message when @p@ fails. + +hidden :: ParsecT s u m a -> ParsecT s u m a +hidden p = label p "" + -- | The parser @try p@ behaves like parser @p@, except that it -- pretends that it hasn't consumed any input when an error occurs. --