Documentation

SemVer.Basic

structure ParserError :

Contains an error message and the position at which the interpretation of the input string was not possible anymore.

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      Equations
      Instances For

        Returns a formatted string that contains the error message and position.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Defines a default with "unknown error" as message an implausible position for parser error.

          Equations
          inductive ParserResult (α : Type) :

          Holds either the value of the given type, if parsing was successful or a parser error in case of failure.

          Instances For
            def instReprParserResult.repr {α✝ : Type} [Repr α✝] :
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Defines a default for ParserResult α based on the default of ParserError.

              Equations

              Returns true iff the ParserResult contains a value of type α.

              Equations
              Instances For
                def ParserResult.to? {α : Type} (res : ParserResult α) :

                Converts a parser result into an optional value.

                Equations
                Instances For
                  def ParserResult.to! {α : Type} [Inhabited α] (res : ParserResult α) :
                  α

                  Unwraps the value from a .success parser result and panics if a .failure is provided.

                  Equations
                  Instances For
                    def ParserResult.toIO! {α : Type} (res : ParserResult α) :
                    IO α

                    Converts the value from a .success parser result into an term of IO α and throws an error, if a .failure is provided.

                    Equations
                    Instances For
                      def NonEmptyList (α : Type) :

                      Defines non-empty lists as subtype of List.

                      Equations
                      Instances For
                        def NonEmptyList.lt {α : Type} [LT α] (a b : NonEmptyList α) :

                        Less-then (lt) for non-empty lists.

                        Equations
                        Instances For
                          def NonEmptyList.decLt {α : Type} [DecidableEq α] [LT α] [DecidableLT α] (a b : NonEmptyList α) :
                          Decidable (a < b)

                          Decidable less-then for NonEmptyList.

                          Equations
                          Instances For
                            def NonEmptyList.repr {α : Type} [Repr α] (a : NonEmptyList α) (n : Nat) :

                            Provides a representation for a non empty list so that #eval can be used.

                            Equations
                            Instances For

                              Renders a non-empty list as string with its elements separated by ".".

                              For instance,

                              #eval toDotSeparatedString (⟨[0, 1, 2, 3, 4], rfl⟩ : NonEmptyList Nat)
                              

                              results in "0.1.2.3.4".

                              Equations
                              Instances For
                                def NonEmptyList.parse {α : Type} (str : String) (parseElement : StringParserResult α) (sep : Char) :

                                Parses the given string and, if possible, returns a result containing a non-empty list of terms of type α.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  def NonEmptyList.parse.helper {α : Type} (lstr : List String) (parseElement : StringParserResult α) :
                                  Equations
                                  Instances For

                                    Defines non-empty strings as subtype of String.

                                    They ensure that the requirement "Identifiers MUST NOT be empty." fulfilled that is stated as item #9 in semver.org.

                                    Equations
                                    Instances For

                                      Less-then (lt) for non-empty strings.

                                      Equations
                                      Instances For

                                        decLt is the decidable <-relation for non-empty strings, which allows for comparing two non-empty strings as in

                                        #eval decLt (⟨"abc", rfl⟩ : NonEmptyString) (⟨"bcd", rfl⟩ : NonEmptyString)
                                        
                                        Equations
                                        Instances For

                                          Parses a given string and returns a result containing a non-empty string if possible.

                                          Equations
                                          Instances For

                                            Converts a character representing a digit for base ten to the natural number corresponding to this digit - for other characters none is returned.

                                            This implementation is seemingly better suited for proofs compared than e.g.

                                            def toDigit? (c: Char) : Option Nat :=
                                              if c.isDigit then
                                                some (c.toNat - '0'.toNat)
                                              else
                                                none
                                            
                                            Equations
                                            Instances For

                                              Is an alternative implementation to the standard function Char.isDigit that is based on Char.toDigit?.

                                              This implementation appears to be better suited for proofs than Char.isDigit.

                                              Equations
                                              Instances For
                                                def Char.toDigit (c : Char) (h : c.isDigit' = true) :

                                                Returns the digit as natural number for a given character that is known to be one of '0', '1' ... '9'

                                                Equations
                                                Instances For

                                                  Converts a digit to a natural number and panics for characters that are no digits (for base ten).

                                                  Equations
                                                  Instances For

                                                    Returns true if the NonEmptyString that is provided as input only contains digits (for base ten). It is based on Char.isDigit', so that it easier to work with it in proofs.

                                                    Hence it is used here instead of shorter implementations like

                                                    def NonEmptyString.hasOnlyDigits (nes: NonEmptyString) : Bool := nes.val.isNat
                                                    
                                                    Equations
                                                    Instances For

                                                      Defines a subtype of NonEmptyString with the restriction that all characters must be digits of base ten.

                                                      This is used for the definitions

                                                        <digits> ::= <digit>
                                                                  | <digit> <digits>
                                                      
                                                        <digit> ::= "0"
                                                                  | <positive digit>
                                                      
                                                        <positive digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
                                                      

                                                      (see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions).

                                                      Equations
                                                      Instances For

                                                        Converts a non-empty string of digits to Nat.

                                                        Also here, shorter implementations exists like

                                                        def toNat (nes: NonEmptyString) : Nat := nes.val.toNat!
                                                        

                                                        However, for direct use in proofs, this implementation appears as preferable.

                                                        Equations
                                                        Instances For
                                                          Equations
                                                          Instances For
                                                            def Digits.lt (a b : Digits) :

                                                            Less-then relation for digits, which is based on Nat (and not String) as defined in https://semver.org/ under 4.1:

                                                            Identifiers consisting of only digits are compared numerically.
                                                            

                                                            This means that the canonical injection fun (a : Digits) => a.val is not a strictly increasing function as the following example shows:

                                                            def a : NonEmptyString := ⟨"23", rfl⟩
                                                            def b : NonEmptyString := ⟨"123", rfl⟩
                                                            #eval b < a -- true
                                                            
                                                            def a' : Digits := ⟨a, rfl⟩
                                                            def b' : Digits := ⟨b, rfl⟩
                                                            #eval a' < b' -- true
                                                            
                                                            Equations
                                                            Instances For
                                                              def Digits.decLt (a b : Digits) :
                                                              Decidable (a < b)

                                                              Decidable less-then for Digits.

                                                              Equations
                                                              Instances For
                                                                instance Digits.decidableLT (a b : Digits) :
                                                                Decidable (a < b)
                                                                Equations

                                                                Converts strings to Digits if possible - wrapped into a ParserResult.

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For

                                                                  Detects if a given term of type Digits has a leading zero.

                                                                  https://semver.org/ forbids leading zeros for both, numbers in the version core and numeric identifiers.

                                                                  Equations
                                                                  Instances For

                                                                    Numeric identifiers are sequences of digits without leading zeros.

                                                                    Examples: Strings "1234" and "0" are valid numeric identifiers while "01" is not.

                                                                    This is used for the definition

                                                                      <numeric identifier> ::= "0"
                                                                                            | <positive digit>
                                                                                            | <positive digit> <digits>
                                                                    

                                                                    (see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions).

                                                                    Equations
                                                                    Instances For

                                                                      Converts a numeric identifier to a natural number.

                                                                      Equations
                                                                      Instances For

                                                                        Less-then for numerical identifiers, which is based on their value as natural number and not as strings.

                                                                        Equations
                                                                        Instances For
                                                                          def NumIdent.decLt (a b : NumIdent) :
                                                                          Decidable (a < b)

                                                                          Decidable less-then for NumIdent.

                                                                          Equations
                                                                          Instances For
                                                                            instance NumIdent.decidableLT (a b : NumIdent) :
                                                                            Decidable (a < b)
                                                                            Equations

                                                                            Parses strings into NumIdent wrapped into a ParserResult if possible.

                                                                            Equations
                                                                            • One or more equations did not get rendered due to their size.
                                                                            Instances For

                                                                              Checks if a character is allowed for identifiers, i.e. it is either an letter (upper or lowercase), a digit (for base 10) or '-'.

                                                                              This is used for the definition

                                                                                <identifier character> ::= <digit>
                                                                                                        | <non-digit>
                                                                                <non-digit> ::= <letter>
                                                                                            | "-"
                                                                              
                                                                                <digits> ::= <digit>
                                                                                          | <digit> <digits>
                                                                              
                                                                                <digit> ::= "0"
                                                                                          | <positive digit>
                                                                              
                                                                                <positive digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
                                                                              
                                                                                <letter> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J"
                                                                                           | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T"
                                                                                           | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d"
                                                                                           | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n"
                                                                                           | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x"
                                                                                           | "y" | "z"
                                                                              

                                                                              (see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions).

                                                                              Equations
                                                                              Instances For

                                                                                Checks if a NonEmptyString only contains characters that are allowed for identifiers.

                                                                                Equations
                                                                                Instances For
                                                                                  def Ident :

                                                                                  Defines the fundamental base type for the different kinds of identifiers.

                                                                                  Equations
                                                                                  Instances For
                                                                                    def Ident.lt (a b : Ident) :
                                                                                    Equations
                                                                                    Instances For
                                                                                      def Ident.decLt (a b : Ident) :
                                                                                      Decidable (a < b)

                                                                                      Decidable less-then for Ident.

                                                                                      Equations
                                                                                      Instances For
                                                                                        instance Ident.decidableLT (a b : Ident) :
                                                                                        Decidable (a < b)
                                                                                        Equations

                                                                                        Parses the given string and if it is not empty and contains only allowed characters, returns an Ident wrapped in a ParserResult.

                                                                                        Equations
                                                                                        • One or more equations did not get rendered due to their size.
                                                                                        Instances For

                                                                                          Returns true iff the character is allowed for identifiers but is not a digit, i.e. is in [A-Za-z\-].

                                                                                          This is used for

                                                                                            <alphanumeric identifier> ::= <non-digit>
                                                                                                                        | <non-digit> <identifier characters>
                                                                                                                        | <identifier characters> <non-digit>
                                                                                                                        | <identifier characters> <non-digit> <identifier characters>
                                                                                          

                                                                                          (see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions).

                                                                                          Equations
                                                                                          Instances For

                                                                                            Returns true iff at least one character in the given identifier is not a digit.

                                                                                            Equations
                                                                                            Instances For
                                                                                              Equations
                                                                                              Instances For

                                                                                                Decidable less-then for AlphanumIdent.

                                                                                                Equations
                                                                                                Instances For

                                                                                                  Parses the given string and if it is a valid alphanumeric identifier, returns it wrapped in a ParserResult.

                                                                                                  Equations
                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                  Instances For
                                                                                                    inductive BuildIdent :

                                                                                                    Defines build-identifiers in accordance with

                                                                                                      <build identifier> ::= <alphanumeric identifier>
                                                                                                                          | <digits>
                                                                                                    

                                                                                                    (see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions).

                                                                                                    Instances For
                                                                                                      Equations
                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                      Instances For

                                                                                                        Returns the string representation of a build identifier.

                                                                                                        Equations
                                                                                                        Instances For

                                                                                                          Parses the given string and if it is a valid build identifier, returns it wrapped in a ParserResult.

                                                                                                          Equations
                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                          Instances For

                                                                                                            Defines dot-separated build identifiers as non-empty lists of BuildIdents in accordance with

                                                                                                              <dot-separated build identifiers> ::= <build identifier>
                                                                                                                                                | <build identifier> "." <dot-separated build identifiers>
                                                                                                            

                                                                                                            (see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions).

                                                                                                            Equations
                                                                                                            Instances For

                                                                                                              Defines a default value for DotSepBuildIdents so that to! can be used on ParserResult DotSepBuildIdents.

                                                                                                              Equations
                                                                                                              • One or more equations did not get rendered due to their size.

                                                                                                              Returns the string representation of dot-separated build identifiers.

                                                                                                              Equations
                                                                                                              Instances For

                                                                                                                Parses the given string and if it is a valid dot-separated build identifiers, retruns it wrapped in a ParserResult.

                                                                                                                Equations
                                                                                                                Instances For
                                                                                                                  inductive PreRelIdent :

                                                                                                                  Defines pre-release identifiers in accordance with

                                                                                                                    <pre-release identifier> ::= <alphanumeric identifier>
                                                                                                                                              | <numeric identifier>
                                                                                                                  

                                                                                                                  (see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions).

                                                                                                                  Instances For
                                                                                                                    Equations
                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                    Instances For

                                                                                                                      Less-then for pre-release identifiers. Numeric identifiers always have lower precedence than alphanumeric (non-numeric) identifiers (see https://semver.org/, section 11.4.3).

                                                                                                                      Equations
                                                                                                                      Instances For

                                                                                                                        Returns the string representation of a pre-release identifier.

                                                                                                                        Equations
                                                                                                                        Instances For

                                                                                                                          Parses the given string and if it is a valid pre-release identifier, returns it wrapped in a ParserResult.

                                                                                                                          Equations
                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                          Instances For

                                                                                                                            Defines dot-separated pre-release identifiers in accordance with

                                                                                                                              <dot-separated pre-release identifiers> ::= <pre-release identifier>
                                                                                                                                                                    | <pre-release identifier> "." <dot-separated pre-release identifiers>
                                                                                                                            

                                                                                                                            (see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions).

                                                                                                                            Equations
                                                                                                                            Instances For
                                                                                                                              Equations
                                                                                                                              • One or more equations did not get rendered due to their size.

                                                                                                                              Provides a representation for dot-separated pre-release identifiers so that #eval can be used.

                                                                                                                              Equations
                                                                                                                              Instances For
                                                                                                                                Equations
                                                                                                                                Instances For

                                                                                                                                  Decidable less-then for DotSepPreRelIdents.

                                                                                                                                  Equations
                                                                                                                                  Instances For

                                                                                                                                    Parses the given string and if it is a valid dot-separated pre-release identifiers, returns it wrapped in a ParserResult.

                                                                                                                                    Equations
                                                                                                                                    Instances For
                                                                                                                                      structure VersionCore :

                                                                                                                                      Defines the version core in accordance with

                                                                                                                                        <version core> ::= <major> "." <minor> "." <patch>
                                                                                                                                        <major> ::= <numeric identifier>
                                                                                                                                        <minor> ::= <numeric identifier>
                                                                                                                                        <patch> ::= <numeric identifier>
                                                                                                                                      

                                                                                                                                      (see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions).

                                                                                                                                      Version cores default to 1.0.0.

                                                                                                                                      Instances For
                                                                                                                                        def instDecidableEqVersionCore.decEq (x✝ x✝¹ : VersionCore) :
                                                                                                                                        Decidable (x✝ = x✝¹)
                                                                                                                                        Equations
                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                        Instances For
                                                                                                                                          Equations
                                                                                                                                          Instances For
                                                                                                                                            Equations
                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                            Instances For

                                                                                                                                              Returns the string representation of a version core.

                                                                                                                                              Equations
                                                                                                                                              Instances For

                                                                                                                                                Returns the version core as list of three natural numbers.

                                                                                                                                                Equations
                                                                                                                                                Instances For

                                                                                                                                                  Constructs a version core from a list of three natural numbers.

                                                                                                                                                  Equations
                                                                                                                                                  Instances For

                                                                                                                                                    Less-then for version cores.

                                                                                                                                                    Equations
                                                                                                                                                    Instances For

                                                                                                                                                      Decides if < holds true for two version cores.

                                                                                                                                                      Equations
                                                                                                                                                      Instances For

                                                                                                                                                        Parses the given string and if it is a valid version core, returns it wrapped in a ParserResult.

                                                                                                                                                        Equations
                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                        Instances For
                                                                                                                                                          structure Versionextends VersionCore :

                                                                                                                                                          Defines a full semantic version in accordance with

                                                                                                                                                            <version> ::= <version core>
                                                                                                                                                                        | <version core> "-" <pre-release>
                                                                                                                                                                        | <version core> "+" <build>
                                                                                                                                                                        | <version core> "-" <pre-release> "+" <build>
                                                                                                                                                            <pre-release> ::= <dot-separated pre-release identifiers>
                                                                                                                                                            <build> ::= <dot-separated build identifiers>
                                                                                                                                                          

                                                                                                                                                          (see https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions).

                                                                                                                                                          Instances For
                                                                                                                                                            def instDecidableEqVersion.decEq (x✝ x✝¹ : Version) :
                                                                                                                                                            Decidable (x✝ = x✝¹)
                                                                                                                                                            Equations
                                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                                            Instances For
                                                                                                                                                              Equations
                                                                                                                                                              Instances For
                                                                                                                                                                Equations
                                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                                Instances For
                                                                                                                                                                  Equations
                                                                                                                                                                  Instances For

                                                                                                                                                                    Returns the string representation of a version.

                                                                                                                                                                    Equations
                                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                                    Instances For

                                                                                                                                                                      Helper function for comparing the parts of versions outside the version core.

                                                                                                                                                                      Equations
                                                                                                                                                                      Instances For
                                                                                                                                                                        def Version.lt (v w : Version) :

                                                                                                                                                                        Less-then for versions in accordance with section 11 of the SemVer specification.

                                                                                                                                                                        Equations
                                                                                                                                                                        Instances For
                                                                                                                                                                          def Version.decLt (v w : Version) :
                                                                                                                                                                          Decidable (v < w)

                                                                                                                                                                          Decides if < holds true for two versions.

                                                                                                                                                                          Equations
                                                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                                                          Instances For

                                                                                                                                                                            Helper function that parses the version core and optional pre-release part of a version string.

                                                                                                                                                                            Equations
                                                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                                                            Instances For

                                                                                                                                                                              Parses the given string and if it is a valid version, returns it wrapped in a ParserResult.

                                                                                                                                                                              Equations
                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                              Instances For

                                                                                                                                                                                Returns true if public API provided under this version is stable.

                                                                                                                                                                                Equations
                                                                                                                                                                                Instances For

                                                                                                                                                                                  Returns a version that is the next major version based on the provided version. The returned version has no pre-release or build metadata.

                                                                                                                                                                                  Equations
                                                                                                                                                                                  Instances For

                                                                                                                                                                                    Returns a version that is the next minor version based on the provided version. The returned version has no pre-release or build metadata.

                                                                                                                                                                                    Equations
                                                                                                                                                                                    Instances For

                                                                                                                                                                                      Returns a version that is the next patch version based on the provided version. The returned version has no pre-release or build metadata.

                                                                                                                                                                                      Equations
                                                                                                                                                                                      Instances For

                                                                                                                                                                                        Returns a version that is the subsequent pre-release version based on the provided version and pre-release string.

                                                                                                                                                                                        If the resulting version is not greater than the provided version, or if the pre-release string is invalid, none is returned.

                                                                                                                                                                                        Equations
                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                        Instances For

                                                                                                                                                                                          Returns a version that is the same as the provided version but with the pre-release part set to the provided string.

                                                                                                                                                                                          If the resulting version is not greater than the provided version, or if the pre-release string is invalid, none is returned.

                                                                                                                                                                                          Equations
                                                                                                                                                                                          Instances For

                                                                                                                                                                                            Returns a version that is the same as the provided version but with the build part set to the provided string.

                                                                                                                                                                                            If the given string is not valid as build metadata, none is returned.

                                                                                                                                                                                            Equations
                                                                                                                                                                                            Instances For
                                                                                                                                                                                              def Version.isPossibleStart (previous : Option Char) (current : Char) :

                                                                                                                                                                                              Helper function that checks if a character can be the start of a version in a string, given the previous character (if any).

                                                                                                                                                                                              Equations
                                                                                                                                                                                              Instances For

                                                                                                                                                                                                Helper function that checks if a character is valid in a version string.

                                                                                                                                                                                                Equations
                                                                                                                                                                                                Instances For
                                                                                                                                                                                                  Equations
                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                    def cutOffPrefix (ch : Option Char) (str : String) :

                                                                                                                                                                                                    Helper that cuts off the prefix of a string that cannot be part of a version.

                                                                                                                                                                                                    Equations
                                                                                                                                                                                                    Instances For

                                                                                                                                                                                                      Extracts all versions that are contained in a given string.

                                                                                                                                                                                                      Equations
                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                        Equations
                                                                                                                                                                                                        Instances For