packages feed

megaparsec 9.0.1 → 9.1.0

raw patch · 16 files changed

+156/−138 lines, 16 filesdep ~basedep ~scientificPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, scientific

API changes (from Hackage documentation)

+ Text.Megaparsec.Debug: dbg' :: forall e s m a. (VisualStream s, ShowErrorComponent e) => String -> ParsecT e s m a -> ParsecT e s m a
+ Text.Megaparsec.Debug: instance GHC.Show.Show (Text.Megaparsec.Debug.Blind x)

Files

CHANGELOG.md view
@@ -1,3 +1,10 @@+## Megaparsec 9.1.0++* Added `dbg'` in `Text.Megaparsec.Debug` for debugging parsers that have+  unshowable return values.++* Documentation improvements.+ ## Megaparsec 9.0.1  * Added [Safe
README.md view
@@ -88,16 +88,16 @@ ### Error messages  * Megaparsec has typed error messages and the ability to signal custom parse-  errors that better suit user's domain of interest.+  errors that better suit the user's domain of interest. -* Since version 8, location of parse errors can independent of current+* Since version 8, the location of parse errors can independent of current   offset in the input stream. It is useful when you want a parse error to   point to a particular position after performing some checks. -* Instead of single parse error Megaparsec produces so-called+* Instead of a single parse error Megaparsec produces so-called   `ParseErrorBundle` data type that helps to manage multi-error messages and-  pretty-print them easily and efficiently. Since version 8, reporting-  multiple parse errors at once has become much easier.+  pretty-print them. Since version 8, reporting multiple parse errors at+  once has become easier.  ### External lexers @@ -139,8 +139,7 @@  You can find the most complete Megaparsec tutorial [here][the-tutorial]. It should provide sufficient guidance to help you start with your parsing-tasks. The site also has instructions and tips for Parsec users who decide-to migrate to Megaparsec.+tasks.  ## Performance @@ -185,12 +184,12 @@   matters more than quality of error messages.  * *Megaparsec* is good for parsing of source code or other human-readable-  texts. It has better error messages and it's implemented as monad+  texts. It has better error messages and it's implemented as a monad   transformer. -So, if you work with something human-readable where size of input data is-moderate, just go with Megaparsec, otherwise Attoparsec may be a better-choice.+So, if you work with something human-readable where the size of input data+is moderate, it makes sense to go with Megaparsec, otherwise Attoparsec may+be a better choice.  ### Megaparsec vs Parsec @@ -209,18 +208,18 @@ * Better support for Unicode parsing in [`Text.Megaparsec.Char`][tm-char].  * Megaparsec has more powerful combinators and can parse languages where-  indentation matters out-of-the-box.+  indentation matters.  * Better documentation.  * Megaparsec can recover from parse errors “on the fly” and continue   parsing. -* Megaparsec allows us to conditionally process parse errors *inside your-  parser* before parsing is finished. In particular, it's possible to define-  regions in which parse errors, should they happen, will get a “context-  tag”, e.g. we could build a context stack like “in function definition-  foo”, “in expression x”, etc.+* Megaparsec allows us to conditionally process parse errors inside a+  running parser. In particular, it's possible to define regions in which+  parse errors, should they happen, will get a “context tag”, e.g. we could+  build a context stack like “in function definition foo”, “in expression+  x”, etc.  * Megaparsec is faster and supports efficient operations `tokens`,   `takeWhileP`, `takeWhile1P`, `takeP`, like Attoparsec.@@ -236,13 +235,12 @@ use:  * Complicated, doesn't have any tutorials available, and documentation-  doesn't help at all.+  doesn't help much.  * Trifecta can parse `String` and `ByteString` natively, but not `Text`.  * Depends on `lens`, which is a very heavy dependency. If you're not into-  `lens` and would like to keep your code “vanilla”, you may not like the-  API.+  `lens`, you may not like the API.  [Idris][idris] has switched from Trifecta to Megaparsec which allowed it to [have better error messages and fewer dependencies][idris-testimony].
Text/Megaparsec.hs view
@@ -23,7 +23,7 @@ -- at the tutorial <https://markkarpov.com/tutorial/megaparsec.html>. -- -- In addition to the "Text.Megaparsec" module, which exports and re-exports--- most everything that you may need, we advise to import+-- almost everything that you may need, we advise to import -- "Text.Megaparsec.Char" if you plan to work with a stream of 'Char' tokens -- or "Text.Megaparsec.Byte" if you intend to parse binary data. --@@ -191,15 +191,15 @@ -- -- The function is supposed to be useful for lightweight parsing, where -- error messages (and thus file names) are not important and entire input--- should be parsed. For example, it can be used when parsing of a single--- number according to a specification of its format is desired.+-- should be consumed. For example, it can be used for parsing of a single+-- number according to a specification of its format. parseMaybe :: (Ord e, Stream s) => Parsec e s a -> s -> Maybe a parseMaybe p s =   case parse (p <* eof) "" s of     Left _ -> Nothing     Right x -> Just x --- | The expression @'parseTest' p input@ applies the parser @p@ against the+-- | The expression @'parseTest' p input@ applies the parser @p@ on the -- input @input@ and prints the result to stdout. Useful for testing. parseTest ::   ( ShowErrorComponent e,@@ -234,9 +234,9 @@ runParser p name s = snd $ runParser' p (initialState name s)  -- | The function is similar to 'runParser' with the difference that it--- accepts and returns parser state. This allows to specify arbitrary--- textual position at the beginning of parsing, for example. This is the--- most general way to run a parser over the 'Identity' monad.+-- accepts and returns the parser state. This allows us e.g. to specify+-- arbitrary textual position at the beginning of parsing. This is the most+-- general way to run a parser over the 'Identity' monad. -- -- @since 4.2.0 runParser' ::@@ -291,7 +291,8 @@     Error e ->       (s', Left (toBundle (e :| stateParseErrors s'))) --- | Given name of source file and input construct initial state for parser.+-- | Given the name of source file and the input construct the initial state+-- for a parser. initialState :: String -> s -> State s e initialState name s =   State@@ -395,7 +396,7 @@ -- | Register a 'ParseError' for later reporting. This action does not end -- parsing and has no effect except for adding the given 'ParseError' to the -- collection of “delayed” 'ParseError's which will be taken into--- consideration at the end of parsing. Only if this collection is empty+-- consideration at the end of parsing. Only if this collection is empty the -- parser will succeed. This is the main way to report several parse errors -- at once. --@@ -460,6 +461,10 @@ -- -- > digitChar = satisfy isDigit <?> "digit" -- > oneOf cs  = satisfy (`elem` cs)+--+-- __Performance note__: when you need to parse a single token, it is often+-- a good idea to use 'satisfy' with the right predicate function instead of+-- creating a complex parser using the combinators. -- -- See also: 'anySingle', 'anySingleBut', 'oneOf', 'noneOf'. --
Text/Megaparsec/Byte/Lexer.hs view
@@ -1,5 +1,5 @@+{-# LANGUAGE Safe #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE Trustworthy #-} {-# LANGUAGE TypeFamilies #-}  -- |@@ -52,7 +52,7 @@ ---------------------------------------------------------------------------- -- White space --- | Given comment prefix this function returns a parser that skips line+-- | Given a comment prefix this function returns a parser that skips line -- comments. Note that it stops just before the newline character but -- doesn't consume the newline. Newline is either supposed to be consumed by -- 'space' parser or picked up manually.@@ -101,8 +101,8 @@ ---------------------------------------------------------------------------- -- Numbers --- | Parse an integer in decimal representation according to the format of--- integer literals described in the Haskell report.+-- | Parse an integer in the decimal representation according to the format+-- of integer literals described in the Haskell report. -- -- If you need to parse signed integers, see the 'signed' combinator. decimal ::@@ -123,8 +123,8 @@     step a w = a * 10 + fromIntegral (w - 48) {-# INLINE decimal_ #-} --- | Parse an integer in binary representation. Binary number is expected to--- be a non-empty sequence of zeroes “0” and ones “1”.+-- | Parse an integer in the binary representation. The binary number is+-- expected to be a non-empty sequence of zeroes “0” and ones “1”. -- -- You could of course parse some prefix before the actual number: --@@ -145,7 +145,7 @@     isBinDigit w = w == 48 || w == 49 {-# INLINEABLE binary #-} --- | Parse an integer in octal representation. Representation of octal+-- | Parse an integer in the octal representation. The format of the octal -- number is expected to be according to the Haskell report except for the -- fact that this parser doesn't parse “0o” or “0O” prefix. It is a -- responsibility of the programmer to parse correct prefix before parsing@@ -168,7 +168,7 @@     isOctDigit w = w - 48 < 8 {-# INLINEABLE octal #-} --- | Parse an integer in hexadecimal representation. Representation of+-- | Parse an integer in the hexadecimal representation. The format of the -- hexadecimal number is expected to be according to the Haskell report -- except for the fact that this parser doesn't parse “0x” or “0X” prefix. -- It is a responsibility of the programmer to parse correct prefix before@@ -291,7 +291,7 @@ ---------------------------------------------------------------------------- -- Helpers --- | A fast predicate to check if given 'Word8' is a digit in ASCII.+-- | A fast predicate to check if the given 'Word8' is a digit in ASCII. isDigit :: Word8 -> Bool isDigit w = w - 48 < 10 {-# INLINE isDigit #-}
Text/Megaparsec/Char/Lexer.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiWayIf #-}+{-# LANGUAGE Safe #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE Trustworthy #-} {-# LANGUAGE TypeFamilies #-}  -- |@@ -82,7 +82,7 @@ ---------------------------------------------------------------------------- -- White space --- | Given comment prefix this function returns a parser that skips line+-- | Given a comment prefix this function returns a parser that skips line -- comments. Note that it stops just before the newline character but -- doesn't consume the newline. Newline is either supposed to be consumed by -- 'space' parser or picked up manually.@@ -223,10 +223,10 @@     -- be present     IndentSome (Maybe Pos) ([b] -> m a) (m b) --- | Parse a “reference” token and a number of other tokens that have--- greater (but the same) level of indentation than that of “reference”--- token. Reference token can influence parsing, see 'IndentOpt' for more--- information.+-- | Parse a “reference” token and a number of other tokens that have a+-- greater (but the same for all of them) level of indentation than that of+-- the “reference” token. The reference token can influence parsing, see+-- 'IndentOpt' for more information. -- -- Tokens /must not/ consume newlines after them. On the other hand, the -- first argument of this function /must/ consume newlines among other white@@ -352,8 +352,8 @@ ---------------------------------------------------------------------------- -- Numbers --- | Parse an integer in decimal representation according to the format of--- integer literals described in the Haskell report.+-- | Parse an integer in the decimal representation according to the format+-- of integer literals described in the Haskell report. -- -- If you need to parse signed integers, see the 'signed' combinator. --@@ -374,8 +374,8 @@     step a c = a * 10 + fromIntegral (Char.digitToInt c) {-# INLINE decimal_ #-} --- | Parse an integer in binary representation. Binary number is expected to--- be a non-empty sequence of zeroes “0” and ones “1”.+-- | Parse an integer in binary representation. The binary number is+-- expected to be a non-empty sequence of zeroes “0” and ones “1”. -- -- You could of course parse some prefix before the actual number: --@@ -396,7 +396,7 @@     isBinDigit x = x == '0' || x == '1' {-# INLINEABLE binary #-} --- | Parse an integer in octal representation. Representation of octal+-- | Parse an integer in the octal representation. The format of the octal -- number is expected to be according to the Haskell report except for the -- fact that this parser doesn't parse “0o” or “0O” prefix. It is a -- responsibility of the programmer to parse correct prefix before parsing@@ -421,7 +421,7 @@     step a c = a * 8 + fromIntegral (Char.digitToInt c) {-# INLINEABLE octal #-} --- | Parse an integer in hexadecimal representation. Representation of+-- | Parse an integer in the hexadecimal representation. The format of the -- hexadecimal number is expected to be according to the Haskell report -- except for the fact that this parser doesn't parse “0x” or “0X” prefix. -- It is a responsibility of the programmer to parse correct prefix before@@ -519,10 +519,10 @@   (+ e') <$> signed (return ()) decimal_ {-# INLINE exponent_ #-} --- | @'signed' space p@ parser parses an optional sign character (“+” or--- “-”), then if there is a sign it consumes optional white space (using--- @space@ parser), then it runs parser @p@ which should return a number.--- Sign of the number is changed according to the previously parsed sign+-- | @'signed' space p@ parses an optional sign character (“+” or “-”), then+-- if there is a sign it consumes optional white space (using the @space@+-- parser), then it runs the parser @p@ which should return a number. Sign+-- of the number is changed according to the previously parsed sign -- character. -- -- For example, to parse signed integer you can write:
Text/Megaparsec/Class.hs view
@@ -48,7 +48,7 @@ -- 'takeWhileP', 'takeWhile1P', and 'takeP'. class (Stream s, MonadPlus m) => MonadParsec e s m | m -> e s where   -- | Stop parsing and report the 'ParseError'. This is the only way to-  -- control position of the error without manipulating parser state+  -- control position of the error without manipulating the parser state   -- manually.   --   -- @since 8.0.0@@ -66,7 +66,7 @@   hidden :: m a -> m a   hidden = label "" -  -- | The parser @'try' p@ behaves like parser @p@, except that it+  -- | The parser @'try' p@ behaves like the parser @p@, except that it   -- backtracks the parser state when @p@ fails (either consuming input or   -- not).   --@@ -118,13 +118,13 @@   -- can be used to implement the “longest match” rule.   notFollowedBy :: m a -> m () -  -- | @'withRecovery' r p@ allows continue parsing even if parser @p@-  -- fails. In this case @r@ is called with the actual 'ParseError' as its-  -- argument. Typical usage is to return a value signifying failure to+  -- | @'withRecovery' r p@ allows us to continue parsing even if the parser+  -- @p@ fails. In this case @r@ is called with the actual 'ParseError' as+  -- its argument. Typical usage is to return a value signifying failure to   -- parse this particular object and to consume some part of the input up   -- to the point where the next object starts.   ---  -- Note that if @r@ fails, original error message is reported as if+  -- Note that if @r@ fails, the original error message is reported as if   -- without 'withRecovery'. In no way recovering parser @r@ can influence   -- error messages.   --@@ -137,12 +137,12 @@     -- | Parser that can recover from failures     m a -  -- | @'observing' p@ allows to “observe” failure of the @p@ parser, should-  -- it happen, without actually ending parsing but instead getting the-  -- 'ParseError' in 'Left'. On success parsed value is returned in 'Right'-  -- as usual. Note that this primitive just allows you to observe parse-  -- errors as they happen, it does not backtrack or change how the @p@-  -- parser works in any way.+  -- | @'observing' p@ allows us to “observe” failure of the @p@ parser,+  -- should it happen, without actually ending parsing but instead getting+  -- the 'ParseError' in 'Left'. On success parsed value is returned in+  -- 'Right' as usual. Note that this primitive just allows you to observe+  -- parse errors as they happen, it does not backtrack or change how the+  -- @p@ parser works in any way.   --   -- @since 5.1.0   observing ::
Text/Megaparsec/Common.hs view
@@ -30,7 +30,7 @@ {-# INLINE string #-}  -- | The same as 'string', but case-insensitive. On success returns string--- cased as actually parsed input.+-- cased as the parsed input. -- -- >>> parseTest (string' "foobar") "foObAr" -- "foObAr"
Text/Megaparsec/Debug.hs view
@@ -16,6 +16,7 @@ -- @since 7.0.0 module Text.Megaparsec.Debug   ( dbg,+    dbg',   ) where @@ -28,8 +29,8 @@ import Text.Megaparsec.Stream  -- | @'dbg' label p@ parser works exactly like @p@, but when it's evaluated--- it also prints information useful for debugging. The @label@ is only used--- to refer to this parser in the debugging output. This combinator uses the+-- it prints information useful for debugging. The @label@ is only used to+-- refer to this parser in the debugging output. This combinator uses the -- 'trace' function from "Debug.Trace" under the hood. -- -- Typical usage is to wrap every sub-parser in misbehaving parser with@@ -87,6 +88,29 @@           l (DbgIn (unfold (stateInput s)))             ++ l (DbgEERR (streamTake (streamDelta s s') (stateInput s)) err)    in unParser p s cok' cerr' eok' eerr'++-- | Just like 'dbg', but doesn't require the return value of the parser to+-- be 'Show'-able.+--+-- @since 9.1.0+dbg' ::+  forall e s m a.+  ( VisualStream s,+    ShowErrorComponent e+  ) =>+  -- | Debugging label+  String ->+  -- | Parser to debug+  ParsecT e s m a ->+  -- | Parser that prints debugging messages+  ParsecT e s m a+dbg' lbl p = unBlind <$> dbg lbl (Blind <$> p)++-- | A wrapper type with a dummy 'Show' instance.+newtype Blind x = Blind {unBlind :: x}++instance Show (Blind x) where+  show _ = "NOT SHOWN"  -- | A single piece of info to be rendered with 'dbgLog'. data DbgItem s e a
Text/Megaparsec/Error.hs view
@@ -20,8 +20,8 @@ -- Stability   :  experimental -- Portability :  portable ----- Parse errors. The current version of Megaparsec supports well-typed--- errors instead of 'String'-based ones. This gives a lot of flexibility in+-- Parse errors. The current version of Megaparsec supports typed errors+-- instead of 'String'-based ones. This gives a lot of flexibility in -- describing what exactly went wrong as well as a way to return arbitrary -- data in case of failure. --@@ -67,8 +67,8 @@ ---------------------------------------------------------------------------- -- Parse error type --- | Data type that is used to represent “unexpected\/expected” items in--- 'ParseError'. The data type is parametrized over the token type @t@.+-- | A data type that is used to represent “unexpected\/expected” items in+-- 'ParseError'. It is parametrized over the token type @t@. -- -- @since 5.0.0 data ErrorItem t@@ -106,15 +106,15 @@ -- | @'ParseError' s e@ represents a parse error parametrized over the -- stream type @s@ and the custom data @e@. ----- 'Semigroup' and 'Monoid' instances of the data type allow to merge parse--- errors from different branches of parsing. When merging two+-- 'Semigroup' and 'Monoid' instances of the data type allow us to merge+-- parse errors from different branches of parsing. When merging two -- 'ParseError's, the longest match is preferred; if positions are the same, -- custom data sets and collections of message items are combined. Note that -- fancy errors take precedence over trivial errors in merging. -- -- @since 7.0.0 data ParseError s e-  = -- | Trivial errors, generated by Megaparsec's machinery. The data+  = -- | Trivial errors, generated by the Megaparsec's machinery. The data     -- constructor includes the offset of error, unexpected token (if any),     -- and expected tokens.     --@@ -187,14 +187,14 @@ mapParseError _ (TrivialError o u p) = TrivialError o u p mapParseError f (FancyError o x) = FancyError o (E.map (fmap f) x) --- | Get offset of 'ParseError'.+-- | Get the offset of a 'ParseError'. -- -- @since 7.0.0 errorOffset :: ParseError s e -> Int errorOffset (TrivialError o _ _) = o errorOffset (FancyError o _) = o --- | Set offset of 'ParseError'.+-- | Set the offset of a 'ParseError'. -- -- @since 8.0.0 setErrorOffset :: Int -> ParseError s e -> ParseError s e@@ -239,13 +239,13 @@ {-# INLINE mergeError #-}  -- | A non-empty collection of 'ParseError's equipped with 'PosState' that--- allows to pretty-print the errors efficiently and correctly.+-- allows us to pretty-print the errors efficiently and correctly. -- -- @since 7.0.0 data ParseErrorBundle s e = ParseErrorBundle   { -- | A collection of 'ParseError's that is sorted by parse error offsets     bundleErrors :: NonEmpty (ParseError s e),-    -- | State that is used for line\/column calculation+    -- | The state that is used for line\/column calculation     bundlePosState :: PosState s   }   deriving (Generic)@@ -302,7 +302,7 @@   displayException = errorBundlePretty  -- | Attach 'SourcePos'es to items in a 'Traversable' container given that--- there is a projection allowing to get an offset per item.+-- there is a projection allowing us to get an offset per item. -- -- Items must be in ascending order with respect to their offsets. --@@ -315,8 +315,7 @@   t a ->   -- | Initial 'PosState'   PosState s ->-  -- | The collection with 'SourcePos'es-  -- added and the final 'PosState'+  -- | The collection with 'SourcePos'es added and the final 'PosState'   (t (a, SourcePos), PosState s) attachSourcePos projectOffset xs = runState (traverse f xs)   where@@ -349,8 +348,8 @@  -- | Pretty-print a 'ParseErrorBundle'. All 'ParseError's in the bundle will -- be pretty-printed in order together with the corresponding offending--- lines by doing a single efficient pass over the input stream. The--- rendered 'String' always ends with a newline.+-- lines by doing a single pass over the input stream. The rendered 'String'+-- always ends with a newline. -- -- @since 7.0.0 errorBundlePretty ::@@ -488,7 +487,7 @@   ErrorCustom a -> errorComponentLen a   _ -> 1 --- | Transforms a list of error messages into their textual representation.+-- | Transform a list of error messages into their textual representation. messageItemsPretty ::   -- | Prefix to prepend   String ->
Text/Megaparsec/Error/Builder.hs view
@@ -96,9 +96,9 @@ ---------------------------------------------------------------------------- -- Top-level helpers --- | Assemble a 'ParseError' from offset and @'ET' t@ value. @'ET' t@ is a--- monoid and can be assembled by combining primitives provided by this--- module, see below.+-- | Assemble a 'ParseError' from the offset and the @'ET' t@ value. @'ET'+-- t@ is a monoid and can be assembled by combining primitives provided by+-- this module, see below. err ::   -- | 'ParseError' offset   Int ->@@ -168,8 +168,8 @@ ---------------------------------------------------------------------------- -- Helpers --- | Construct appropriate 'ErrorItem' representation for given token--- stream. Empty string produces 'EndOfInput'.+-- | Construct the appropriate 'ErrorItem' representation for the given+-- token stream. The empty string produces 'EndOfInput'. canonicalizeTokens ::   Stream s =>   Proxy s ->
Text/Megaparsec/Internal.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE LambdaCase #-}@@ -94,8 +93,8 @@   mempty = Hints mempty  -- | All information available after parsing. This includes consumption of--- input, success (with returned value) or failure (with parse error), and--- parser state at the end of parsing.+-- input, success (with the returned value) or failure (with the parse+-- error), and parser state at the end of parsing. -- -- See also: 'Consumption', 'Result'. data Reply e s a = Reply (State s e) Consumption (Result s e a)@@ -209,10 +208,6 @@   return = pure   (>>=) = pBind -#if !(MIN_VERSION_base(4,13,0))-  fail   = Fail.fail-#endif- pBind ::   Stream s =>   ParsecT e s m a ->@@ -287,7 +282,7 @@ -- | 'mzero' is a parser that __fails__ without consuming input. -- -- __Note__: strictly speaking, this instance is unlawful. The right--- identity law is does not hold, e.g. in general this is not true:+-- identity law does not hold, e.g. in general this is not true: -- -- > v >> mzero = mero --@@ -580,7 +575,7 @@ ---------------------------------------------------------------------------- -- Helper functions --- | Convert 'ParseError' record to 'Hints'.+-- | Convert a 'ParseError' record into 'Hints'. toHints ::   Stream s =>   -- | Current offset in input stream@@ -660,7 +655,7 @@ -- | Transform any custom errors thrown by the parser using the given -- function. Similar in function and purpose to @withExceptT@. ----- __Note__ that the inner parser will start with empty collection of+-- __Note__ that the inner parser will start with an empty collection of -- “delayed” 'ParseError's. Any delayed 'ParseError's produced in the inner -- parser will be lifted by applying the provided function and added to the -- collection of delayed parse errors of the outer parser.@@ -692,5 +687,4 @@         eok' x st hs = eok x (adjustState st) hs         eerr' e st = eerr (mapParseError f e) (adjustState st)      in unParser p s' cok' cerr' eok' eerr'-  where {-# INLINE withParsecT #-}
Text/Megaparsec/Lexer.hs view
@@ -30,18 +30,19 @@ ---------------------------------------------------------------------------- -- White space --- | @'space' sc lineComment blockComment@ produces parser that can parse+-- | @'space' sc lineComment blockComment@ produces a parser that can parse -- white space in general. It's expected that you create such a parser once -- and pass it to other functions in this module as needed (when you see -- @spaceConsumer@ in documentation, usually it means that something like -- 'space' is expected there). ----- @sc@ is used to parse blocks of space characters. You can use 'C.space1'--- from "Text.Megaparsec.Char" for this purpose as well as your own parser--- (if you don't want to automatically consume newlines, for example). Make--- sure the parser does not succeed on empty input though. In earlier--- version 'C.spaceChar' was recommended, but now parsers based on--- 'takeWhile1P' are preferred because of their speed.+-- @sc@ is used to parse blocks of space characters. You can use+-- 'Text.Megaparsec.Char.space1' from "Text.Megaparsec.Char" for this+-- purpose as well as your own parser (if you don't want to automatically+-- consume newlines, for example). Make sure that the parser does not+-- succeed on the empty input though. In an earlier version of the library+-- 'Text.Megaparsec.Char.spaceChar' was recommended, but now parsers based+-- on 'takeWhile1P' are preferred because of their speed. -- -- @lineComment@ is used to parse line comments. You can use -- @skipLineComment@ if you don't need anything special.@@ -57,7 +58,7 @@ space ::   MonadParsec e s m =>   -- | A parser for space characters which does not accept empty-  -- input (e.g. 'C.space1')+  -- input (e.g. 'Text.Megaparsec.Char.space1')   m () ->   -- | A parser for a line comment (e.g. 'skipLineComment')   m () ->@@ -70,7 +71,7 @@       [hidden sp, hidden line, hidden block] {-# INLINEABLE space #-} --- | This is a wrapper for lexemes. Typical usage is to supply the first+-- | This is a wrapper for lexemes. The typical usage is to supply the first -- argument (parser that consumes white space, probably defined via 'space') -- and use the resulting function to wrap parsers for every lexeme. --@@ -110,7 +111,7 @@ symbol spc = lexeme spc . string {-# INLINEABLE symbol #-} --- | Case-insensitive version of 'symbol'. This may be helpful if you're+-- | A case-insensitive version of 'symbol'. This may be helpful if you're -- working with case-insensitive languages. symbol' ::   (MonadParsec e s m, CI.FoldCase (Tokens s)) =>
Text/Megaparsec/State.hs view
@@ -74,8 +74,8 @@  instance (NFData s, NFData (ParseError s e)) => NFData (State s e) --- | Special kind of state that is used to calculate line\/column positions--- on demand.+-- | A special kind of state that is used to calculate line\/column+-- positions on demand. -- -- @since 7.0.0 data PosState s = PosState
bench/memory/Main.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} @@ -17,10 +16,6 @@ import qualified Text.Megaparsec.Char.Lexer as L import Weigh -#if !MIN_VERSION_base(4,13,0)-import Data.Semigroup ((<>))-#endif- -- | The type of parser that consumes 'String's. type Parser = Parsec Void Text @@ -86,7 +81,7 @@       p' (s, n) = parse (p (s, n)) "" s   func (name ++ "-" ++ show i) p' arg --- | Bench the 'errorBundlePretty' function.+-- | Benchmark the 'errorBundlePretty' function. bbundle ::   -- | Name of the benchmark   String ->@@ -121,7 +116,7 @@     errorBundlePretty     bundle --- | Bench the 'reachOffset' function.+-- | Benchmark the 'reachOffset' function. breachOffset ::   -- | Starting offset in 'PosState'   Int ->@@ -147,7 +142,7 @@               pstateLinePrefix = ""             } --- | Bench the 'reachOffsetNoLine' function.+-- | Benchmark the 'reachOffsetNoLine' function. breachOffsetNoLine ::   -- | Starting offset in 'PosState'   Int ->
bench/speed/Main.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} @@ -16,10 +15,6 @@ import Text.Megaparsec.Char import qualified Text.Megaparsec.Char.Lexer as L -#if !MIN_VERSION_base(4,13,0)-import Data.Semigroup ((<>))-#endif- -- | The type of parser that consumes 'String's. type Parser = Parsec Void Text @@ -82,7 +77,7 @@     bs n = env (return (f n, n)) (bench (show n) . nf p')     p' (s, n) = parse (p (s, n)) "" s --- | Bench the 'errorBundlePretty' function.+-- | Benchmark the 'errorBundlePretty' function. bbundle ::   -- | Name of the benchmark   String ->@@ -116,7 +111,7 @@         ("errorBundlePretty-" ++ show totalLines ++ "-" ++ name)         (nf errorBundlePretty bundle) --- | Bench the 'reachOffset' function.+-- | Benchmark the 'reachOffset' function. breachOffset ::   -- | Starting offset in 'PosState'   Int ->@@ -141,7 +136,7 @@               pstateLinePrefix = ""             } --- | Bench the 'reachOffsetNoLine' function.+-- | Benchmark the 'reachOffsetNoLine' function. breachOffsetNoLine ::   -- | Starting offset in 'PosState'   Int ->
megaparsec.cabal view
@@ -1,6 +1,6 @@ cabal-version:   1.18 name:            megaparsec-version:         9.0.1+version:         9.1.0 license:         BSD2 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 ==8.6.5 ghc ==8.8.4 ghc ==8.10.2+tested-with:     ghc ==8.8.4 ghc ==8.10.5 ghc ==9.0.1 homepage:        https://github.com/mrkkrp/megaparsec bug-reports:     https://github.com/mrkkrp/megaparsec/issues synopsis:        Monadic parser combinators@@ -55,8 +55,8 @@      default-language: Haskell2010     build-depends:-        base >=4.12 && <5.0,-        bytestring >=0.2 && <0.11,+        base >=4.13 && <5.0,+        bytestring >=0.2 && <0.12,         case-insensitive >=1.2 && <1.3,         containers >=0.5 && <0.7,         deepseq >=1.3 && <1.5,@@ -83,11 +83,11 @@     hs-source-dirs:   bench/speed     default-language: Haskell2010     build-depends:-        base >=4.12 && <5.0,+        base >=4.13 && <5.0,         containers >=0.5 && <0.7,         criterion >=0.6.2.1 && <1.6,         deepseq >=1.3 && <1.5,-        megaparsec -any,+        megaparsec,         text >=0.2 && <1.3      if flag(dev)@@ -102,10 +102,10 @@     hs-source-dirs:   bench/memory     default-language: Haskell2010     build-depends:-        base >=4.12 && <5.0,+        base >=4.13 && <5.0,         containers >=0.5 && <0.7,         deepseq >=1.3 && <1.5,-        megaparsec -any,+        megaparsec,         text >=0.2 && <1.3,         weigh >=0.0.4