Refactor pre-release and build parsing, simplify
This commit is contained in:
parent
2b77b72d71
commit
77fd6f4be1
|
@ -298,9 +298,6 @@ class VersionParser implements Parser<Version> {
|
||||||
*
|
*
|
||||||
* <dot-separated pre-release identifiers> ::= <pre-release identifier>
|
* <dot-separated pre-release identifiers> ::= <pre-release identifier>
|
||||||
* | <pre-release identifier> "." <dot-separated pre-release identifiers>
|
* | <pre-release identifier> "." <dot-separated pre-release identifiers>
|
||||||
*
|
|
||||||
* <pre-release identifier> ::= <alphanumeric identifier>
|
|
||||||
* | <numeric identifier>
|
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -309,23 +306,37 @@ class VersionParser implements Parser<Version> {
|
||||||
*/
|
*/
|
||||||
private MetadataVersion parsePreRelease() {
|
private MetadataVersion parsePreRelease() {
|
||||||
List<String> idents = new ArrayList<String>();
|
List<String> idents = new ArrayList<String>();
|
||||||
CharType end = nearestCharType(PLUS, EOL);
|
|
||||||
CharType before = nearestCharType(DOT, end);
|
|
||||||
do {
|
do {
|
||||||
checkForEmptyIdentifier();
|
checkForEmptyIdentifier();
|
||||||
if (chars.positiveLookaheadBefore(before, LETTER, HYPHEN)) {
|
idents.add(preReleaseIdentifier());
|
||||||
idents.add(alphanumericIdentifier());
|
if (chars.positiveLookahead(DOT)) {
|
||||||
} else {
|
|
||||||
idents.add(numericIdentifier());
|
|
||||||
}
|
|
||||||
if (before == DOT) {
|
|
||||||
chars.consume(DOT);
|
chars.consume(DOT);
|
||||||
before = nearestCharType(DOT, end);
|
|
||||||
}
|
}
|
||||||
} while (!chars.positiveLookahead(end));
|
} while (!chars.positiveLookahead(PLUS, EOL));
|
||||||
return new MetadataVersion(idents.toArray(new String[idents.size()]));
|
return new MetadataVersion(idents.toArray(new String[idents.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the {@literal <pre-release identifier>} non-terminal.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@literal
|
||||||
|
* <pre-release identifier> ::= <alphanumeric identifier>
|
||||||
|
* | <numeric identifier>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @return a single pre-release identifier
|
||||||
|
*/
|
||||||
|
private String preReleaseIdentifier() {
|
||||||
|
CharType boundary = nearestCharType(DOT, PLUS, EOL);
|
||||||
|
if (chars.positiveLookaheadBefore(boundary, LETTER, HYPHEN)) {
|
||||||
|
return alphanumericIdentifier();
|
||||||
|
} else {
|
||||||
|
return numericIdentifier();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the {@literal <build>} non-terminal.
|
* Parses the {@literal <build>} non-terminal.
|
||||||
*
|
*
|
||||||
|
@ -335,9 +346,6 @@ class VersionParser implements Parser<Version> {
|
||||||
*
|
*
|
||||||
* <dot-separated build identifiers> ::= <build identifier>
|
* <dot-separated build identifiers> ::= <build identifier>
|
||||||
* | <build identifier> "." <dot-separated build identifiers>
|
* | <build identifier> "." <dot-separated build identifiers>
|
||||||
*
|
|
||||||
* <build identifier> ::= <alphanumeric identifier>
|
|
||||||
* | <digits>
|
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -346,23 +354,37 @@ class VersionParser implements Parser<Version> {
|
||||||
*/
|
*/
|
||||||
private MetadataVersion parseBuild() {
|
private MetadataVersion parseBuild() {
|
||||||
List<String> idents = new ArrayList<String>();
|
List<String> idents = new ArrayList<String>();
|
||||||
CharType end = EOL;
|
|
||||||
CharType before = nearestCharType(DOT, end);
|
|
||||||
do {
|
do {
|
||||||
checkForEmptyIdentifier();
|
checkForEmptyIdentifier();
|
||||||
if (chars.positiveLookaheadBefore(before, LETTER, HYPHEN)) {
|
idents.add(buildIdentifier());
|
||||||
idents.add(alphanumericIdentifier());
|
if (chars.positiveLookahead(DOT)) {
|
||||||
} else {
|
|
||||||
idents.add(digits());
|
|
||||||
}
|
|
||||||
if (before == DOT) {
|
|
||||||
chars.consume(DOT);
|
chars.consume(DOT);
|
||||||
before = nearestCharType(DOT, end);
|
|
||||||
}
|
}
|
||||||
} while (!chars.positiveLookahead(end));
|
} while (!chars.positiveLookahead(EOL));
|
||||||
return new MetadataVersion(idents.toArray(new String[idents.size()]));
|
return new MetadataVersion(idents.toArray(new String[idents.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the {@literal <build identifier>} non-terminal.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@literal
|
||||||
|
* <build identifier> ::= <alphanumeric identifier>
|
||||||
|
* | <digits>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @return a single build identifier
|
||||||
|
*/
|
||||||
|
private String buildIdentifier() {
|
||||||
|
CharType boundary = nearestCharType(DOT, EOL);
|
||||||
|
if (chars.positiveLookaheadBefore(boundary, LETTER, HYPHEN)) {
|
||||||
|
return alphanumericIdentifier();
|
||||||
|
} else {
|
||||||
|
return digits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the {@literal <numeric identifier>} non-terminal.
|
* Parses the {@literal <numeric identifier>} non-terminal.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user