Class VersionParser
java.lang.Object
com.github.zafarkhaja.semver.VersionParser
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumValid character types. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVersionParser(String input) Constructs aVersionParserinstance with the input string to parse. -
Method Summary
Modifier and TypeMethodDescriptionprivate StringParses the <alphanumeric identifier> non-terminal.private StringParses the <build identifier> non-terminal.private voidChecks for empty identifiers in the pre-release version or build metadata.private voidChecks for leading zeroes in the numeric identifiers.private CharacterconsumeNextCharacter(VersionParser.CharType... expected) Tries to consume the next character in the stream.private Stringdigits()Parses the <digits> non-terminal.private voidensureValidLookahead(VersionParser.CharType... expected) Checks if the next character in the stream is valid.private VersionParser.CharTypenearestCharType(VersionParser.CharType... types) Finds the nearest character type.private StringParses the <numeric identifier> non-terminal.Parses the input string.private MetadataVersionParses the <build> non-terminal.(package private) static MetadataVersionparseBuild(String build) Parses the build metadata.private MetadataVersionParses the <pre-release> non-terminal.(package private) static MetadataVersionparsePreRelease(String preRelease) Parses the pre-release version.private VersionParses the <valid semver> non-terminal.(package private) static VersionparseValidSemVer(String version) Parses the whole version including pre-release version and build metadata.private NormalVersionParses the <version core> non-terminal.(package private) static NormalVersionparseVersionCore(String versionCore) Parses the version core.private StringParses the <pre-release identifier> non-terminal.
-
Field Details
-
chars
-
-
Constructor Details
-
VersionParser
VersionParser(String input) Constructs aVersionParserinstance with the input string to parse.- Parameters:
input- the input string to parse- Throws:
IllegalArgumentException- if the input string isNULLor empty
-
-
Method Details
-
parse
Parses the input string.- Specified by:
parsein interfaceParser<Version>- Parameters:
input- the input string to parse- Returns:
- a valid version object
- Throws:
ParseException- when there is a grammar errorUnexpectedCharacterException- when encounters an unexpected character type
-
parseValidSemVer
Parses the whole version including pre-release version and build metadata.- Parameters:
version- the version string to parse- Returns:
- a valid version object
- Throws:
IllegalArgumentException- if the input string isNULLor emptyParseException- when there is a grammar errorUnexpectedCharacterException- when encounters an unexpected character type
-
parseVersionCore
Parses the version core.- Parameters:
versionCore- the version core string to parse- Returns:
- a valid normal version object
- Throws:
IllegalArgumentException- if the input string isNULLor emptyParseException- when there is a grammar errorUnexpectedCharacterException- when encounters an unexpected character type
-
parsePreRelease
Parses the pre-release version.- Parameters:
preRelease- the pre-release version string to parse- Returns:
- a valid pre-release version object
- Throws:
IllegalArgumentException- if the input string isNULLor emptyParseException- when there is a grammar errorUnexpectedCharacterException- when encounters an unexpected character type
-
parseBuild
Parses the build metadata.- Parameters:
build- the build metadata string to parse- Returns:
- a valid build metadata object
- Throws:
IllegalArgumentException- if the input string isNULLor emptyParseException- when there is a grammar errorUnexpectedCharacterException- when encounters an unexpected character type
-
parseValidSemVer
Parses the <valid semver> non-terminal.<valid semver> ::= <version core> | <version core> "-" <pre-release> | <version core> "+" <build> | <version core> "-" <pre-release> "+" <build>- Returns:
- a valid version object
-
parseVersionCore
Parses the <version core> non-terminal.<version core> ::= <major> "." <minor> "." <patch>
- Returns:
- a valid normal version object
-
parsePreRelease
Parses the <pre-release> non-terminal.<pre-release> ::= <dot-separated pre-release identifiers> <dot-separated pre-release identifiers> ::= <pre-release identifier> | <pre-release identifier> "." <dot-separated pre-release identifiers>
- Returns:
- a valid pre-release version object
-
preReleaseIdentifier
Parses the <pre-release identifier> non-terminal.<pre-release identifier> ::= <alphanumeric identifier> | <numeric identifier>- Returns:
- a single pre-release identifier
-
parseBuild
Parses the <build> non-terminal.<build> ::= <dot-separated build identifiers> <dot-separated build identifiers> ::= <build identifier> | <build identifier> "." <dot-separated build identifiers>- Returns:
- a valid build metadata object
-
buildIdentifier
Parses the <build identifier> non-terminal.<build identifier> ::= <alphanumeric identifier> | <digits>- Returns:
- a single build identifier
-
numericIdentifier
Parses the <numeric identifier> non-terminal.<numeric identifier> ::= "0" | <positive digit> | <positive digit> <digits>- Returns:
- a string representing the numeric identifier
-
alphanumericIdentifier
Parses the <alphanumeric identifier> non-terminal.<alphanumeric identifier> ::= <non-digit> | <non-digit> <identifier characters> | <identifier characters> <non-digit> | <identifier characters> <non-digit> <identifier characters>- Returns:
- a string representing the alphanumeric identifier
-
digits
Parses the <digits> non-terminal.<digits> ::= <digit> | <digit> <digits>- Returns:
- a string representing the digits
-
nearestCharType
Finds the nearest character type.- Parameters:
types- the character types to choose from- Returns:
- the nearest character type or
EOI
-
checkForLeadingZeroes
private void checkForLeadingZeroes()Checks for leading zeroes in the numeric identifiers.- Throws:
ParseException- if a numeric identifier has leading zero(es)
-
checkForEmptyIdentifier
private void checkForEmptyIdentifier()Checks for empty identifiers in the pre-release version or build metadata.- Throws:
ParseException- if the pre-release version or build metadata have empty identifier(s)
-
consumeNextCharacter
Tries to consume the next character in the stream.- Parameters:
expected- the expected types of the next character- Returns:
- the next character in the stream
- Throws:
UnexpectedCharacterException- when encounters an unexpected character type
-
ensureValidLookahead
Checks if the next character in the stream is valid.- Parameters:
expected- the expected types of the next character- Throws:
UnexpectedCharacterException- if the next character is not valid
-