std/semantic_version
import std/semantic_version to use it. Source: src/std/semantic_version.iyi at v0.18.0.
SemanticVersion.parse? answers nil and SemanticVersion.parse panics with not a semantic version: "1.0" for anything the grammar refuses: a missing field, a leading zero in a numeric field or in a numeric prerelease identifier, an empty identifier (1.0.0-alpha..1, 1.0.0-, 1.0.0+), a byte outside [0-9A-Za-z-] in an identifier, a v prefix. One trailing newline is tolerated, the way a version read from a file arrives, and nothing else outside the grammar is.
Ordering is the standard's: numeric fields, then prerelease identifiers (numeric before alphanumeric, numeric by value however long, a numeric identifier being digits only so -1 is alphanumeric, alphanumeric by bytes, a shorter list first, and no prerelease after every prerelease). Build metadata never orders (1.0.0+a and 1.0.0+b compare equal) but does distinguish (== and hash read it), so a set of versions keeps both.
SemanticVersionstruct
pub struct SemanticVersion
# The dot-separated identifiers after `-`; a numeric identifier is held
# as a number so that `beta.2 < beta.11`, and one too long for an Int32
# is held as its digits and still ordered as a number.
struct Prerelease
# `Prerelease`, not `self`: spelled `self` it was the very method the
# `impl Comparable` below defines, which replaced it, and that one's
# `self <=> other` then called itself until the stack ran out.
def <=>(other : Prerelease) : Int32
def <=>(other : self) : Int32
def ==(other : Prerelease) : Bool
def empty? : Bool
def hash : Int32
def identifiers : Array(String | Int32)
def initialize(identifiers : Array(String | Int32) = [] of String | Int32)
def self.parse(str : String) : self
def to_s(io : IO) : Nil
def to_s : String
end
# Precedence, with build metadata ignored as the standard says. The
# parameter is `SemanticVersion` for the reason `Prerelease#<=>` gives:
# as `self` the `impl Comparable` replaced this, and every `<=>`, `==`,
# `<` and sort recursed until the stack ran out (a hang under --release).
def <=>(other : SemanticVersion) : Int32
# Identity, with build metadata read: `1.0.0+a` is not `1.0.0+b`.
def ==(other : SemanticVersion) : Bool
def build : String | ::Nil
def bump_major : self
def bump_minor : self
# A prerelease of a patch is bumped to that patch; a release to the next.
def bump_patch : self
def copy_with(major : Int32 = @major, minor : Int32 = @minor, patch : Int32 = @patch, prerelease : String | Prerelease | Nil = @prerelease, build : String | ::Nil = @build) : SemanticVersion
def hash : Int32
def initialize(major : Int32, minor : Int32, patch : Int32, prerelease : String | Prerelease | Nil = nil, build : String | ::Nil = nil)
def major : Int32
def minor : Int32
def self.parse(str : String) : self
def self.parse?(str : String) : self | ::Nil
def patch : Int32
def prerelease : Prerelease
def to_s(io : IO) : Nil
def to_s : String
def self.valid?(str : String) : Bool
endStd::Traits::Comparable for SemanticVersion::Prereleaseimpl
impl Std::Traits::Comparable for SemanticVersion::Prerelease
def <=>(other : self) : Int32
endStd::Traits::Comparable for SemanticVersionimpl
impl Std::Traits::Comparable for SemanticVersion
def <=>(other : self) : Int32
end
Semantic versions, as Semantic Versioning 2.0.0 spells them:
MAJOR.MINOR.PATCH, an optional-prereleaseof dot-separated identifiers, an optional+buildtail.