Class Parser.Builder

  • Enclosing class:
    Parser

    public static class Parser.Builder
    extends Object
    Facilitates the construction of Parser instances. 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 Detail

      • Builder

        public Builder()
    • 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 null
        UnsatisfiedLinkError - if the language was not linked to native code
        ABIVersionError - 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 is null
        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 amount
        timeUnit - the duration time unit
        Returns:
        this builder
        Throws:
        NullPointerException - if the time unit is null
        IllegalArgumentException - 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 each Range at index i:
        
         ranges[i].end_byte <= ranges[i + 1].start_byte
         
        This method will overwrite all the currently specified ranges.
        Parameters:
        ranges - the included text ranges
        Returns:
        this builder
        Throws:
        NullPointerException - if the ranges list is null, or contains null elements
        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 each Range at index i:
        
         ranges[i].end_byte <= ranges[i + 1].start_byte
         
        Parameters:
        ranges - the included text ranges
        Returns:
        this builder
        Throws:
        NullPointerException - if the range sequence is null, or contains null elements
        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 each Range at index i:
        
         ranges[i].end_byte <= ranges[i + 1].start_byte
         
        Parameters:
        range - the included text range
        Returns:
        this builder
        Throws:
        NullPointerException - if the range is null
        Since:
        1.12.0
      • range

        public Parser.Builder range()
        Removes all currently specified ranges.
        Returns:
        this builder
        Since:
        1.12.0