55 Parser(std::string_view input) : input_(input) {};
58 std::expected<SemVer, Error>
parse();
61 std::string_view input_;
73 std::expected<void, Error>
expect(
char expected);
111 static std::expected<SemVer, Parser::Error>
parse(std::string_view input) {
return Parser{input}.
parse(); }
Used to parse SemVers from strings.
Definition semver.h:40
Error
Common parsing errors.
Definition semver.h:43
@ INVALID_NUMBER
Could not parse the numeric.
Definition semver.h:45
@ WRONG_CHAR
Did not find the expected char.
Definition semver.h:48
@ END_OF_STREAM
Reached end of stream while parsing.
Definition semver.h:51
std::expected< void, Error > expect(char expected)
Expect a character to be the next in the stream.
Definition semver.cpp:93
std::string_view parsePreRelease()
Consumes all characters up to the build-tag identifier '+' and returns them.
Definition semver.cpp:65
std::expected< SemVer, Error > parse()
Execute the parser, returning either the well-formed SemVer or a Parser::Error.
Definition semver.cpp:25
std::expected< SemVer, Error > parseVersionCore()
Parses a Semantic Versioning "version core" (i.e. '1.20.7') from the input stream.
Definition semver.cpp:55
Parser(std::string_view input)
Create a new parser with the given string.
Definition semver.h:55
std::expected< uint8_t, Error > parseNumericIdentifier()
Parse a number from the input stream.
Definition semver.cpp:83
Represents a simple Semantic Version number such as "4.3.7-beta".
Definition semver.h:9
bool operator==(const SemVer &) const =default
Default equality operator.
static std::expected< SemVer, Parser::Error > parse(std::string_view input)
Parse a SemVer from a string.
Definition semver.h:111
uint8_t patch
Patch version.
Definition semver.h:17
std::strong_ordering operator<=>(const SemVer &other) const
Compare two SemVer objects.
Definition semver.cpp:6
uint8_t minor
Minor version.
Definition semver.h:14
uint8_t major
Major version.
Definition semver.h:11
std::string_view pre_release
Pre-release string.
Definition semver.h:20