range-0.3.0.2: An efficient and versatile range library.

Data.Range.Parser

Description

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.

Synopsis

# Documentation

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.

If you disagree with the default characters for separating ranges then this function can be used to customise them, up to a point.

These are the arguments that will be used when parsing a string as a range.

Constructors

 Args FieldsunionSeparator :: StringA separator that represents a union.rangeSeparator :: StringA separator that separates the two halves of a range.wildcardSymbol :: StringA separator that implies an unbounded range.
Instances
 Source # Instance detailsDefined in Data.Range.Parser MethodsshowList :: [RangeParserArgs] -> ShowS #

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.

Instances
 Instance detailsDefined in Text.Parsec.Error Methods Instance detailsDefined in Text.Parsec.Error MethodsshowList :: [ParseError] -> ShowS #