Note that the ParseDot instances for Bool, etc. match those
specified for use with Graphviz (e.g. non-zero integers are
equivalent to True).
You should not be using this module; rather, it is here for
informative/documentative reasons. If you want to parse a
DotRepr, you should use
parseDotGraph rather than its ParseDot
instance.
A variant of <*> with the types of the arguments reversed. It differs from
flip(<*>) in that the effects are resolved in the order the arguments are
presented.
Parse a bracketed item, discarding the brackets.
If everything matches except the closing bracket, the whole
parse fails soft, which can give less-than-satisfying error messages.
If you want better error messages, try calling with e.g.
bracket open (commit close) item
manyFinally e t parses a possibly-empty sequence of e's,
terminated by a t. The final t is discarded. Any parse failures
could be due either to a badly-formed terminator or a badly-formed
element, so it raises both possible errors.
manyFinally' is like manyFinally, except when the terminator
parser overlaps with the element parser. In manyFinally e t,
the parser t is tried only when parser e fails, whereas in
manyFinally' e t, the parser t is always tried first, then
parser e only if the terminator is not found. For instance,
manyFinally (accept "01") (accept "0") on input "0101010" returns
["01","01","01"], whereas manyFinally' with the same arguments
and input returns [].
p onFail q means parse p, unless p fails, in which case
parse q instead.
Can be chained together to give multiple attempts to parse something.
(Note that q could itself be a failing parser, e.g. to change the error
message from that defined in p to something different.)
However, a severe failure in p cannot be ignored.
Push some tokens back onto the front of the input stream and reparse.
This is useful e.g. for recursively expanding macros. When the
user-parser recognises a macro use, it can lookup the macro
expansion from the parse state, lex it, and then stuff the
lexed expansion back down into the parser.
>>> some (putStr "la")lalalalalalalalala... * goes on forever *
Example1 expression
>>> some Nothingnothing
Example1 expression
>>> take 5 <$> some (Just 1)* hangs forever *
Note that this function can be used with Parsers based on
Applicatives. In that case some parser will attempt to
parse parser one or more times until it fails.
>>> many (putStr "la")lalalalalalalalala... * goes on forever *
Example1 expression
>>> many NothingJust []
Example1 expression
>>> take 5 <$> many (Just 1)* hangs forever *
Note that this function can be used with Parsers based on
Applicatives. In that case many parser will attempt to
parse parser zero or more times until it fails.
Instances55Alternative, …
AlternativeGetDefined in binary-0.8.9.3 · Data.Binary.Get.Internal
AlternativeSeqDefined in containers-0.8 · Data.Sequence.Internal
sequence computations and combine their results (<*> and liftA2).
A minimal complete definition must include implementations of pure
and one of either <*> or liftA2. If it defines both, then they must behave
the same as their default definitions:
Some functors support an implementation of liftA2 that is more
efficient than the default one. In particular, if fmap is an
expensive operation, it is likely better to use liftA2 than to
fmap over the structure and then use <*>.
This became a typeclass method in 4.10.0.0. Prior to that, it was
a function defined in terms of <*> and fmap.
Sequence actions, discarding the value of the first argument.
Examples
If used in conjunction with the Applicative instance for Maybe,
you can chain Maybe computations, with a possible "early return"
in case of Nothing.
Example1 expression
>>> Just 2 *> Just 3Just 3
Example1 expression
>>> Nothing *> Just 3Nothing
Of course a more interesting use case would be to have effectful
computations instead of just returning pure values.
Example4 expressions
>>> import Data.Char>>> import GHC.Internal.Text.ParserCombinators.ReadP>>> let p = string "my name is " *> munch1 isAlpha <* eof>>> readP_to_S p "my name is Simon"[("Simon","")]
Replace all locations in the input with the same value.
The default definition is fmap . const, but this may be
overridden with a more efficient version.
Examples
Perform a computation with Maybe and replace the result with a
constant value if it is Just:
Example2 expressions
>>> 'a' <$ Just 2Just 'a'>>> 'a' <$ NothingNothing
Because we ignore the second type parameter to Const,
the Applicative instance, which has
(<*>) :: Monoid m => Const m (a -> b) -> Const m a -> Const m b
essentially turns into Monoid m => m -> m -> m, which is (<>)
The Commitment class is an abstraction over all the current
concrete representations of monadic/applicative parser combinators in this
package. The common feature is two-level error-handling.
Some primitives must be implemented specific to each parser type
(e.g. depending on whether the parser has a running state, or
whether it is lazy). But given those primitives, large numbers of
combinators do not depend any further on the internal structure of
the particular parser.
Commit is a way of raising the severity of any errors found within
its argument. Used in the middle of a parser definition, it means that
any operations prior to commitment fail softly, but after commitment,
they fail hard.
The PolyParse class is an abstraction gathering all of the common
features that a two-level error-handling parser requires:
the applicative parsing interface, the monadic interface, and commitment.
There are two additional basic combinators that we expect to be implemented
afresh for every concrete type, but which (for technical reasons)
cannot be class methods. They are next and satisfy.
Instances9PolyParse, …
PolyParseParserDefined in polyparse-1.13.1 · Text.ParserCombinators.Poly.ByteString
PolyParseParserDefined in polyparse-1.13.1 · Text.ParserCombinators.Poly.ByteStringChar
PolyParseParserDefined in polyparse-1.13.1 · Text.ParserCombinators.Poly.Text
PolyParse (Parsert)Defined in polyparse-1.13.1 · Text.ParserCombinators.Poly.Lazy
PolyParse (Parsert)Defined in polyparse-1.13.1 · Text.ParserCombinators.Poly.Lex
PolyParse (Parsert)Defined in polyparse-1.13.1 · Text.ParserCombinators.Poly.Parser
PolyParse (Parsers)Defined in polyparse-1.13.1 · Text.ParserCombinators.Poly.StateText
PolyParse (Parserst)Defined in polyparse-1.13.1 · Text.ParserCombinators.Poly.StateLazy
PolyParse (Parserst)Defined in polyparse-1.13.1 · Text.ParserCombinators.Poly.StateParser
A return type like Either, that distinguishes not only between
right and wrong answers, but also has commitment, so that a failure
cannot be undone. This should only be used for writing very primitive
parsers - really it is an internal detail of the library.
The z type is the remaining unconsumed input.
This Parser datatype is a specialised parsing monad with error
reporting. Whereas the standard version can be used for arbitrary
token types, this version is specialised to Text input only.
ParseDotIntegerDefined in graphviz-2999.20.2.1 · Data.GraphViz.Parsing
ParseDotVersionDefined in graphviz-2999.20.2.1 · Data.GraphViz.Parsing
Ignores versionTags and assumes 'not . null . versionBranch'
(usually you want 'length . versionBranch == 2') and that all
such values are non-negative.
ParseDotBoolDefined in graphviz-2999.20.2.1 · Data.GraphViz.Parsing
ParseDotCharDefined in graphviz-2999.20.2.1 · Data.GraphViz.Parsing
ParseDotDoubleDefined in graphviz-2999.20.2.1 · Data.GraphViz.Parsing
ParseDotIntDefined in graphviz-2999.20.2.1 · Data.GraphViz.Parsing
ParseDotWord16Defined in graphviz-2999.20.2.1 · Data.GraphViz.Parsing
ParseDotWord8Defined in graphviz-2999.20.2.1 · Data.GraphViz.Parsing
ParseDotArrowFillDefined in graphviz-2999.20.2.1 · Data.GraphViz.Attributes.Arrows
ParseDotArrowModifierDefined in graphviz-2999.20.2.1 · Data.GraphViz.Attributes.Arrows
ParseDotArrowShapeDefined in graphviz-2999.20.2.1 · Data.GraphViz.Attributes.Arrows
ParseDotArrowSideDefined in graphviz-2999.20.2.1 · Data.GraphViz.Attributes.Arrows
ParseDotArrowTypeDefined in graphviz-2999.20.2.1 · Data.GraphViz.Attributes.Arrows
ParseDotBrewerNameDefined in graphviz-2999.20.2.1 · Data.GraphViz.Parsing
A variant of runParser where it is assumed that the provided
parsing function consumes all of the Text input (with the
exception of whitespace at the end).
Parse a Text where the provided Chars (as well as " and
\) are escaped and the second list of Chars are those that
are not permitted. Note: does not parse surrounding quotes. The
Bool value indicates whether empty Texts are allowed or not.