Remove GrammarException in favor of ParseException
This commit is contained in:
parent
9b2ffbc290
commit
84b74fa602
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright 2013 Zafar Khaja <zafarkhaja@gmail.com>.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.github.zafarkhaja.semver;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when an error occurs during the parsing specified
|
|
||||||
* by the SemVer or the formal grammar of the parsed string.
|
|
||||||
*
|
|
||||||
* @author Zafar Khaja <zafarkhaja@gmail.com>
|
|
||||||
* @since 0.7.0
|
|
||||||
*/
|
|
||||||
public class GrammarException extends ParseException {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a {@code GrammarException} instance with an error message.
|
|
||||||
*
|
|
||||||
* @param message the error message
|
|
||||||
*/
|
|
||||||
GrammarException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -138,8 +138,8 @@ class VersionParser implements Parser<Version> {
|
||||||
*
|
*
|
||||||
* @param input the input string to parse
|
* @param input the input string to parse
|
||||||
* @return a valid version object
|
* @return a valid version object
|
||||||
* @throws GrammarException when there is an error defined in
|
* @throws ParseException when there is an error defined in
|
||||||
* the SemVer or the formal grammar
|
* the SemVer or the formal grammar
|
||||||
* @throws UnexpectedElementException when encounters an unexpected character type
|
* @throws UnexpectedElementException when encounters an unexpected character type
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -152,8 +152,8 @@ class VersionParser implements Parser<Version> {
|
||||||
*
|
*
|
||||||
* @param version the version string to parse
|
* @param version the version string to parse
|
||||||
* @return a valid version object
|
* @return a valid version object
|
||||||
* @throws GrammarException when there is an error defined in
|
* @throws ParseException when there is an error defined in
|
||||||
* the SemVer or the formal grammar
|
* the SemVer or the formal grammar
|
||||||
* @throws UnexpectedElementException when encounters an unexpected character type
|
* @throws UnexpectedElementException when encounters an unexpected character type
|
||||||
*/
|
*/
|
||||||
static Version parseValidSemVer(String version) {
|
static Version parseValidSemVer(String version) {
|
||||||
|
@ -166,8 +166,8 @@ class VersionParser implements Parser<Version> {
|
||||||
*
|
*
|
||||||
* @param versionCore the version core string to parse
|
* @param versionCore the version core string to parse
|
||||||
* @return a valid normal version object
|
* @return a valid normal version object
|
||||||
* @throws GrammarException when there is an error defined in
|
* @throws ParseException when there is an error defined in
|
||||||
* the SemVer or the formal grammar
|
* the SemVer or the formal grammar
|
||||||
* @throws UnexpectedElementException when encounters an unexpected character type
|
* @throws UnexpectedElementException when encounters an unexpected character type
|
||||||
*/
|
*/
|
||||||
static NormalVersion parseVersionCore(String versionCore) {
|
static NormalVersion parseVersionCore(String versionCore) {
|
||||||
|
@ -180,8 +180,8 @@ class VersionParser implements Parser<Version> {
|
||||||
*
|
*
|
||||||
* @param preRelease the pre-release version string to parse
|
* @param preRelease the pre-release version string to parse
|
||||||
* @return a valid pre-release version object
|
* @return a valid pre-release version object
|
||||||
* @throws GrammarException when there is an error defined in
|
* @throws ParseException when there is an error defined in
|
||||||
* the SemVer or the formal grammar
|
* the SemVer or the formal grammar
|
||||||
*/
|
*/
|
||||||
static MetadataVersion parsePreRelease(String preRelease) {
|
static MetadataVersion parsePreRelease(String preRelease) {
|
||||||
if (preRelease == null) {
|
if (preRelease == null) {
|
||||||
|
@ -196,8 +196,8 @@ class VersionParser implements Parser<Version> {
|
||||||
*
|
*
|
||||||
* @param build the build metadata string to parse
|
* @param build the build metadata string to parse
|
||||||
* @return a valid build metadata object
|
* @return a valid build metadata object
|
||||||
* @throws GrammarException when there is an error defined in
|
* @throws ParseException when there is an error defined in
|
||||||
* the SemVer or the formal grammar
|
* the SemVer or the formal grammar
|
||||||
*/
|
*/
|
||||||
static MetadataVersion parseBuild(String build) {
|
static MetadataVersion parseBuild(String build) {
|
||||||
if (build == null) {
|
if (build == null) {
|
||||||
|
@ -272,7 +272,7 @@ class VersionParser implements Parser<Version> {
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @return a valid pre-release version object
|
* @return a valid pre-release version object
|
||||||
* @throws GrammarException if the pre-release version has empty identifier(s)
|
* @throws ParseException if the pre-release version has empty identifier(s)
|
||||||
*/
|
*/
|
||||||
private MetadataVersion parsePreRelease() {
|
private MetadataVersion parsePreRelease() {
|
||||||
CharType end = closestEndpoint(PLUS, EOL);
|
CharType end = closestEndpoint(PLUS, EOL);
|
||||||
|
@ -311,7 +311,7 @@ class VersionParser implements Parser<Version> {
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @return a valid build metadata object
|
* @return a valid build metadata object
|
||||||
* @throws GrammarException if the build metadata has empty identifier(s)
|
* @throws ParseException if the build metadata has empty identifier(s)
|
||||||
*/
|
*/
|
||||||
private MetadataVersion parseBuild() {
|
private MetadataVersion parseBuild() {
|
||||||
CharType end = EOL;
|
CharType end = EOL;
|
||||||
|
@ -346,7 +346,7 @@ class VersionParser implements Parser<Version> {
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @return a string representing the numeric identifier
|
* @return a string representing the numeric identifier
|
||||||
* @throws GrammarException if the numeric identifier has leading zero(es)
|
* @throws ParseException if the numeric identifier has leading zero(es)
|
||||||
*/
|
*/
|
||||||
private String numericIdentifier() {
|
private String numericIdentifier() {
|
||||||
checkForLeadingZeroes();
|
checkForLeadingZeroes();
|
||||||
|
@ -414,13 +414,13 @@ class VersionParser implements Parser<Version> {
|
||||||
/**
|
/**
|
||||||
* Checks for leading zeroes in the numeric identifiers.
|
* Checks for leading zeroes in the numeric identifiers.
|
||||||
*
|
*
|
||||||
* @throws GrammarException if a numeric identifier has leading zero(es)
|
* @throws ParseException if a numeric identifier has leading zero(es)
|
||||||
*/
|
*/
|
||||||
private void checkForLeadingZeroes() {
|
private void checkForLeadingZeroes() {
|
||||||
Character la1 = chars.lookahead(1);
|
Character la1 = chars.lookahead(1);
|
||||||
Character la2 = chars.lookahead(2);
|
Character la2 = chars.lookahead(2);
|
||||||
if (la1 == '0' && DIGIT.isMatchedBy(la2)) {
|
if (la1 == '0' && DIGIT.isMatchedBy(la2)) {
|
||||||
throw new GrammarException(
|
throw new ParseException(
|
||||||
"Numeric identifier MUST NOT contain leading zeroes"
|
"Numeric identifier MUST NOT contain leading zeroes"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -429,12 +429,12 @@ class VersionParser implements Parser<Version> {
|
||||||
/**
|
/**
|
||||||
* Checks for empty identifiers in the pre-release version or build metadata.
|
* Checks for empty identifiers in the pre-release version or build metadata.
|
||||||
*
|
*
|
||||||
* @throws GrammarException if the pre-release version or build
|
* @throws ParseException if the pre-release version or build
|
||||||
* metadata have empty identifier(s)
|
* metadata have empty identifier(s)
|
||||||
*/
|
*/
|
||||||
private void checkForEmptyIdentifier() {
|
private void checkForEmptyIdentifier() {
|
||||||
if (DOT.isMatchedBy(chars.lookahead(1))) {
|
if (DOT.isMatchedBy(chars.lookahead(1))) {
|
||||||
throw new GrammarException("Identifiers MUST NOT be empty");
|
throw new ParseException("Identifiers MUST NOT be empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class VersionParserTest {
|
||||||
public void shouldRaiseErrorIfNumericIdentifierHasLeadingZeroes() {
|
public void shouldRaiseErrorIfNumericIdentifierHasLeadingZeroes() {
|
||||||
try {
|
try {
|
||||||
VersionParser.parseVersionCore("01.1.0");
|
VersionParser.parseVersionCore("01.1.0");
|
||||||
} catch (GrammarException e) {
|
} catch (ParseException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fail("Numeric identifier MUST NOT contain leading zeroes");
|
fail("Numeric identifier MUST NOT contain leading zeroes");
|
||||||
|
@ -74,7 +74,7 @@ public class VersionParserTest {
|
||||||
public void shouldRaiseErrorForEmptyPreReleaseIdentifier() {
|
public void shouldRaiseErrorForEmptyPreReleaseIdentifier() {
|
||||||
try {
|
try {
|
||||||
VersionParser.parsePreRelease("beta-1..1");
|
VersionParser.parsePreRelease("beta-1..1");
|
||||||
} catch (GrammarException e) {
|
} catch (ParseException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fail("Identifiers MUST NOT be empty");
|
fail("Identifiers MUST NOT be empty");
|
||||||
|
@ -105,7 +105,7 @@ public class VersionParserTest {
|
||||||
public void shouldRaiseErrorForEmptyBuildIdentifier() {
|
public void shouldRaiseErrorForEmptyBuildIdentifier() {
|
||||||
try {
|
try {
|
||||||
VersionParser.parseBuild(".build.01");
|
VersionParser.parseBuild(".build.01");
|
||||||
} catch (GrammarException e) {
|
} catch (ParseException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fail("Identifiers MUST NOT be empty");
|
fail("Identifiers MUST NOT be empty");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user