range- An efficient and versatile range library.

Safe HaskellSafe



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 [Range 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.



parseRanges :: Read a => String -> Either ParseError [Range 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 [Range 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.




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 [Range 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.

Eq ParseError 
Instance details

Defined in Text.Parsec.Error

Show ParseError 
Instance details

Defined in Text.Parsec.Error