Top Description Inners Fields Constructors Methods
io.github.kusoroadeolu.clique.configuration

public final Class ParserConfiguration

extends Object
Class Inheritance
Annotations
@Stable
since:3.2.0
Imports
io.github.kusoroadeolu.clique.internal.documentation.Stable, io.github.kusoroadeolu.clique.spi.AnsiCode, java.util.Objects

An immutable configuration for a io.github.kusoroadeolu.clique.parser.MarkupParser.

Instances are obtained via builder(). The DEFAULT constant provides a pre-built configuration with the following values:

Style resolution order. When the parser encounters a markup tag, styles are resolved in the following order, with earlier entries taking precedence:

  1. Local styles — registered via ParserConfigurationBuilder#styleContext(StyleContext) or ParserConfigurationBuilder#addStyle(String, AnsiCode) on this configuration.
  2. Global custom styles — registered via Clique.registerStyle().
  3. Predefined styles — built-in colors, backgrounds, and text styles.

This class is immutable and thread-safe. ParserConfigurationBuilder is not thread-safe; external synchronization is required if a builder instance is shared across threads.

Example:

ParserConfiguration config = ParserConfiguration.builder()
    .enableAutoReset()
    .delimiter(' ')
    .addStyle("highlight", ColorCode.YELLOW)
    .build();
Since
1.0.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
public static final ParserConfiguration
DEFAULT

A default ParserConfiguration with delimiter ',', strict parsing and auto-reset disabled, and no local style context.

private final String
private final boolean
private final boolean
private final StyleContext

Constructor Summary

AccessConstructor and Description
private
private

Method Summary

Modifier and TypeMethod and Description
public static ParserConfiguration.ParserConfigurationBuilder
builder()

Returns a new builder for constructing a ParserConfiguration.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String

Returns:

the delimiter string; never null
getDelimiter
()

Returns the delimiter used to separate style names within a markup tag.

public boolean

Returns:

true if auto-reset is enabled; false otherwise
getEnableAutoReset
()

Returns whether auto-reset is enabled.

public boolean

Returns:

true if strict parsing is enabled; false otherwise
getEnableStrictParsing
()

Returns whether strict parsing is enabled.

public StyleContext

Returns:

the style context; never null
getStyleContext
()

Returns the local StyleContext for this configuration.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

DEFAULTback to summary
public static final ParserConfiguration DEFAULT

A default ParserConfiguration with delimiter ',', strict parsing and auto-reset disabled, and no local style context.

delimiterback to summary
private final String delimiter
enableAutoResetback to summary
private final boolean enableAutoReset
enableStrictParsingback to summary
private final boolean enableStrictParsing
styleContextback to summary
private final StyleContext styleContext

Constructor Detail

ParserConfigurationback to summary
private ParserConfiguration()
ParserConfigurationback to summary
private ParserConfiguration(ParserConfiguration.ParserConfigurationBuilder builder)

Method Detail

builderback to summary
public static ParserConfiguration.ParserConfigurationBuilder builder()

Returns a new builder for constructing a ParserConfiguration.

Returns:ParserConfiguration.ParserConfigurationBuilder

a new ParserConfigurationBuilder

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getDelimiterback to summary
public String getDelimiter()

Returns the delimiter used to separate style names within a markup tag.

Defaults to "," (e.g. [red, bold]). A space delimiter would allow [red bold] syntax instead.

Returns:String

the delimiter string; never null

getEnableAutoResetback to summary
public boolean getEnableAutoReset()

Returns whether auto-reset is enabled.

When true, an ANSI reset sequence is automatically injected when a new tag is opened, preventing styles from leaking into subsequent tags.

Returns:boolean

true if auto-reset is enabled; false otherwise

getEnableStrictParsingback to summary
public boolean getEnableStrictParsing()

Returns whether strict parsing is enabled.

When true, the parser throws io.github.kusoroadeolu.clique.internal.exception.UnidentifiedStyleException for unrecognized style names on otherwise valid tags. Structurally malformed tags are always passed through as-is regardless of this setting.

Returns:boolean

true if strict parsing is enabled; false otherwise

getStyleContextback to summary
public StyleContext getStyleContext()

Returns the local StyleContext for this configuration.

Styles in this context are resolved before global custom styles and predefined styles. Returns StyleContext#NONE if no local styles were registered.

Returns:StyleContext

the style context; never null

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
io.github.kusoroadeolu.clique.configuration back to summary

public Class ParserConfiguration.ParserConfigurationBuilder

extends Object
Class Inheritance
  • java.lang.Object
  • io.github.kusoroadeolu.clique.configuration.ParserConfiguration.ParserConfigurationBuilder

Builder for ParserConfiguration.

