[jsemver] 81/95: Refactor pre-release and build parsing, simplify
Alexandre Viau
reazem-guest at moszumanska.debian.org
Mon Feb 16 14:58:33 UTC 2015
This is an automated email from the git hooks/post-receive script.
reazem-guest pushed a commit to branch master
in repository jsemver.
commit 77fd6f4be166c230ecb7419a8a14892707c922e1
Author: Zafar Khaja <zafarkhaja at gmail.com>
Date: Wed Feb 5 15:07:20 2014 +0400
Refactor pre-release and build parsing, simplify
---
.../github/zafarkhaja/semver/VersionParser.java | 74 ++++++++++++++--------
1 file changed, 48 insertions(+), 26 deletions(-)
diff --git a/src/main/java/com/github/zafarkhaja/semver/VersionParser.java b/src/main/java/com/github/zafarkhaja/semver/VersionParser.java
index cdb64be..5347a19 100644
--- a/src/main/java/com/github/zafarkhaja/semver/VersionParser.java
+++ b/src/main/java/com/github/zafarkhaja/semver/VersionParser.java
@@ -298,9 +298,6 @@ class VersionParser implements Parser<Version> {
*
* <dot-separated pre-release identifiers> ::= <pre-release identifier>
* | <pre-release identifier> "." <dot-separated pre-release identifiers>
- *
- * <pre-release identifier> ::= <alphanumeric identifier>
- * | <numeric identifier>
* }
* </pre>
*
@@ -309,24 +306,38 @@ class VersionParser implements Parser<Version> {
*/
private MetadataVersion parsePreRelease() {
List<String> idents = new ArrayList<String>();
- CharType end = nearestCharType(PLUS, EOL);
- CharType before = nearestCharType(DOT, end);
do {
checkForEmptyIdentifier();
- if (chars.positiveLookaheadBefore(before, LETTER, HYPHEN)) {
- idents.add(alphanumericIdentifier());
- } else {
- idents.add(numericIdentifier());
- }
- if (before == DOT) {
+ idents.add(preReleaseIdentifier());
+ if (chars.positiveLookahead(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()]));
}
/**
+ * 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.
*
* <pre>
@@ -335,9 +346,6 @@ class VersionParser implements Parser<Version> {
*
* <dot-separated build identifiers> ::= <build identifier>
* | <build identifier> "." <dot-separated build identifiers>
- *
- * <build identifier> ::= <alphanumeric identifier>
- * | <digits>
* }
* </pre>
*
@@ -346,24 +354,38 @@ class VersionParser implements Parser<Version> {
*/
private MetadataVersion parseBuild() {
List<String> idents = new ArrayList<String>();
- CharType end = EOL;
- CharType before = nearestCharType(DOT, end);
do {
checkForEmptyIdentifier();
- if (chars.positiveLookaheadBefore(before, LETTER, HYPHEN)) {
- idents.add(alphanumericIdentifier());
- } else {
- idents.add(digits());
- }
- if (before == DOT) {
+ idents.add(buildIdentifier());
+ if (chars.positiveLookahead(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()]));
}
/**
+ * 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.
*
* <pre>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jsemver.git
More information about the pkg-java-commits
mailing list