@@ -97,18 +97,6 @@ public TSTree parseString(TSTree oldTree, String source, TSInputEncoding encodin
9797 pointer , oldTree .getPointer (), bytes , bytes .length , encoding .getFlag ()));
9898 }
9999
100- /**
101- * Instruct the parser to start the next parse from the beginning.
102- *
103- * <p>If the parser previously failed because of a timeout or a cancellation, then by default, it
104- * will resume where it left off on the next call to any of the parsing functions. If you don't
105- * want to resume, and instead intend to use this parser to parse some other document, you must
106- * call this function first.
107- */
108- public void reset () {
109- Native .reset (this .pointer );
110- }
111-
112100 /**
113101 * Set the maximum duration in microseconds that parsing should be allowed to take before halting.
114102 *
@@ -127,6 +115,46 @@ public long getTimeout() {
127115 return Native .getTimeout (this .pointer );
128116 }
129117
118+ /**
119+ * Set the ranges of text that the parser should include when parsing.
120+ *
121+ * <p>By default, the parser will always include entire documents. This function allows you to
122+ * parse only a *portion* of a document but still return a syntax tree whose ranges match up with
123+ * the document as a whole. You can also pass multiple disjoint ranges.
124+ *
125+ * <p>The second and third parameters specify the location and length of an array of ranges. The
126+ * parser does *not* take ownership of these ranges; it copies the data, so it doesn't matter how
127+ * these ranges are allocated.
128+ *
129+ * <p>If the ranges parameter is an empty array, then the entire document will be parsed.
130+ * Otherwise, the given ranges must be ordered from earliest to latest in the document, and they
131+ * must not overlap. That is, the following must hold for all `i` < `length - 1`:
132+ * ranges[i].end_byte <= ranges[i + 1].start_byte where `length` is the length of the ranges
133+ * array.
134+ *
135+ * <p>If this requirement is not satisfied, the operation will fail, the ranges will not be
136+ * assigned, and this function will return `false`. On success, this function returns `true`
137+ */
138+ public boolean setIncludedRanges (TSRange [] ranges ) {
139+ return Native .setIncludedRanges (this .pointer , ranges );
140+ }
141+
142+ public TSRange [] getIncludedRanges () {
143+ return Native .getIncludedRanges (this .pointer );
144+ }
145+
146+ /**
147+ * Instruct the parser to start the next parse from the beginning.
148+ *
149+ * <p>If the parser previously failed because of a timeout or a cancellation, then by default, it
150+ * will resume where it left off on the next call to any of the parsing functions. If you don't
151+ * want to resume, and instead intend to use this parser to parse some other document, you must
152+ * call this function first.
153+ */
154+ public void reset () {
155+ Native .reset (this .pointer );
156+ }
157+
130158 /** Closes and deletes the current parser. */
131159 @ Override
132160 public void close () {
@@ -152,5 +180,9 @@ public static native long incrementalParseBytes(
152180 public static native void setTimeout (long parser , long timeout );
153181
154182 public static native long getTimeout (long parser );
183+
184+ public static native boolean setIncludedRanges (long parser , TSRange [] ranges );
185+
186+ public static native TSRange [] getIncludedRanges (long parser );
155187 }
156188}
0 commit comments