Default values match those of ParserConfiguration#DEFAULT. Methods may be called in any order; each returns this for chaining. Style registrations via addStyle(String, AnsiCode) and styleContext(StyleContext) are cumulative — both can be used together and their entries are merged into a single StyleContext at build() time.

This builder is not thread-safe.

Field Summary

Modifier and TypeField and Description
private StyleContext
private String
private boolean
private boolean
private final StyleContext.StyleContextBuilder

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ParserConfiguration.ParserConfigurationBuilder

Returns:

this builder
addStyle
(String
the markup name to register (e.g. "highlight")
markup
,
AnsiCode
the AnsiCode to associate with the markup name
code
)

Registers a single custom style in the local StyleContext.

public ParserConfiguration

Returns:

a new, immutable ParserConfiguration
build
()

Constructs a new ParserConfiguration from the current builder state.

public ParserConfiguration.ParserConfigurationBuilder

Returns:

this builder
delimiter
(char
the character to use as a style delimiter
delimiter
)

Sets the delimiter used to separate style names within a markup tag.

public ParserConfiguration.ParserConfigurationBuilder

Returns:

this builder
enableAutoReset
()

Enables auto-reset, causing an ANSI reset sequence to be injected automatically when a new tag is encountered, preventing style bleed between tags.

public ParserConfiguration.ParserConfigurationBuilder

Returns:

this builder
enableStrictParsing
()

Enables strict parsing, causing the parser to throw UnidentifiedStyleException when a valid tag contains an unrecognized style name.

public ParserConfiguration.ParserConfigurationBuilder

Returns:

this builder
styleContext
(StyleContext
the context whose styles to add; must not be null
styleContext
)

Merges all styles from the given StyleContext into the local style context for this configuration.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private StyleContext context
delimiterback to summary
private String delimiter
enableAutoResetback to summary
private boolean enableAutoReset
enableStrictParsingback to summary
private boolean enableStrictParsing
styleContextBuilderback to summary
private final StyleContext.StyleContextBuilder styleContextBuilder

Constructor Detail

ParserConfigurationBuilderback to summary
public ParserConfigurationBuilder()

Method Detail

addStyleback to summary
public ParserConfiguration.ParserConfigurationBuilder addStyle(String markup, AnsiCode code)

Registers a single custom style in the local StyleContext.

Local styles take precedence over global custom styles and predefined styles. Multiple calls accumulate; styles registered here are merged with any StyleContext added via styleContext(StyleContext).

Parameters
markup:String

the markup name to register (e.g. "highlight")

code:AnsiCode

the AnsiCode to associate with the markup name

Returns:ParserConfiguration.ParserConfigurationBuilder

this builder

buildback to summary
public ParserConfiguration build()

Constructs a new ParserConfiguration from the current builder state.

All styles registered via addStyle(String, AnsiCode) and styleContext(StyleContext) are merged into a single StyleContext at this point.

Returns:ParserConfiguration

a new, immutable ParserConfiguration

delimiterback to summary
public ParserConfiguration.ParserConfigurationBuilder delimiter(char delimiter)

Sets the delimiter used to separate style names within a markup tag.

Defaults to ','. For example, setting ' ' allows [red bold] syntax in place of [red, bold].

Parameters
delimiter:char

the character to use as a style delimiter

Returns:ParserConfiguration.ParserConfigurationBuilder

this builder

enableAutoResetback to summary
public ParserConfiguration.ParserConfigurationBuilder enableAutoReset()

Enables auto-reset, causing an ANSI reset sequence to be injected automatically when a new tag is encountered, preventing style bleed between tags.

Returns:ParserConfiguration.ParserConfigurationBuilder

this builder

enableStrictParsingback to summary
public ParserConfiguration.ParserConfigurationBuilder enableStrictParsing()

Enables strict parsing, causing the parser to throw UnidentifiedStyleException when a valid tag contains an unrecognized style name.

Without this option, unrecognized styles are silently ignored and the tag is passed through as-is. Structurally malformed tags (e.g. unclosed brackets, nested tags) are always passed through regardless of this setting.

Returns:ParserConfiguration.ParserConfigurationBuilder

this builder

styleContextback to summary
public ParserConfiguration.ParserConfigurationBuilder styleContext(StyleContext styleContext)

Merges all styles from the given StyleContext into the local style context for this configuration.

Local styles take precedence over global custom styles and predefined styles. Multiple calls accumulate; styles from each context are merged with any styles added via addStyle(String, AnsiCode).

Parameters
styleContext:StyleContext

the context whose styles to add; must not be null

Returns:ParserConfiguration.ParserConfigurationBuilder

this builder

Exceptions
NullPointerException:
if styleContext is null