Package jjparse.description
Class Description
java.lang.Object
jjparse.description.Description
public abstract sealed class Description
extends Object
permits Choice, Literal, Negation, RegExp, Sequence, Empty
The base class for all kinds of
A
Parsing.Parser Descriptions.
A
Description describes the expectation of a Parsing.Parser and can be used to generate more informative
error messages in case of a Parsing.Failure. The following kinds of Descriptions are supported:
Literal: ADescriptiondescribing that a specificStringliteral was expected.RegExp: ADescriptiondescribing that a specificPatternwas expected.Choice: ADescriptionthat represents a choice between otherDescriptions.Sequence: ADescriptionthat represents a sequence of otherDescriptions.Negation: ADescriptionthat negates anotherDescription.Empty: An emptyDescriptionthat does not provide further information.
- Author:
- Björn Lötters
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Descriptionand(Description description) describe()Produces aStringthat explains what a correspondingParsing.Parserwould expect according to thisDescription.final Descriptionnegate()final DescriptionNormalizes thisDescriptionsuch thatNegations are propagated downwards to the individualLiteralandRegExpDescriptions.final Descriptionor(Description alternative)
-
Constructor Details
-
Description
public Description()Construct a newDescription.
-
-
Method Details
-
describe
Produces aStringthat explains what a correspondingParsing.Parserwould expect according to thisDescription.- Returns:
- An
OptionalStringwhereOptional.empty()is returned in case thisDescriptionisEmpty.
-
normalize
Normalizes thisDescriptionsuch thatNegations are propagated downwards to the individualLiteralandRegExpDescriptions. Moreover,Choices ofRegExps are summarized into a singleRegExp.- Returns:
- The normalized
Description.
-
and
- Parameters:
description- The secondDescription.- Returns:
- A
SequenceDescriptioncontainingthisand the providedDescriptionin this order.
-
or
- Parameters:
alternative- The alternativeDescription.- Returns:
- A
ChoiceDescriptioncontainingthisand the providedDescriptionin this order.
-
negate
- Returns:
- A
NegationofthisDescription.
-