Package ch.usi.si.seart.treesitter
Class Parser.Builder
- java.lang.Object
-
- ch.usi.si.seart.treesitter.Parser.Builder
-
- Enclosing class:
- Parser
public static class Parser.Builder extends Object
Facilitates the construction ofParserinstances. It allows for the step-by-step creation of these objects by providing methods for setting individual attributes. Input validations are performed at each build step.- Since:
- 1.7.0
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Parserbuild()Builds and returns a new Parser instance with the configured language.Parser.Builderlanguage(@NotNull Language language)Sets the programming language intended for parsing.Parser.Builderrange()Removes all currently specified ranges.Parser.Builderrange(@NotNull Range range)Specify an additional range that the parser should include when parsing.Parser.Builderranges(@NotNull Range... ranges)Specify additional ranges that the parser should include when parsing.Parser.Builderranges(@NotNull List<@NotNull Range> ranges)Sets the collection of ranges that the parser will include when parsing.Parser.Buildertimeout(long timeout)Set the maximum duration in microseconds that parsing should be allowed to take.Parser.Buildertimeout(long timeout, @NotNull TimeUnit timeUnit)Set the maximum duration that parsing should be allowed to take.Parser.Buildertimeout(@NotNull Duration duration)Set the maximum duration that parsing should be allowed to take.
-
-
-
Method Detail
-
language
public Parser.Builder language(@NotNull @NotNull Language language)
Sets the programming language intended for parsing.- Parameters:
language- the language used for parsing- Returns:
- this builder
- Throws:
NullPointerException- if the language is nullUnsatisfiedLinkError- if the language was not linked to native codeABIVersionError- if the language ABI version is incompatible with requirements
-
timeout
public Parser.Builder timeout(@NotNull @NotNull Duration duration)
Set the maximum duration that parsing should be allowed to take. If parsing time exceeds this value, an exception is thrown. The duration is rounded down to zero if it does not exceed one microsecond. Timeouts are considered disabled when the value is zero.- Parameters:
duration- the timeout duration- Returns:
- this builder
- Throws:
NullPointerException- if the duration isnull- Since:
- 1.8.0
-
timeout
public Parser.Builder timeout(long timeout, @NotNull @NotNull TimeUnit timeUnit)
Set the maximum duration that parsing should be allowed to take. If parsing time exceeds this value, an exception is thrown. The duration is rounded down to zero if it does not exceed one microsecond. Timeouts are considered disabled when the value is zero.- Parameters:
timeout- the timeout duration amounttimeUnit- the duration time unit- Returns:
- this builder
- Throws:
NullPointerException- if the time unit isnullIllegalArgumentException- if the timeout value is negative- Since:
- 1.8.0
-
timeout
public Parser.Builder timeout(long timeout)
Set the maximum duration in microseconds that parsing should be allowed to take. If parsing time exceeds this value, an exception is thrown. Timeouts are considered disabled when the value is zero.- Parameters:
timeout- the timeout in microseconds- Returns:
- this builder
- Throws:
IllegalArgumentException- if the timeout value is negative- Since:
- 1.8.0
-
ranges
public Parser.Builder ranges(@NotNull @NotNull List<@NotNull Range> ranges)
Sets the collection of ranges that the parser will include when parsing. Although ranges can be disjoint, they must be ordered from earliest to latest in the source, and they must not overlap. In other words, the following must hold for eachRangeat indexi:
This method will overwrite all the currently specified ranges.ranges[i].end_byte <= ranges[i + 1].start_byte- Parameters:
ranges- the included text ranges- Returns:
- this builder
- Throws:
NullPointerException- if the ranges list isnull, or containsnullelements- Since:
- 1.12.0
-
ranges
public Parser.Builder ranges(@NotNull @NotNull Range... ranges)
Specify additional ranges that the parser should include when parsing. The added ranges can be disjoint, both with respect to the already specified ranges, and among themselves. At the same time, the union of the already specified ranges and the added ranges must satisfy the range overlap invariant. In other words, the following must hold for eachRangeat indexi:ranges[i].end_byte <= ranges[i + 1].start_byte- Parameters:
ranges- the included text ranges- Returns:
- this builder
- Throws:
NullPointerException- if the range sequence isnull, or containsnullelements- Since:
- 1.12.0
-
range
public Parser.Builder range(@NotNull @NotNull Range range)
Specify an additional range that the parser should include when parsing. The added range can be disjoint with respect to the already specified ranges. At the same time, the union of the already specified ranges and the added range must satisfy the range overlap invariant. In other words, the following must hold for eachRangeat indexi:ranges[i].end_byte <= ranges[i + 1].start_byte- Parameters:
range- the included text range- Returns:
- this builder
- Throws:
NullPointerException- if the range isnull- Since:
- 1.12.0
-
range
public Parser.Builder range()
Removes all currently specified ranges.- Returns:
- this builder
- Since:
- 1.12.0
-
build
public Parser build()
Builds and returns a new Parser instance with the configured language.- Returns:
- a new parser instance
- Throws:
NullPointerException- if the language was not previously setIllegalArgumentException- if the range overlap invariant is violatedIncompatibleLanguageException- if the language can not be set
-
-