File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
main/java/io/github/treesitter/jtreesitter
test/java/io/github/treesitter/jtreesitter Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ jextract \
111111 --include-function ts_query_delete \
112112 --include-function ts_query_disable_capture \
113113 --include-function ts_query_disable_pattern \
114+ --include-function ts_query_end_byte_for_pattern \
114115 --include-function ts_query_is_pattern_guaranteed_at_step \
115116 --include-function ts_query_is_pattern_non_local \
116117 --include-function ts_query_is_pattern_rooted \
Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ public final class Query implements AutoCloseable {
120120 }
121121
122122 try (var alloc = Arena .ofConfined ()) {
123- for (int i = 0 , steps = 0 ; i < patternCount ; ++i ) {
123+ for (int i = 0 , steps ; i < patternCount ; ++i ) {
124124 var count = alloc .allocate (C_INT );
125125 var tokens = ts_query_predicates_for_pattern (query , i , count );
126126 if ((steps = count .get (C_INT , 0 )) == 0 ) continue ;
@@ -369,6 +369,17 @@ public void disableCapture(String name) throws NoSuchElementException {
369369 return ts_query_start_byte_for_pattern (query , index );
370370 }
371371
372+ /**
373+ * Get the byte offset where the given pattern ends in the query's source.
374+ *
375+ * @throws IndexOutOfBoundsException If the index exceeds the
376+ * {@linkplain #getPatternCount pattern count}.
377+ */
378+ public @ Unsigned int endByteForPattern (@ Unsigned int index ) throws IndexOutOfBoundsException {
379+ checkIndex (index );
380+ return ts_query_end_byte_for_pattern (query , index );
381+ }
382+
372383 /**
373384 * Check if the pattern with the given index has a single root node.
374385 *
Original file line number Diff line number Diff line change @@ -148,6 +148,14 @@ void startByteForPattern() {
148148 });
149149 }
150150
151+ @ Test
152+ void endByteForPattern () {
153+ assertQuery (query -> {
154+ assertEquals (26 , query .endByteForPattern (0 ));
155+ assertThrows (IndexOutOfBoundsException .class , () -> query .endByteForPattern (2 ));
156+ });
157+ }
158+
151159 @ Test
152160 void isPatternRooted () {
153161 assertQuery (query -> {
You can’t perform that action at this time.
0 commit comments