Package jjparse
Class Parsing.Result<T>
java.lang.Object
jjparse.Parsing.Result<T>
- Type Parameters:
T- The covariant type of the parsed value in case of aParsing.Success.
- Direct Known Subclasses:
Parsing.Failure,Parsing.Success
public abstract sealed class Parsing.Result<T>
extends Object
permits Parsing<I>.Success<T>, Parsing<I>.Failure<T>
Represents the result of a parsing operation.
A
Note: This class is intended to be immutable and hence covariant in its type parameter.
A
Parsing.Result can either be a Parsing.Success or a Parsing.Failure, whereas a failure is further divided into:
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
Fields -
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.get()Returns the value of thisParsing.Result, if it is present.abstract TReturns the value of thisParsing.Resultor fails with an exception, if it is not present.abstract booleanChecks whether thisParsing.Resultis aParsing.Failure.abstract booleanChecks whether thisParsing.Resultis aParsing.Success.
-
Field Details
-
rest
The rest of theInput.
-
-
Constructor Details
-
Result
The base constructor forParsing.Result.- Parameters:
rest- The rest of theInput.
-
-
Method Details
-
get
Returns the value of thisParsing.Result, if it is present.- Returns:
- The optional value of this
Parsing.Result.
-
getOrFail
Returns the value of thisParsing.Resultor fails with an exception, if it is not present.- Returns:
- The value of this
Parsing.Result. - Throws:
NoSuchElementException- If thisParsing.Resultis not aParsing.Success.
-
isFailure
public abstract boolean isFailure()Checks whether thisParsing.Resultis aParsing.Failure.- Returns:
trueif thisParsing.Resultis aParsing.Failure.
-
isSuccess
public abstract boolean isSuccess()Checks whether thisParsing.Resultis aParsing.Success.- Returns:
trueif thisParsing.Resultis aParsing.Success.
-
map
- Type Parameters:
U- The type of the mapped value.- Parameters:
function- TheFunctionused to map the value.- Returns:
- A
Parsing.Resultwhich contains the mapped value.
-
flatMap
Maps the value of thisParsing.Resultin case it is aParsing.Successto anotherParsing.Resultusing the providedFunctionand flattens the nestedParsing.Result.- Type Parameters:
U- The type of the returnedParsing.Result.- Parameters:
function- TheFunctionused to map the value.- Returns:
- The
Parsing.Resultof the mapped value.
-