Package jjparse
Class Parsing.Failure<T>
- Type Parameters:
T- The covariant type of the parsed value, which is unused in case of aParsing.Failure.
- Direct Known Subclasses:
Parsing.Abort,Parsing.Error
public abstract sealed class Parsing.Failure<T>
extends Parsing<I>.Result<T>
permits Parsing<I>.Error<T>, Parsing<I>.Abort<T>
Represents a
Instead of the parsed value, a
Note: This class is intended to be immutable and hence covariant in its type parameter.
Parsing.Result which indicates a parse failure.
Instead of the parsed value, a
Parsing.Failure only carries an error message that describes the failure in detail.
Moreover, a Parsing.Failure comes in two variants:
Parsing.Error: A recoverable kind ofParsing.Failurethat may trigger backtracking during parsing.Parsing.Abort: A fatal kind ofParsing.Failurethat does not trigger backtracking and aborts parsing.
Note: This class is intended to be immutable and hence covariant in its type parameter.
- Author:
- Björn Lötters
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal StringThe error message that describes thisParsing.Failurein more detail.Fields inherited from class jjparse.Parsing.Result
rest -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMaps the value of thisParsing.Resultin case it is aParsing.Successto anotherParsing.Resultusing the providedFunctionand flattens the nestedParsing.Result.static Stringformat(Input<?> input, Description description) Format an error message for the providedInputandDescription.get()Returns the value of thisParsing.Result, if it is present.Returns the value of thisParsing.Resultor fails with an exception, if it is not present.final booleanChecks whether thisParsing.Resultis aParsing.Failure.abstract booleanisFatal()Checks whether thisParsing.Failureis fatal in the sense that no backtracking shall be applied during parsing.final booleanChecks whether thisParsing.Resultis aParsing.Success.
-
Field Details
-
message
The error message that describes thisParsing.Failurein more detail.
-
-
Constructor Details
-
Failure
The base constructor for aParsing.Failure.- Parameters:
message- The error message that describes thisParsing.Failurein more detail.rest- The rest of theInput.
-
-
Method Details
-
get
Description copied from class:Parsing.ResultReturns the value of thisParsing.Result, if it is present. -
getOrFail
Description copied from class:Parsing.ResultReturns the value of thisParsing.Resultor fails with an exception, if it is not present.- Specified by:
getOrFailin classParsing<I>.Result<T>- Returns:
- The value of this
Parsing.Result. - Throws:
NoSuchElementException- If thisParsing.Resultis not aParsing.Success.
-
isFailure
public final boolean isFailure()Description copied from class:Parsing.ResultChecks whether thisParsing.Resultis aParsing.Failure.- Specified by:
isFailurein classParsing<I>.Result<T>- Returns:
trueif thisParsing.Resultis aParsing.Failure.
-
isSuccess
public final boolean isSuccess()Description copied from class:Parsing.ResultChecks whether thisParsing.Resultis aParsing.Success.- Specified by:
isSuccessin classParsing<I>.Result<T>- Returns:
trueif thisParsing.Resultis aParsing.Success.
-
isFatal
public abstract boolean isFatal()Checks whether thisParsing.Failureis fatal in the sense that no backtracking shall be applied during parsing.- Returns:
trueif thisParsing.Failureis anParsing.Abortandfalseif it is anParsing.Error.
-
map
Description copied from class:Parsing.Result -
flatMap
Description copied from class:Parsing.ResultMaps the value of thisParsing.Resultin case it is aParsing.Successto anotherParsing.Resultusing the providedFunctionand flattens the nestedParsing.Result.- Specified by:
flatMapin classParsing<I>.Result<T>- Type Parameters:
U- The type of the returnedParsing.Result.- Parameters:
function- TheFunctionused to map the value.- Returns:
- The
Parsing.Resultof the mapped value.
-
format
Format an error message for the providedInputandDescription.- Parameters:
input- The relatedInputof the error message.description- TheDescriptionof theParsing.Parserthat failed.- Returns:
- A formatted error message that provides details about the location and kind of the error.
-