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,7 +138,7 @@ class VersionParser implements Parser<Version> {
|
|||
*
|
||||
* @param input the input string to parse
|
||||
* @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
|
||||
* @throws UnexpectedElementException when encounters an unexpected character type
|
||||
*/
|
||||
|
@ -152,7 +152,7 @@ class VersionParser implements Parser<Version> {
|
|||
*
|
||||
* @param version the version string to parse
|
||||
* @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
|
||||
* @throws UnexpectedElementException when encounters an unexpected character type
|
||||
*/
|
||||
|
@ -166,7 +166,7 @@ class VersionParser implements Parser<Version> {
|
|||
*
|
||||
* @param versionCore the version core string to parse
|
||||
* @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
|
||||
* @throws UnexpectedElementException when encounters an unexpected character type
|
||||
*/
|
||||
|
@ -180,7 +180,7 @@ class VersionParser implements Parser<Version> {
|
|||
*
|
||||
* @param preRelease the pre-release version string to parse
|
||||
* @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
|
||||
*/
|
||||
static MetadataVersion parsePreRelease(String preRelease) {
|
||||
|
@ -196,7 +196,7 @@ class VersionParser implements Parser<Version> {
|
|||
*
|
||||
* @param build the build metadata string to parse
|
||||
* @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
|
||||
*/
|
||||
static MetadataVersion parseBuild(String build) {
|
||||
|
@ -272,7 +272,7 @@ class VersionParser implements Parser<Version> {
|
|||
* </pre>
|
||||
*
|
||||
* @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() {
|
||||
CharType end = closestEndpoint(PLUS, EOL);
|
||||
|
@ -311,7 +311,7 @@ class VersionParser implements Parser<Version> {
|
|||
* </pre>
|
||||
*
|
||||
* @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() {
|
||||
CharType end = EOL;
|
||||
|
@ -346,7 +346,7 @@ class VersionParser implements Parser<Version> {
|
|||
* </pre>
|
||||
*
|
||||
* @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() {
|
||||
checkForLeadingZeroes();
|
||||
|
@ -414,13 +414,13 @@ class VersionParser implements Parser<Version> {
|
|||
/**
|
||||
* 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() {
|
||||
Character la1 = chars.lookahead(1);
|
||||
Character la2 = chars.lookahead(2);
|
||||
if (la1 == '0' && DIGIT.isMatchedBy(la2)) {
|
||||
throw new GrammarException(
|
||||
throw new ParseException(
|
||||
"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.
|
||||
*
|
||||
* @throws GrammarException if the pre-release version or build
|
||||
* @throws ParseException if the pre-release version or build
|
||||
* metadata have empty identifier(s)
|
||||
*/
|
||||
private void checkForEmptyIdentifier() {
|
||||
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() {
|
||||
try {
|
||||
VersionParser.parseVersionCore("01.1.0");
|
||||
} catch (GrammarException e) {
|
||||
} catch (ParseException e) {
|
||||
return;
|
||||
}
|
||||
fail("Numeric identifier MUST NOT contain leading zeroes");
|
||||
|
@ -74,7 +74,7 @@ public class VersionParserTest {
|
|||
public void shouldRaiseErrorForEmptyPreReleaseIdentifier() {
|
||||
try {
|
||||
VersionParser.parsePreRelease("beta-1..1");
|
||||
} catch (GrammarException e) {
|
||||
} catch (ParseException e) {
|
||||
return;
|
||||
}
|
||||
fail("Identifiers MUST NOT be empty");
|
||||
|
@ -105,7 +105,7 @@ public class VersionParserTest {
|
|||
public void shouldRaiseErrorForEmptyBuildIdentifier() {
|
||||
try {
|
||||
VersionParser.parseBuild(".build.01");
|
||||
} catch (GrammarException e) {
|
||||
} catch (ParseException e) {
|
||||
return;
|
||||
}
|
||||
fail("Identifiers MUST NOT be empty");
|
||||
|
|
Loading…
Reference in New Issue
Block a user