| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Shrun.Configuration.Args.Parsing.Graph.Utils
Synopsis
- type MParser a = Parsec FatalError Text a
- parseIndexSet :: MParser (NESeq CommandIndex)
- parseOneIndex :: MParser CommandIndex
- newtype FatalError = MkFatalError String
- runFatalErrors :: MParser a -> [MParser a] -> MParser a
- runFatalErrors1 :: NonEmpty (MParser a) -> MParser a
- failIfNext :: String -> MParser a -> MParser ()
- noLabel :: MParser a -> MParser a
- optionalTry :: MParser a -> MParser (Maybe a)
- parseIfNoComma :: a -> MParser a -> MParser a
- char :: Char -> MParser Char
- string :: Text -> MParser Text
- lexeme :: MParser a -> MParser a
- parseComma :: MParser ()
- parseDots :: MParser ()
- anyLeft :: MParser Bool
- mkMpError :: String -> String -> String
High-level
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 |
Instances
| Show FatalError Source # | |
Defined in Shrun.Configuration.Args.Parsing.Graph.Utils Methods showsPrec :: Int -> FatalError -> ShowS # show :: FatalError -> String # showList :: [FatalError] -> ShowS # | |
| Eq FatalError Source # | |
Defined in Shrun.Configuration.Args.Parsing.Graph.Utils | |
| Ord FatalError Source # | |
Defined in Shrun.Configuration.Args.Parsing.Graph.Utils Methods compare :: FatalError -> FatalError -> Ordering # (<) :: FatalError -> FatalError -> Bool # (<=) :: FatalError -> FatalError -> Bool # (>) :: FatalError -> FatalError -> Bool # (>=) :: FatalError -> FatalError -> Bool # max :: FatalError -> FatalError -> FatalError # min :: FatalError -> FatalError -> FatalError # | |
| ShowErrorComponent FatalError Source # | |
Defined in Shrun.Configuration.Args.Parsing.Graph.Utils Methods showErrorComponent :: FatalError -> String Source # errorComponentLen :: FatalError -> Int Source # | |
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.
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
parseComma :: MParser () Source #
Parses a comma.