Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This package provides a simple range parser.
This range parser was designed to be a useful tool for CLI programs. For example, by default, this example depicts how the parser works:
>>>
parseRanges "-5,8-10,13-15,20-" :: Either ParseError [AnyRange Integer]
Right [UpperBoundRange 5,SpanRange 8 10,SpanRange 13 15,LowerBoundRange 20] (0.01 secs, 681,792 bytes)
And the * character translates to an infinite range. This is very useful for accepting ranges as input in CLI programs, but not as useful for parsing .cabal or package.json files.
To handle more complex parsing cases it is recommended that you use the ranges library in conjunction with parsec or Alex/Happy and convert the versions that you find into ranges.
Synopsis
- parseRanges :: Read a => String -> Either ParseError [AnyRange a]
- customParseRanges :: Read a => RangeParserArgs -> String -> Either ParseError [AnyRange a]
- data RangeParserArgs = Args {}
- defaultArgs :: RangeParserArgs
- ranges :: Read a => RangeParserArgs -> Parser [AnyRange a]
- data ParseError
Documentation
parseRanges :: Read a => String -> Either ParseError [AnyRange a] Source #
Given a string, this function will either return a parse error back to the user or the list of ranges that are represented by the parsed string. Very useful for CLI programs that need to load ranges from a single-line string.
customParseRanges :: Read a => RangeParserArgs -> String -> Either ParseError [AnyRange a] Source #
If you disagree with the default characters for separating ranges then this function can be used to customise them, up to a point.
data RangeParserArgs Source #
These are the arguments that will be used when parsing a string as a range.
Args | |
|
Instances
Show RangeParserArgs Source # | |
Defined in Data.Range.Typed.Parser showsPrec :: Int -> RangeParserArgs -> ShowS # show :: RangeParserArgs -> String # showList :: [RangeParserArgs] -> ShowS # |
defaultArgs :: RangeParserArgs Source #
These are the default arguments that are used by the parser. Please feel free to use the default arguments for you own parser and modify it from the defaults at will.
ranges :: Read a => RangeParserArgs -> Parser [AnyRange a] Source #
Given the parser arguments this returns a parsec parser that is capable of parsing a list of ranges.
data ParseError #
The abstract data type ParseError
represents parse errors. It
provides the source position (SourcePos
) of the error
and a list of error messages (Message
). A ParseError
can be returned by the function parse
. ParseError
is an
instance of the Show
and Eq
classes.
Instances
Show ParseError | |
Defined in Text.Parsec.Error showsPrec :: Int -> ParseError -> ShowS # show :: ParseError -> String # showList :: [ParseError] -> ShowS # | |
Eq ParseError | |
Defined in Text.Parsec.Error (==) :: ParseError -> ParseError -> Bool # (/=) :: ParseError -> ParseError -> Bool # |