megaparsec 9.3.0 → 9.3.1
raw patch · 17 files changed
+121/−110 lines, 17 files
Files
- CHANGELOG.md +5/−0
- README.md +1/−0
- Text/Megaparsec.hs +28/−24
- Text/Megaparsec/Byte/Binary.hs +1/−1
- Text/Megaparsec/Char/Lexer.hs +1/−1
- Text/Megaparsec/Class.hs +5/−5
- Text/Megaparsec/Common.hs +1/−1
- Text/Megaparsec/Debug.hs +7/−7
- Text/Megaparsec/Error.hs +8/−8
- Text/Megaparsec/Error/Builder.hs +17/−17
- Text/Megaparsec/Internal.hs +25/−25
- Text/Megaparsec/Lexer.hs +3/−3
- Text/Megaparsec/State.hs +1/−1
- Text/Megaparsec/Stream.hs +12/−11
- bench/memory/Main.hs +2/−2
- bench/speed/Main.hs +2/−2
- megaparsec.cabal +2/−2
CHANGELOG.md view
@@ -1,5 +1,10 @@ *Megaparsec follows [SemVer](https://semver.org/).* +## Megaparsec 9.3.1++* Fixed a bug related to processing of tabs when error messages are+ rendered. [Issue 524](https://github.com/mrkkrp/megaparsec/issues/524).+ ## Megaparsec 9.3.0 * Now `label` can override more than one group of hints in the parser it
README.md view
@@ -281,6 +281,7 @@ library for easily using [TagSoup](https://hackage.haskell.org/package/tagsoup) as a token type in Megaparsec.+* [`parser-combinators`](https://hackage.haskell.org/package/parser-combinators)—provides permutation and expression parsers [previously bundled with Megaparsec](https://markkarpov.com/post/megaparsec-7.html#parsercombinators-grows-megaparsec-shrinks). ## Prominent projects that use Megaparsec
Text/Megaparsec.hs view
@@ -174,6 +174,8 @@ -- > Right xs -> print (sum xs) -- > -- > numbers = decimal `sepBy` char ','+--+-- 'parse' is the same as 'runParser'. parse :: -- | Parser to run Parsec e s a ->@@ -223,6 +225,8 @@ -- 'ParseErrorBundle' ('Left') or a value of type @a@ ('Right'). -- -- > parseFromFile p file = runParser p file <$> readFile file+--+-- 'runParser' is the same as 'parse'. runParser :: -- | Parser to run Parsec e s a ->@@ -253,7 +257,7 @@ -- underlying monad @m@ that returns either a 'ParseErrorBundle' ('Left') or -- a value of type @a@ ('Right'). runParserT ::- Monad m =>+ (Monad m) => -- | Parser to run ParsecT e s m a -> -- | Name of source file@@ -269,7 +273,7 @@ -- -- @since 4.2.0 runParserT' ::- Monad m =>+ (Monad m) => -- | Parser to run ParsecT e s m a -> -- | Initial state@@ -323,7 +327,7 @@ -- -- @since 6.0.0 failure ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | Unexpected item (if any) Maybe (ErrorItem (Token s)) -> -- | Expected items@@ -339,7 +343,7 @@ -- -- @since 6.0.0 fancyFailure ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | Fancy error components Set (ErrorFancy e) -> m a@@ -352,7 +356,7 @@ -- about unexpected item @item@ without consuming any input. -- -- > unexpected item = failure (Just item) Set.empty-unexpected :: MonadParsec e s m => ErrorItem (Token s) -> m a+unexpected :: (MonadParsec e s m) => ErrorItem (Token s) -> m a unexpected item = failure (Just item) E.empty {-# INLINE unexpected #-} @@ -362,7 +366,7 @@ -- > customFailure = fancyFailure . Set.singleton . ErrorCustom -- -- @since 6.3.0-customFailure :: MonadParsec e s m => e -> m a+customFailure :: (MonadParsec e s m) => e -> m a customFailure = fancyFailure . E.singleton . ErrorCustom {-# INLINE customFailure #-} @@ -375,7 +379,7 @@ -- -- @since 5.3.0 region ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | How to process 'ParseError's (ParseError s e -> ParseError s e) -> -- | The “region” that the processing applies to@@ -401,7 +405,7 @@ -- at once. -- -- @since 8.0.0-registerParseError :: MonadParsec e s m => ParseError s e -> m ()+registerParseError :: (MonadParsec e s m) => ParseError s e -> m () registerParseError e = updateParserState $ \s -> s {stateParseErrors = e : stateParseErrors s} {-# INLINE registerParseError #-}@@ -410,7 +414,7 @@ -- -- @since 8.0.0 registerFailure ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | Unexpected item (if any) Maybe (ErrorItem (Token s)) -> -- | Expected items@@ -425,7 +429,7 @@ -- -- @since 8.0.0 registerFancyFailure ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | Fancy error components Set (ErrorFancy e) -> m ()@@ -446,7 +450,7 @@ -- -- @since 7.0.0 single ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | Token to match Token s -> m (Token s)@@ -470,7 +474,7 @@ -- -- @since 7.0.0 satisfy ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | Predicate to apply (Token s -> Bool) -> m (Token s)@@ -487,7 +491,7 @@ -- See also: 'satisfy', 'anySingleBut'. -- -- @since 7.0.0-anySingle :: MonadParsec e s m => m (Token s)+anySingle :: (MonadParsec e s m) => m (Token s) anySingle = satisfy (const True) {-# INLINE anySingle #-} @@ -500,7 +504,7 @@ -- -- @since 7.0.0 anySingleBut ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | Token we should not match Token s -> m (Token s)@@ -564,7 +568,7 @@ -- -- @since 7.0.0 chunk ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | Chunk to match Tokens s -> m (Tokens s)@@ -574,7 +578,7 @@ -- | A synonym for 'label' in the form of an operator. infix 0 <?> -(<?>) :: MonadParsec e s m => m a -> String -> m a+(<?>) :: (MonadParsec e s m) => m a -> String -> m a (<?>) = flip label {-# INLINE (<?>) #-} @@ -584,7 +588,7 @@ -- manually in the argument parser, prepare for troubles. -- -- @since 5.3.0-match :: MonadParsec e s m => m a -> m (Tokens s, a)+match :: (MonadParsec e s m) => m a -> m (Tokens s, a) match p = do o <- getOffset s <- getInput@@ -604,7 +608,7 @@ -- > takeRest = takeWhileP Nothing (const True) -- -- @since 6.0.0-takeRest :: MonadParsec e s m => m (Tokens s)+takeRest :: (MonadParsec e s m) => m (Tokens s) takeRest = takeWhileP Nothing (const True) {-# INLINE takeRest #-} @@ -613,7 +617,7 @@ -- > atEnd = option False (True <$ hidden eof) -- -- @since 6.0.0-atEnd :: MonadParsec e s m => m Bool+atEnd :: (MonadParsec e s m) => m Bool atEnd = option False (True <$ hidden eof) {-# INLINE atEnd #-} @@ -621,12 +625,12 @@ -- Parser state combinators -- | Return the current input.-getInput :: MonadParsec e s m => m s+getInput :: (MonadParsec e s m) => m s getInput = stateInput <$> getParserState {-# INLINE getInput #-} -- | @'setInput' input@ continues parsing with @input@.-setInput :: MonadParsec e s m => s -> m ()+setInput :: (MonadParsec e s m) => s -> m () setInput s = updateParserState (\(State _ o pst de) -> State s o pst de) {-# INLINE setInput #-} @@ -652,7 +656,7 @@ -- See also: 'setOffset'. -- -- @since 7.0.0-getOffset :: MonadParsec e s m => m Int+getOffset :: (MonadParsec e s m) => m Int getOffset = stateOffset <$> getParserState {-# INLINE getOffset #-} @@ -661,7 +665,7 @@ -- See also: 'getOffset'. -- -- @since 7.0.0-setOffset :: MonadParsec e s m => Int -> m ()+setOffset :: (MonadParsec e s m) => Int -> m () setOffset o = updateParserState $ \(State s _ pst de) -> State s o pst de {-# INLINE setOffset #-}@@ -669,6 +673,6 @@ -- | @'setParserState' st@ sets the parser state to @st@. -- -- See also: 'getParserState', 'updateParserState'.-setParserState :: MonadParsec e s m => State s e -> m ()+setParserState :: (MonadParsec e s m) => State s e -> m () setParserState st = updateParserState (const st) {-# INLINE setParserState #-}
Text/Megaparsec/Byte/Binary.hs view
@@ -185,7 +185,7 @@ -- -- Performs ceiling division, so byte-unaligned types (bitsize not a -- multiple of 8) should work, but further usage is not tested.-finiteByteSize :: forall a. FiniteBits a => Int+finiteByteSize :: forall a. (FiniteBits a) => Int finiteByteSize = finiteBitSize @a undefined `ceilDiv` 8 where ceilDiv x y = (x + y - 1) `div` y
Text/Megaparsec/Char/Lexer.hs view
@@ -152,7 +152,7 @@ -- -- @since 5.0.0 incorrectIndent ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | Desired ordering between reference level and actual level Ordering -> -- | Reference indentation level
Text/Megaparsec/Class.hs view
@@ -275,7 +275,7 @@ ---------------------------------------------------------------------------- -- Lifting through MTL -instance MonadParsec e s m => MonadParsec e s (L.StateT st m) where+instance (MonadParsec e s m) => MonadParsec e s (L.StateT st m) where parseError e = lift (parseError e) label n (L.StateT m) = L.StateT $ label n . m try (L.StateT m) = L.StateT $ try . m@@ -296,7 +296,7 @@ getParserState = lift getParserState updateParserState f = lift (updateParserState f) -instance MonadParsec e s m => MonadParsec e s (S.StateT st m) where+instance (MonadParsec e s m) => MonadParsec e s (S.StateT st m) where parseError e = lift (parseError e) label n (S.StateT m) = S.StateT $ label n . m try (S.StateT m) = S.StateT $ try . m@@ -317,7 +317,7 @@ getParserState = lift getParserState updateParserState f = lift (updateParserState f) -instance MonadParsec e s m => MonadParsec e s (L.ReaderT r m) where+instance (MonadParsec e s m) => MonadParsec e s (L.ReaderT r m) where parseError e = lift (parseError e) label n (L.ReaderT m) = L.ReaderT $ label n . m try (L.ReaderT m) = L.ReaderT $ try . m@@ -433,7 +433,7 @@ getParserState = lift getParserState updateParserState f = lift (updateParserState f) -instance MonadParsec e s m => MonadParsec e s (IdentityT m) where+instance (MonadParsec e s m) => MonadParsec e s (IdentityT m) where parseError e = lift (parseError e) label n (IdentityT m) = IdentityT $ label n m try = IdentityT . try . runIdentityT@@ -457,7 +457,7 @@ fixs _ (Right (b, s)) = (Right b, s) {-# INLINE fixs #-} -fixs' :: Monoid w => s -> Either a (b, s, w) -> (Either a b, s, w)+fixs' :: (Monoid w) => s -> Either a (b, s, w) -> (Either a b, s, w) fixs' s (Left a) = (Left a, s, mempty) fixs' _ (Right (b, s, w)) = (Right b, s, w) {-# INLINE fixs' #-}
Text/Megaparsec/Common.hs view
@@ -25,7 +25,7 @@ import Text.Megaparsec -- | A synonym for 'chunk'.-string :: MonadParsec e s m => Tokens s -> m (Tokens s)+string :: (MonadParsec e s m) => Tokens s -> m (Tokens s) string = chunk {-# INLINE string #-}
Text/Megaparsec/Debug.hs view
@@ -43,7 +43,7 @@ -- | Type class describing parser monads that can trace during evaluation. -- -- @since 9.3.0-class MonadParsec e s m => MonadParsecDbg e s m where+class (MonadParsec e s m) => MonadParsecDbg e s m where -- | @'dbg' label p@ parser works exactly like @p@, but when it's evaluated -- it prints information useful for debugging. The @label@ is only used to -- refer to this parser in the debugging output. This combinator uses the@@ -70,7 +70,7 @@ -- function that worked only in 'ParsecT'. It was first introduced in the -- version /7.0.0/. dbg ::- Show a =>+ (Show a) => -- | Debugging label String -> -- | Parser to debug@@ -109,7 +109,7 @@ dbgWithComment "STATE" str $ S.runStateT sma s instance- MonadParsecDbg e s m =>+ (MonadParsecDbg e s m) => MonadParsecDbg e s (L.ReaderT r m) where dbg = L.mapReaderT . dbg@@ -182,7 +182,7 @@ ((a, st), w) <- first unComment . unComment <$> dbg str smth pure (a, st, w) -instance MonadParsecDbg e s m => MonadParsecDbg e s (IdentityT m) where+instance (MonadParsecDbg e s m) => MonadParsecDbg e s (IdentityT m) where dbg = mapIdentityT . dbg -- | @'dbgWithComment' label_a label_c m@ traces the first component of the@@ -273,7 +273,7 @@ "MATCH (EERR): " ++ showStream pxy ts ++ "\nERROR:\n" ++ parseErrorPretty e -- | Pretty-print a list of tokens.-showStream :: VisualStream s => Proxy s -> [Token s] -> String+showStream :: (VisualStream s) => Proxy s -> [Token s] -> String showStream pxy ts = case NE.nonEmpty ts of Nothing -> "<EMPTY>"@@ -293,7 +293,7 @@ streamDelta s0 s1 = stateOffset s1 - stateOffset s0 -- | Extract a given number of tokens from the stream.-streamTake :: forall s. Stream s => Int -> s -> [Token s]+streamTake :: forall s. (Stream s) => Int -> s -> [Token s] streamTake n s = case fst <$> takeN_ n s of Nothing -> []@@ -304,7 +304,7 @@ -- -- @since 9.1.0 dbg' ::- MonadParsecDbg e s m =>+ (MonadParsecDbg e s m) => -- | Debugging label String -> -- | Parser to debug
Text/Megaparsec/Error.hs view
@@ -80,7 +80,7 @@ EndOfInput deriving (Show, Read, Eq, Ord, Data, Typeable, Generic, Functor) -instance NFData t => NFData (ErrorItem t)+instance (NFData t) => NFData (ErrorItem t) -- | Additional error data, extendable by user. When no custom data is -- necessary, the type is typically indexed by 'Void' to “cancel” the@@ -98,7 +98,7 @@ ErrorCustom e deriving (Show, Read, Eq, Ord, Data, Typeable, Generic, Functor) -instance NFData a => NFData (ErrorFancy a) where+instance (NFData a) => NFData (ErrorFancy a) where rnf (ErrorFail str) = rnf str rnf (ErrorIndentation ord ref act) = ord `seq` rnf ref `seq` rnf act rnf (ErrorCustom a) = rnf a@@ -180,7 +180,7 @@ -- -- @since 7.0.0 mapParseError ::- Ord e' =>+ (Ord e') => (e -> e') -> ParseError s e -> ParseError s e'@@ -332,7 +332,7 @@ -- | The type class defines how to print a custom component of 'ParseError'. -- -- @since 5.0.0-class Ord a => ShowErrorComponent a where+class (Ord a) => ShowErrorComponent a where -- | Pretty-print a component of 'ParseError'. showErrorComponent :: a -> String @@ -458,20 +458,20 @@ -- Helpers -- | Pretty-print an 'ErrorItem'.-showErrorItem :: VisualStream s => Proxy s -> ErrorItem (Token s) -> String+showErrorItem :: (VisualStream s) => Proxy s -> ErrorItem (Token s) -> String showErrorItem pxy = \case Tokens ts -> showTokens pxy ts Label label -> NE.toList label EndOfInput -> "end of input" -- | Get length of the “pointer” to display under a given 'ErrorItem'.-errorItemLength :: VisualStream s => Proxy s -> ErrorItem (Token s) -> Int+errorItemLength :: (VisualStream s) => Proxy s -> ErrorItem (Token s) -> Int errorItemLength pxy = \case Tokens ts -> tokensLength pxy ts _ -> 1 -- | Pretty-print an 'ErrorFancy'.-showErrorFancy :: ShowErrorComponent e => ErrorFancy e -> String+showErrorFancy :: (ShowErrorComponent e) => ErrorFancy e -> String showErrorFancy = \case ErrorFail msg -> msg ErrorIndentation ord ref actual ->@@ -489,7 +489,7 @@ ErrorCustom a -> showErrorComponent a -- | Get length of the “pointer” to display under a given 'ErrorFancy'.-errorFancyLength :: ShowErrorComponent e => ErrorFancy e -> Int+errorFancyLength :: (ShowErrorComponent e) => ErrorFancy e -> Int errorFancyLength = \case ErrorCustom a -> errorComponentLen a _ -> 1
Text/Megaparsec/Error/Builder.hs view
@@ -59,9 +59,9 @@ data ET s = ET (Maybe (ErrorItem (Token s))) (Set (ErrorItem (Token s))) deriving (Typeable, Generic) -deriving instance Eq (Token s) => Eq (ET s)+deriving instance (Eq (Token s)) => Eq (ET s) -deriving instance Ord (Token s) => Ord (ET s)+deriving instance (Ord (Token s)) => Ord (ET s) deriving instance ( Data s,@@ -70,7 +70,7 @@ ) => Data (ET s) -instance Stream s => Semigroup (ET s) where+instance (Stream s) => Semigroup (ET s) where ET us0 ps0 <> ET us1 ps1 = ET (n us0 us1) (E.union ps0 ps1) where n Nothing Nothing = Nothing@@ -78,7 +78,7 @@ n Nothing (Just y) = Just y n (Just x) (Just y) = Just (max x y) -instance Stream s => Monoid (ET s) where+instance (Stream s) => Monoid (ET s) where mempty = ET Nothing E.empty mappend = (<>) @@ -86,10 +86,10 @@ newtype EF e = EF (Set (ErrorFancy e)) deriving (Eq, Ord, Data, Typeable, Generic) -instance Ord e => Semigroup (EF e) where+instance (Ord e) => Semigroup (EF e) where EF xs0 <> EF xs1 = EF (E.union xs0 xs1) -instance Ord e => Monoid (EF e) where+instance (Ord e) => Monoid (EF e) where mempty = EF E.empty mappend = (<>) @@ -122,43 +122,43 @@ -- Error components -- | Construct an “unexpected token” error component.-utok :: Stream s => Token s -> ET s+utok :: (Stream s) => Token s -> ET s utok = unexp . Tokens . nes -- | Construct an “unexpected tokens” error component. Empty chunk produces -- 'EndOfInput'.-utoks :: forall s. Stream s => Tokens s -> ET s+utoks :: forall s. (Stream s) => Tokens s -> ET s utoks = unexp . canonicalizeTokens (Proxy :: Proxy s) -- | Construct an “unexpected label” error component. Do not use with empty -- strings (for empty strings it's bottom).-ulabel :: Stream s => String -> ET s+ulabel :: (Stream s) => String -> ET s ulabel label | label == "" = error "Text.Megaparsec.Error.Builder.ulabel: empty label" | otherwise = unexp . Label . NE.fromList $ label -- | Construct an “unexpected end of input” error component.-ueof :: Stream s => ET s+ueof :: (Stream s) => ET s ueof = unexp EndOfInput -- | Construct an “expected token” error component.-etok :: Stream s => Token s -> ET s+etok :: (Stream s) => Token s -> ET s etok = expe . Tokens . nes -- | Construct an “expected tokens” error component. Empty chunk produces -- 'EndOfInput'.-etoks :: forall s. Stream s => Tokens s -> ET s+etoks :: forall s. (Stream s) => Tokens s -> ET s etoks = expe . canonicalizeTokens (Proxy :: Proxy s) -- | Construct an “expected label” error component. Do not use with empty -- strings.-elabel :: Stream s => String -> ET s+elabel :: (Stream s) => String -> ET s elabel label | label == "" = error "Text.Megaparsec.Error.Builder.elabel: empty label" | otherwise = expe . Label . NE.fromList $ label -- | Construct an “expected end of input” error component.-eeof :: Stream s => ET s+eeof :: (Stream s) => ET s eeof = expe EndOfInput -- | Construct a custom error component.@@ -171,7 +171,7 @@ -- | Construct the appropriate 'ErrorItem' representation for the given -- token stream. The empty string produces 'EndOfInput'. canonicalizeTokens ::- Stream s =>+ (Stream s) => Proxy s -> Tokens s -> ErrorItem (Token s)@@ -181,11 +181,11 @@ Just xs -> Tokens xs -- | Lift an unexpected item into 'ET'.-unexp :: Stream s => ErrorItem (Token s) -> ET s+unexp :: (Stream s) => ErrorItem (Token s) -> ET s unexp u = ET (pure u) E.empty -- | Lift an expected item into 'ET'.-expe :: Stream s => ErrorItem (Token s) -> ET s+expe :: (Stream s) => ErrorItem (Token s) -> ET s expe p = ET Nothing (E.singleton p) -- | Make a singleton non-empty list from a value.
Text/Megaparsec/Internal.hs view
@@ -87,10 +87,10 @@ -- expecting 'r' or end of input newtype Hints t = Hints (Set (ErrorItem t)) -instance Ord t => Semigroup (Hints t) where+instance (Ord t) => Semigroup (Hints t) where Hints xs <> Hints ys = Hints $ xs <> ys -instance Ord t => Monoid (Hints t) where+instance (Ord t) => Monoid (Hints t) where mempty = Hints mempty -- | All information available after parsing. This includes consumption of@@ -164,18 +164,18 @@ {-# INLINE pMap #-} -- | 'pure' returns a parser that __succeeds__ without consuming input.-instance Stream s => Applicative (ParsecT e s m) where+instance (Stream s) => Applicative (ParsecT e s m) where pure = pPure (<*>) = pAp p1 *> p2 = p1 `pBind` const p2 p1 <* p2 = do x1 <- p1; void p2; return x1 -pPure :: Stream s => a -> ParsecT e s m a+pPure :: (Stream s) => a -> ParsecT e s m a pPure x = ParsecT $ \s _ _ eok _ -> eok x s mempty {-# INLINE pPure #-} pAp ::- Stream s =>+ (Stream s) => ParsecT e s m (a -> b) -> ParsecT e s m a -> ParsecT e s m b@@ -205,12 +205,12 @@ (<|>) = mplus -- | 'return' returns a parser that __succeeds__ without consuming input.-instance Stream s => Monad (ParsecT e s m) where+instance (Stream s) => Monad (ParsecT e s m) where return = pure (>>=) = pBind pBind ::- Stream s =>+ (Stream s) => ParsecT e s m a -> (a -> ParsecT e s m b) -> ParsecT e s m b@@ -234,7 +234,7 @@ in unParser m s mcok cerr meok eerr {-# INLINE pBind #-} -instance Stream s => Fail.MonadFail (ParsecT e s m) where+instance (Stream s) => Fail.MonadFail (ParsecT e s m) where fail = pFail pFail :: String -> ParsecT e s m a@@ -332,7 +332,7 @@ Error _ -> error "mfix ParsecT" runParsecT (f a) s -instance Stream s => MonadTrans (ParsecT e s) where+instance (Stream s) => MonadTrans (ParsecT e s) where lift amb = ParsecT $ \s _ _ eok _ -> amb >>= \a -> eok a s mempty @@ -381,13 +381,13 @@ in unParser p s cok eerr' eok eerr' {-# INLINE pTry #-} -pLookAhead :: Stream s => ParsecT e s m a -> ParsecT e s m a+pLookAhead :: (Stream s) => ParsecT e s m a -> ParsecT e s m a pLookAhead p = ParsecT $ \s _ cerr eok eerr -> let eok' a _ _ = eok a s mempty in unParser p s eok' cerr eok' eerr {-# INLINE pLookAhead #-} -pNotFollowedBy :: Stream s => ParsecT e s m a -> ParsecT e s m ()+pNotFollowedBy :: (Stream s) => ParsecT e s m a -> ParsecT e s m () pNotFollowedBy p = ParsecT $ \s@(State input o _ _) _ _ eok eerr -> let what = maybe EndOfInput (Tokens . nes . fst) (take1_ input) unexpect u = TrivialError o (pure u) E.empty@@ -399,7 +399,7 @@ {-# INLINE pNotFollowedBy #-} pWithRecovery ::- Stream s =>+ (Stream s) => (ParseError s e -> ParsecT e s m a) -> ParsecT e s m a -> ParsecT e s m a@@ -420,7 +420,7 @@ {-# INLINE pWithRecovery #-} pObserving ::- Stream s =>+ (Stream s) => ParsecT e s m a -> ParsecT e s m (Either (ParseError s e) a) pObserving p = ParsecT $ \s cok _ eok _ ->@@ -429,7 +429,7 @@ in unParser p s (cok . Right) cerr' (eok . Right) eerr' {-# INLINE pObserving #-} -pEof :: forall e s m. Stream s => ParsecT e s m ()+pEof :: forall e s m. (Stream s) => ParsecT e s m () pEof = ParsecT $ \s@(State input o pst de) _ _ eok eerr -> case take1_ input of Nothing -> eok () s mempty@@ -443,7 +443,7 @@ pToken :: forall e s m a.- Stream s =>+ (Stream s) => (Token s -> Maybe a) -> Set (ErrorItem (Token s)) -> ParsecT e s m a@@ -465,7 +465,7 @@ pTokens :: forall e s m.- Stream s =>+ (Stream s) => (Tokens s -> Tokens s -> Bool) -> Tokens s -> ParsecT e s m (Tokens s)@@ -493,7 +493,7 @@ pTakeWhileP :: forall e s m.- Stream s =>+ (Stream s) => Maybe String -> (Token s -> Bool) -> ParsecT e s m (Tokens s)@@ -512,7 +512,7 @@ pTakeWhile1P :: forall e s m.- Stream s =>+ (Stream s) => Maybe String -> (Token s -> Bool) -> ParsecT e s m (Tokens s)@@ -540,7 +540,7 @@ pTakeP :: forall e s m.- Stream s =>+ (Stream s) => Maybe String -> Int -> ParsecT e s m (Tokens s)@@ -562,11 +562,11 @@ else cok ts (State input' (o + len) pst de) mempty {-# INLINE pTakeP #-} -pGetParserState :: Stream s => ParsecT e s m (State s e)+pGetParserState :: (Stream s) => ParsecT e s m (State s e) pGetParserState = ParsecT $ \s _ _ eok _ -> eok s s mempty {-# INLINE pGetParserState #-} -pUpdateParserState :: Stream s => (State s e -> State s e) -> ParsecT e s m ()+pUpdateParserState :: (Stream s) => (State s e -> State s e) -> ParsecT e s m () pUpdateParserState f = ParsecT $ \s _ _ eok _ -> eok () (f s) mempty {-# INLINE pUpdateParserState #-} @@ -579,7 +579,7 @@ -- | Convert a 'ParseError' record into 'Hints'. toHints ::- Stream s =>+ (Stream s) => -- | Current offset in input stream Int -> -- | Parse error to convert@@ -602,7 +602,7 @@ -- __Note__ that if resulting continuation gets 'ParseError' that has custom -- data in it, hints are ignored. withHints ::- Stream s =>+ (Stream s) => -- | Hints to use Hints (Token s) -> -- | Continuation to influence@@ -621,7 +621,7 @@ -- | @'accHints' hs c@ results in “OK” continuation that will add given -- hints @hs@ to third argument of original continuation @c@. accHints ::- Stream s =>+ (Stream s) => -- | 'Hints' to add Hints (Token s) -> -- | An “OK” continuation to alter@@ -643,7 +643,7 @@ -- | Low-level unpacking of the 'ParsecT' type. runParsecT ::- Monad m =>+ (Monad m) => -- | Parser to run ParsecT e s m a -> -- | Initial state
Text/Megaparsec/Lexer.hs view
@@ -56,7 +56,7 @@ -- 'space' will just move on or finish depending on whether there is more -- white space for it to consume. space ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | A parser for space characters which does not accept empty -- input (e.g. 'Text.Megaparsec.Char.space1') m () ->@@ -78,7 +78,7 @@ -- > lexeme = L.lexeme spaceConsumer -- > integer = lexeme L.decimal lexeme ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | How to consume white space after lexeme m () -> -- | How to parse actual lexeme@@ -102,7 +102,7 @@ -- > colon = symbol ":" -- > dot = symbol "." symbol ::- MonadParsec e s m =>+ (MonadParsec e s m) => -- | How to consume white space after lexeme m () -> -- | Symbol to parse
Text/Megaparsec/State.hs view
@@ -92,4 +92,4 @@ } deriving (Show, Eq, Data, Typeable, Generic) -instance NFData s => NFData (PosState s)+instance (NFData s) => NFData (PosState s)
Text/Megaparsec/Stream.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE BangPatterns #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE LambdaCase #-}@@ -131,7 +132,7 @@ takeWhile_ :: (Token s -> Bool) -> s -> (Tokens s, s) -- | @since 9.0.0-instance Ord a => Stream [a] where+instance (Ord a) => Stream [a] where type Token [a] = a type Tokens [a] = [a] tokenToChunk Proxy = pure@@ -148,7 +149,7 @@ takeWhile_ = span -- | @since 9.0.0-instance Ord a => Stream (S.Seq a) where+instance (Ord a) => Stream (S.Seq a) where type Token (S.Seq a) = a type Tokens (S.Seq a) = S.Seq a tokenToChunk Proxy = pure@@ -408,7 +409,7 @@ -- | Type class for inputs that can also be used for debugging. -- -- @since 9.0.0-class Stream s => VisualStream s where+class (Stream s) => VisualStream s where -- | Pretty-print non-empty stream of tokens. This function is also used -- to print single tokens (represented as singleton lists). --@@ -441,7 +442,7 @@ -- | Type class for inputs that can also be used for error reporting. -- -- @since 9.0.0-class Stream s => TraversableStream s where+class (Stream s) => TraversableStream s where {-# MINIMAL reachOffset | reachOffsetNoLine #-} -- | Given an offset @o@ and initial 'PosState', adjust the state in such@@ -552,7 +553,7 @@ -- stream types. reachOffset' :: forall s.- Stream s =>+ (Stream s) => -- | How to split input stream at given offset (Int -> s -> (Tokens s, s)) -> -- | How to fold over input stream@@ -630,7 +631,7 @@ -- | Like 'reachOffset'' but for 'reachOffsetNoLine'. reachOffsetNoLine' :: forall s.- Stream s =>+ (Stream s) => -- | How to split input stream at given offset (Int -> s -> (Tokens s, s)) -> -- | How to fold over input stream@@ -745,10 +746,10 @@ Pos -> String -> String-expandTab w' = go 0+expandTab w' = go 0 0 where- go 0 [] = []- go 0 ('\t' : xs) = go w xs- go 0 (x : xs) = x : go 0 xs- go n xs = ' ' : go (n - 1) xs+ go _ 0 [] = []+ go !i 0 ('\t' : xs) = go i (w - (i `rem` w)) xs+ go !i 0 (x : xs) = x : go (i + 1) 0 xs+ go !i n xs = ' ' : go (i + 1) (n - 1) xs w = unPos w'
bench/memory/Main.hs view
@@ -76,7 +76,7 @@ -- | Perform a series of measurements with the same parser. bparser ::- NFData a =>+ (NFData a) => -- | Name of the benchmark group String -> -- | How to construct input@@ -91,7 +91,7 @@ -- | Perform a series of measurements with the same parser. bparserBs ::- NFData a =>+ (NFData a) => -- | Name of the benchmark group String -> -- | How to construct input
bench/speed/Main.hs view
@@ -71,7 +71,7 @@ -- | Perform a series to measurements with the same parser. bparser ::- NFData a =>+ (NFData a) => -- | Name of the benchmark group String -> -- | How to construct input@@ -87,7 +87,7 @@ -- | Perform a series to measurements with the same parser. bparserBs ::- NFData a =>+ (NFData a) => -- | Name of the benchmark group String -> -- | How to construct input
megaparsec.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: megaparsec-version: 9.3.0+version: 9.3.1 license: BSD-2-Clause license-file: LICENSE.md maintainer: Mark Karpov <markkarpov92@gmail.com>@@ -9,7 +9,7 @@ Paolo Martini <paolo@nemail.it>, Daan Leijen <daan@microsoft.com> -tested-with: ghc ==9.0.2 ghc ==9.2.4 ghc ==9.4.1+tested-with: ghc ==9.0.2 ghc ==9.2.5 ghc ==9.4.4 homepage: https://github.com/mrkkrp/megaparsec bug-reports: https://github.com/mrkkrp/megaparsec/issues synopsis: Monadic parser combinators