shrun
Safe HaskellNone
LanguageGHC2021

Shrun.Configuration.Args.Parsing.Graph.Utils

Synopsis

High-level

type MParser a = Parsec FatalError Text a Source #

Core parser type.

parseIndexSet :: MParser (NESeq CommandIndex) Source #

Parses an index set.

  - "{1, 2, 3}"
  - "{1 .. 3}"
  - "{1, 4..6}"

parseOneIndex :: MParser CommandIndex Source #

Parses a single index i.e. a positive integer.

Errors

newtype FatalError Source #

Represents a "fatal" parse error i.e. we should not try any other parsers. This exists for better error messages.

Suppose we try parsers p1 and p2 on some text. If p1 fails, normally we will try p2, and if that fails, use its error message. However, it may be the case that p1 has the "real" failure, and its error message would be better.

For example, when parsing nodes, we attempt to parse, in order:

  • Sets: "{2,3}"
  • Arrow ranges: "2..3"
  • Positive integers: "3"

Suppose we parse '{3..2}'. This is a set, but the set parser will fail due to a bad range error. Normally, we will then try arrow ranges and positive integers, which will both fail, and the positive integer error will be reported. This is misleading though, as the real problem was deep in the set parser i.e. the range.

Hence we report this as a "fatal error", and have special logic that only tries other parsers when no fatal errors have been encountered.

Constructors

MkFatalError String 

runFatalErrors :: MParser a -> [MParser a] -> MParser a Source #

Like asum, except the combinator is runFatalError. The first parser is the default when all fail, intended for a better error message.

runFatalErrors1 :: NonEmpty (MParser a) -> MParser a Source #

Like runFatalErrors but with no default error. For when we want the underlying error to be used.

Combinators

failIfNext :: String -> MParser a -> MParser () Source #

Fails with the given error message if the given parser is next. Does not consume the parser, for better carets in the error message.

noLabel :: MParser a -> MParser a Source #

Clears a parser label.

optionalTry :: MParser a -> MParser (Maybe a) Source #

Optional + try i.e. returns Just iff the parser succeeds, otherwise backtracks.

parseIfNoComma :: a -> MParser a -> MParser a Source #

Runs the parser if iff a comma is not encountered. If a comma is encountered, it is not consumed, and the default value is returned.

Low-level

char :: Char -> MParser Char Source #

Consumes char and trailing whitespace.

string :: Text -> MParser Text Source #

Consumes string and trailing whitespace.

lexeme :: MParser a -> MParser a Source #

Modifies a parser to consume trailing whitespace.

parseComma :: MParser () Source #

Parses a comma.

parseDots :: MParser () Source #

Parses two dots.

Misc

anyLeft :: MParser Bool Source #

Returns true iff eof is not succesfully parsed.