versions-1.0.0: Types and parsers for software version numbers.

Copyright(c) Colin Woodbury, 2015
LicenseBSD3
MaintainerColin Woodbury <colingw@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Data.Versions

Contents

Description

A library for parsing and comparing software version numbers.

We like to give version numbers to our software in a myriad of different ways. Some ways follow strict guidelines for incrementing and comparison. Some follow conventional wisdom and are generally self-consistent. Some are just plain asinine. This library provides a means of parsing and comparing any style of versioning, be it a nice Semantic Version like this:

1.2.3-r1+git123

...or a monstrosity like this:

2:10.2+0.0093r3+1-1

Please switch to Semantic Versioning if you aren't currently using it. It provides consistency in version incrementing and has the best constraints on comparisons.

Using the Parsers

In general, parseV is the function you want. It attempts to parse a given Text using the three individual parsers, semver, version and mess. If one fails, it tries the next. If you know you only want to parse one specific version type, use that parser directly (e.g. semver).

Synopsis

Types

data Versioning Source

A top-level Versioning type. Acts as a wrapper for the more specific types. This allows each subtype to have its own parser, and for said parsers to be composed. This is useful for specifying custom behaviour for when a certain parser fails.

Instances

Eq Versioning Source 
Ord Versioning Source

Comparison of Ideals is always well defined.

If comparison of Generals is well-defined, then comparison of Ideal and General is well-defined, as there exists a perfect mapping from Ideal to General.

If comparison of Complexes is well-defined, then comparison of General and Complex is well defined for the same reason. This implies comparison of Ideal and Complex is also well-defined.

Show Versioning Source 

data SemVer Source

An (Ideal) version number that conforms to Semantic Versioning. This is a prescriptive parser, meaning it follows the SemVer standard.

Legal semvers are of the form: MAJOR.MINOR.PATCH-PREREL+META

Example: 1.2.3-r1+commithash

Extra Rules:

  1. Pre-release versions have lower precedence than normal versions.
  2. Build metadata does not affect version precedence.

For more information, see http://semver.org

Constructors

SemVer 

Fields

svMajor :: Int
 
svMinor :: Int
 
svPatch :: Int
 
svPreRel :: [VChunk]
 
svMeta :: [VChunk]
 

Instances

Eq SemVer Source

Two SemVers are equal if all fields except metadata are equal.

Ord SemVer Source

Build metadata does not affect version precedence.

Show SemVer Source 

data Version Source

A (General) Version. Not quite as ideal as a SemVer, but has some internal consistancy from version to version. Generally conforms to the x.x.x-x pattern.

Examples of Version that are not SemVer: 0.25-2, 8.u51-1, 20150826-1

Constructors

Version 

Fields

vChunks :: [VChunk]
 
vRel :: [VChunk]
 

data Mess Source

A (Complex) Mess. This is a descriptive parser, based on examples of stupidly crafted version numbers used in the wild.

Groups of letters/numbers, separated by a period, can be further separated by the symbols _-+:

Unfortunately, VChunks cannot be used here, as some developers have numbers like 1.003.04 which make parsers quite sad.

Not guaranteed to have well-defined ordering (Ord) behaviour, but so far interal tests show consistency.

Constructors

VLeaf [Text] 
VNode [Text] VSep Mess 

data VUnit Source

A single unit of a Version. May be digits or a string of characters. Groups of these are called VChunks, and are the identifiers separated by periods in the source.

Constructors

Digits Int 
Str Text 

type VChunk = [VUnit] Source

A logical unit of a version number. Can consist of multiple letters and numbers.

data VSep Source

Developers use a number of symbols to seperate groups of digits/letters in their version numbers. These are:

  • A colon (:). Often denotes an "epoch".
  • A hyphen (-).
  • A plus (+). Stop using this outside of metadata if you are. Example: 10.2+0.93+1-1
  • An underscore (_). Stop using this if you are.

Constructors

VColon 
VHyphen 
VPlus 
VUnder 

newtype VParser Source

A wrapper for a parser function. Can be composed via their Semigroup instance, such that a different parser can be tried if a previous one fails.

Constructors

VParser 

Parsers

semver :: Text -> Either ParseError SemVer Source

Parse a (Ideal) Semantic Version.

semver' :: String -> Either ParseError SemVer Source

Parse a Semantic Version, as a legacy String.

version :: Text -> Either ParseError Version Source

Parse a (General) Version, as defined above.

version' :: String -> Either ParseError Version Source

Parse a Version, where the input is a legacy String.

mess :: Text -> Either ParseError Mess Source

Parse a (Complex) Mess, as defined above.

mess' :: String -> Either ParseError Mess Source

Parse a Mess, where the input is a legacy String.

Wrapped Parsers

parseV :: Text -> Either ParseError Versioning Source

Parse a piece of Text into either an (Ideal) SemVer, a (General) Version, or a (Complex) Mess.

semverP :: VParser Source

A wrapped SemVer parser. Can be composed with other parsers.

versionP :: VParser Source

A wrapped Version parser. Can be composed with other parsers.

messP :: VParser Source

A wrapped Mess parser. Can be composed with other parsers.

Pretty Printing

prettyV :: Versioning -> Text Source

Convert any parsed Versioning type to its textual representation.

prettySemVer :: SemVer -> Text Source

Convert a SemVer back to its textual representation.

prettyVer :: Version -> Text Source

Convert a Version back to its textual representation.

prettyMess :: Mess -> Text Source

Convert a Mess back to its textual representation.