diff options
| author | Eli Zaretskii | 2022-10-17 13:11:13 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2022-10-17 13:11:13 +0300 |
| commit | 02f78c09b0a97ba044a43682a366a9d7732b885d (patch) | |
| tree | cf4b816c2e021f457c6917760150aa8925c2c9f9 /src | |
| parent | 170924e945f4cceda12b5e1681391c3b828a3dec (diff) | |
| download | emacs-02f78c09b0a97ba044a43682a366a9d7732b885d.tar.gz emacs-02f78c09b0a97ba044a43682a366a9d7732b885d.zip | |
; Rename ts_* symbols in treesit.c
* src/treesit.c: Rename all ts_* functions and variables to
treesit_*; all references changed. Fix whitespace.
Diffstat (limited to 'src')
| -rw-r--r-- | src/alloc.c | 4 | ||||
| -rw-r--r-- | src/casefiddle.c | 2 | ||||
| -rw-r--r-- | src/insdel.c | 14 | ||||
| -rw-r--r-- | src/print.c | 2 | ||||
| -rw-r--r-- | src/treesit.c | 559 | ||||
| -rw-r--r-- | src/treesit.h | 18 |
6 files changed, 305 insertions, 294 deletions
diff --git a/src/alloc.c b/src/alloc.c index 7197c183beb..4b6f9b57b38 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -3171,9 +3171,9 @@ cleanup_vector (struct Lisp_Vector *vector) | |||
| 3171 | } | 3171 | } |
| 3172 | #ifdef HAVE_TREE_SITTER | 3172 | #ifdef HAVE_TREE_SITTER |
| 3173 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_TS_PARSER)) | 3173 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_TS_PARSER)) |
| 3174 | ts_delete_parser (PSEUDOVEC_STRUCT (vector, Lisp_TS_Parser)); | 3174 | treesit_delete_parser (PSEUDOVEC_STRUCT (vector, Lisp_TS_Parser)); |
| 3175 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_TS_COMPILED_QUERY)) | 3175 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_TS_COMPILED_QUERY)) |
| 3176 | ts_delete_query (PSEUDOVEC_STRUCT (vector, Lisp_TS_Query)); | 3176 | treesit_delete_query (PSEUDOVEC_STRUCT (vector, Lisp_TS_Query)); |
| 3177 | #endif | 3177 | #endif |
| 3178 | #ifdef HAVE_MODULES | 3178 | #ifdef HAVE_MODULES |
| 3179 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_MODULE_FUNCTION)) | 3179 | else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_MODULE_FUNCTION)) |
diff --git a/src/casefiddle.c b/src/casefiddle.c index 3022c5cc7d6..de2325ebf36 100644 --- a/src/casefiddle.c +++ b/src/casefiddle.c | |||
| @@ -558,7 +558,7 @@ casify_region (enum case_action flag, Lisp_Object b, Lisp_Object e) | |||
| 558 | signal_after_change (start, end - start - added, end - start); | 558 | signal_after_change (start, end - start - added, end - start); |
| 559 | update_compositions (start, end, CHECK_ALL); | 559 | update_compositions (start, end, CHECK_ALL); |
| 560 | #ifdef HAVE_TREE_SITTER | 560 | #ifdef HAVE_TREE_SITTER |
| 561 | ts_record_change (start_byte, old_end_byte, CHAR_TO_BYTE (end)); | 561 | treesit_record_change (start_byte, old_end_byte, CHAR_TO_BYTE (end)); |
| 562 | #endif | 562 | #endif |
| 563 | } | 563 | } |
| 564 | 564 | ||
diff --git a/src/insdel.c b/src/insdel.c index 7cbc88e51d4..b9fba4cd747 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -947,7 +947,7 @@ insert_1_both (const char *string, | |||
| 947 | #ifdef HAVE_TREE_SITTER | 947 | #ifdef HAVE_TREE_SITTER |
| 948 | eassert (nbytes >= 0); | 948 | eassert (nbytes >= 0); |
| 949 | eassert (PT_BYTE >= 0); | 949 | eassert (PT_BYTE >= 0); |
| 950 | ts_record_change (PT_BYTE, PT_BYTE, PT_BYTE + nbytes); | 950 | treesit_record_change (PT_BYTE, PT_BYTE, PT_BYTE + nbytes); |
| 951 | #endif | 951 | #endif |
| 952 | 952 | ||
| 953 | adjust_point (nchars, nbytes); | 953 | adjust_point (nchars, nbytes); |
| @@ -1084,7 +1084,7 @@ insert_from_string_1 (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1084 | #ifdef HAVE_TREE_SITTER | 1084 | #ifdef HAVE_TREE_SITTER |
| 1085 | eassert (nbytes >= 0); | 1085 | eassert (nbytes >= 0); |
| 1086 | eassert (PT_BYTE >= 0); | 1086 | eassert (PT_BYTE >= 0); |
| 1087 | ts_record_change (PT_BYTE, PT_BYTE, PT_BYTE + nbytes); | 1087 | treesit_record_change (PT_BYTE, PT_BYTE, PT_BYTE + nbytes); |
| 1088 | #endif | 1088 | #endif |
| 1089 | 1089 | ||
| 1090 | adjust_point (nchars, outgoing_nbytes); | 1090 | adjust_point (nchars, outgoing_nbytes); |
| @@ -1157,7 +1157,7 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail) | |||
| 1157 | #ifdef HAVE_TREE_SITTER | 1157 | #ifdef HAVE_TREE_SITTER |
| 1158 | eassert (nbytes >= 0); | 1158 | eassert (nbytes >= 0); |
| 1159 | eassert (ins_bytepos >= 0); | 1159 | eassert (ins_bytepos >= 0); |
| 1160 | ts_record_change (ins_bytepos, ins_bytepos, ins_bytepos + nbytes); | 1160 | treesit_record_change (ins_bytepos, ins_bytepos, ins_bytepos + nbytes); |
| 1161 | #endif | 1161 | #endif |
| 1162 | 1162 | ||
| 1163 | if (ins_charpos < PT) | 1163 | if (ins_charpos < PT) |
| @@ -1313,7 +1313,7 @@ insert_from_buffer_1 (struct buffer *buf, | |||
| 1313 | #ifdef HAVE_TREE_SITTER | 1313 | #ifdef HAVE_TREE_SITTER |
| 1314 | eassert (outgoing_nbytes >= 0); | 1314 | eassert (outgoing_nbytes >= 0); |
| 1315 | eassert (PT_BYTE >= 0); | 1315 | eassert (PT_BYTE >= 0); |
| 1316 | ts_record_change (PT_BYTE, PT_BYTE, PT_BYTE + outgoing_nbytes); | 1316 | treesit_record_change (PT_BYTE, PT_BYTE, PT_BYTE + outgoing_nbytes); |
| 1317 | #endif | 1317 | #endif |
| 1318 | 1318 | ||
| 1319 | adjust_point (nchars, outgoing_nbytes); | 1319 | adjust_point (nchars, outgoing_nbytes); |
| @@ -1568,7 +1568,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, | |||
| 1568 | eassert (to_byte >= from_byte); | 1568 | eassert (to_byte >= from_byte); |
| 1569 | eassert (outgoing_insbytes >= 0); | 1569 | eassert (outgoing_insbytes >= 0); |
| 1570 | eassert (from_byte >= 0); | 1570 | eassert (from_byte >= 0); |
| 1571 | ts_record_change (from_byte, to_byte, from_byte + outgoing_insbytes); | 1571 | treesit_record_change (from_byte, to_byte, from_byte + outgoing_insbytes); |
| 1572 | #endif | 1572 | #endif |
| 1573 | 1573 | ||
| 1574 | /* Relocate point as if it were a marker. */ | 1574 | /* Relocate point as if it were a marker. */ |
| @@ -1609,7 +1609,7 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, | |||
| 1609 | Because this function is called in a loop, one character at a time. | 1609 | Because this function is called in a loop, one character at a time. |
| 1610 | The caller of 'replace_range_2' calls these hooks for the entire | 1610 | The caller of 'replace_range_2' calls these hooks for the entire |
| 1611 | region once. Apart from signal_after_change, any caller of this | 1611 | region once. Apart from signal_after_change, any caller of this |
| 1612 | function should also call ts_record_change. */ | 1612 | function should also call treesit_record_change. */ |
| 1613 | 1613 | ||
| 1614 | void | 1614 | void |
| 1615 | replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte, | 1615 | replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte, |
| @@ -1935,7 +1935,7 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte, | |||
| 1935 | #ifdef HAVE_TREE_SITTER | 1935 | #ifdef HAVE_TREE_SITTER |
| 1936 | eassert (from_byte <= to_byte); | 1936 | eassert (from_byte <= to_byte); |
| 1937 | eassert (from_byte >= 0); | 1937 | eassert (from_byte >= 0); |
| 1938 | ts_record_change (from_byte, to_byte, from_byte); | 1938 | treesit_record_change (from_byte, to_byte, from_byte); |
| 1939 | #endif | 1939 | #endif |
| 1940 | 1940 | ||
| 1941 | return deletion; | 1941 | return deletion; |
diff --git a/src/print.c b/src/print.c index a9afe1dd2b6..0c50cbab09a 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -2027,7 +2027,7 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, | |||
| 2027 | /* Prints #<treesit-node (identifier) in #<buffer xxx>> or | 2027 | /* Prints #<treesit-node (identifier) in #<buffer xxx>> or |
| 2028 | #<treesit-node "keyword" in #<buffer xxx>>. */ | 2028 | #<treesit-node "keyword" in #<buffer xxx>>. */ |
| 2029 | print_c_string ("#<treesit-node ", printcharfun); | 2029 | print_c_string ("#<treesit-node ", printcharfun); |
| 2030 | bool named = ts_named_node_p (XTS_NODE (obj)->node); | 2030 | bool named = treesit_named_node_p (XTS_NODE (obj)->node); |
| 2031 | const char *delim1 = named ? "(" : "\""; | 2031 | const char *delim1 = named ? "(" : "\""; |
| 2032 | const char *delim2 = named ? ")" : "\""; | 2032 | const char *delim2 = named ? ")" : "\""; |
| 2033 | print_c_string (delim1, printcharfun); | 2033 | print_c_string (delim1, printcharfun); |
diff --git a/src/treesit.c b/src/treesit.c index 7b80ea71d76..a2da44b4a7d 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -312,11 +312,11 @@ init_treesit_functions (void) | |||
| 312 | REF: https://github.com/tree-sitter/tree-sitter/issues/445 | 312 | REF: https://github.com/tree-sitter/tree-sitter/issues/445 |
| 313 | 313 | ||
| 314 | treesit.h has some commentary on the two main data structure | 314 | treesit.h has some commentary on the two main data structure |
| 315 | for the parser and node. ts_ensure_position_synced has some | 315 | for the parser and node. treesit_ensure_position_synced has some |
| 316 | commentary on how do we make tree-sitter play well with narrowing | 316 | commentary on how do we make tree-sitter play well with narrowing |
| 317 | (tree-sitter parser only sees the visible region, so we need to | 317 | (tree-sitter parser only sees the visible region, so we need to |
| 318 | translate positions back and forth). Most action happens in | 318 | translate positions back and forth). Most action happens in |
| 319 | ts_ensure_parsed, ts_read_buffer and ts_record_change. | 319 | treesit_ensure_parsed, treesit_read_buffer and treesit_record_change. |
| 320 | 320 | ||
| 321 | A complete correspondence list between tree-sitter functions and | 321 | A complete correspondence list between tree-sitter functions and |
| 322 | exposed Lisp functions can be found in the manual (elisp)API | 322 | exposed Lisp functions can be found in the manual (elisp)API |
| @@ -377,9 +377,10 @@ init_treesit_functions (void) | |||
| 377 | These are all imagined scenarios but they are not impossible :-) | 377 | These are all imagined scenarios but they are not impossible :-) |
| 378 | */ | 378 | */ |
| 379 | 379 | ||
| 380 | |||
| 380 | /*** Initialization */ | 381 | /*** Initialization */ |
| 381 | 382 | ||
| 382 | bool ts_initialized = false; | 383 | bool treesit_initialized = false; |
| 383 | 384 | ||
| 384 | static bool | 385 | static bool |
| 385 | load_tree_sitter_if_necessary (bool required) | 386 | load_tree_sitter_if_necessary (bool required) |
| @@ -409,28 +410,29 @@ load_tree_sitter_if_necessary (bool required) | |||
| 409 | } | 410 | } |
| 410 | 411 | ||
| 411 | static void * | 412 | static void * |
| 412 | ts_calloc_wrapper (size_t n, size_t size) | 413 | treesit_calloc_wrapper (size_t n, size_t size) |
| 413 | { | 414 | { |
| 414 | return xzalloc (n * size); | 415 | return xzalloc (n * size); |
| 415 | } | 416 | } |
| 416 | 417 | ||
| 417 | static void | 418 | static void |
| 418 | ts_initialize (void) | 419 | treesit_initialize (void) |
| 419 | { | 420 | { |
| 420 | if (!ts_initialized) | 421 | if (!treesit_initialized) |
| 421 | { | 422 | { |
| 422 | load_tree_sitter_if_necessary (true); | 423 | load_tree_sitter_if_necessary (true); |
| 423 | ts_set_allocator (xmalloc, ts_calloc_wrapper, xrealloc, xfree); | 424 | ts_set_allocator (xmalloc, treesit_calloc_wrapper, xrealloc, xfree); |
| 424 | ts_initialized = true; | 425 | treesit_initialized = true; |
| 425 | } | 426 | } |
| 426 | } | 427 | } |
| 427 | 428 | ||
| 429 | |||
| 428 | /*** Loading language library */ | 430 | /*** Loading language library */ |
| 429 | 431 | ||
| 430 | /* Translates a symbol treesit-<lang> to a C name | 432 | /* Translates a symbol treesit-<lang> to a C name |
| 431 | treesit_<lang>. */ | 433 | treesit_<lang>. */ |
| 432 | static void | 434 | static void |
| 433 | ts_symbol_to_c_name (char *symbol_name) | 435 | treesit_symbol_to_c_name (char *symbol_name) |
| 434 | { | 436 | { |
| 435 | for (int idx = 0; idx < strlen (symbol_name); idx++) | 437 | for (int idx = 0; idx < strlen (symbol_name); idx++) |
| 436 | { | 438 | { |
| @@ -440,8 +442,8 @@ ts_symbol_to_c_name (char *symbol_name) | |||
| 440 | } | 442 | } |
| 441 | 443 | ||
| 442 | static bool | 444 | static bool |
| 443 | ts_find_override_name (Lisp_Object language_symbol, Lisp_Object *name, | 445 | treesit_find_override_name (Lisp_Object language_symbol, Lisp_Object *name, |
| 444 | Lisp_Object *c_symbol) | 446 | Lisp_Object *c_symbol) |
| 445 | { | 447 | { |
| 446 | for (Lisp_Object list = Vtreesit_load_name_override_list; | 448 | for (Lisp_Object list = Vtreesit_load_name_override_list; |
| 447 | !NILP (list); list = XCDR (list)) | 449 | !NILP (list); list = XCDR (list)) |
| @@ -465,8 +467,8 @@ ts_find_override_name (Lisp_Object language_symbol, Lisp_Object *name, | |||
| 465 | into *path_candidates. Obiviously path_candidates should be a Lisp | 467 | into *path_candidates. Obiviously path_candidates should be a Lisp |
| 466 | list of Lisp strings. */ | 468 | list of Lisp strings. */ |
| 467 | static void | 469 | static void |
| 468 | ts_load_language_push_for_each_suffix (Lisp_Object lib_base_name, | 470 | treesit_load_language_push_for_each_suffix (Lisp_Object lib_base_name, |
| 469 | Lisp_Object *path_candidates) | 471 | Lisp_Object *path_candidates) |
| 470 | { | 472 | { |
| 471 | for (Lisp_Object suffixes = Vdynamic_library_suffixes; | 473 | for (Lisp_Object suffixes = Vdynamic_library_suffixes; |
| 472 | !NILP (suffixes); suffixes = XCDR (suffixes)) | 474 | !NILP (suffixes); suffixes = XCDR (suffixes)) |
| @@ -482,8 +484,8 @@ ts_load_language_push_for_each_suffix (Lisp_Object lib_base_name, | |||
| 482 | If error occurs, return NULL and fill SIGNAL_SYMBOL and SIGNAL_DATA | 484 | If error occurs, return NULL and fill SIGNAL_SYMBOL and SIGNAL_DATA |
| 483 | with values suitable for xsignal. */ | 485 | with values suitable for xsignal. */ |
| 484 | static TSLanguage * | 486 | static TSLanguage * |
| 485 | ts_load_language (Lisp_Object language_symbol, | 487 | treesit_load_language (Lisp_Object language_symbol, |
| 486 | Lisp_Object *signal_symbol, Lisp_Object *signal_data) | 488 | Lisp_Object *signal_symbol, Lisp_Object *signal_data) |
| 487 | { | 489 | { |
| 488 | Lisp_Object symbol_name = Fsymbol_name (language_symbol); | 490 | Lisp_Object symbol_name = Fsymbol_name (language_symbol); |
| 489 | 491 | ||
| @@ -494,13 +496,14 @@ ts_load_language (Lisp_Object language_symbol, | |||
| 494 | concat2 (build_pure_c_string ("tree-sitter-"), symbol_name); | 496 | concat2 (build_pure_c_string ("tree-sitter-"), symbol_name); |
| 495 | /* FIXME: The result of strdup leaks memory in some cases. */ | 497 | /* FIXME: The result of strdup leaks memory in some cases. */ |
| 496 | char *c_name = strdup (SSDATA (base_name)); | 498 | char *c_name = strdup (SSDATA (base_name)); |
| 497 | ts_symbol_to_c_name (c_name); | 499 | treesit_symbol_to_c_name (c_name); |
| 498 | 500 | ||
| 499 | /* Override the library name and C name, if appropriate. */ | 501 | /* Override the library name and C name, if appropriate. */ |
| 500 | Lisp_Object override_name; | 502 | Lisp_Object override_name; |
| 501 | Lisp_Object override_c_name; | 503 | Lisp_Object override_c_name; |
| 502 | bool found_override = ts_find_override_name (language_symbol, &override_name, | 504 | bool found_override = treesit_find_override_name (language_symbol, |
| 503 | &override_c_name); | 505 | &override_name, |
| 506 | &override_c_name); | ||
| 504 | if (found_override) | 507 | if (found_override) |
| 505 | { | 508 | { |
| 506 | lib_base_name = override_name; | 509 | lib_base_name = override_name; |
| @@ -511,19 +514,19 @@ ts_load_language (Lisp_Object language_symbol, | |||
| 511 | Lisp_Object path_candidates = Qnil; | 514 | Lisp_Object path_candidates = Qnil; |
| 512 | /* First push just the filenames to the candidate list, which will | 515 | /* First push just the filenames to the candidate list, which will |
| 513 | make dynlib_open look under standard system load paths. */ | 516 | make dynlib_open look under standard system load paths. */ |
| 514 | ts_load_language_push_for_each_suffix (lib_base_name, &path_candidates); | 517 | treesit_load_language_push_for_each_suffix (lib_base_name, &path_candidates); |
| 515 | /* Then push ~/.emacs.d/tree-sitter paths. */ | 518 | /* Then push ~/.emacs.d/tree-sitter paths. */ |
| 516 | Lisp_Object lib_name = | 519 | Lisp_Object lib_name = |
| 517 | Fexpand_file_name (concat2 (build_string ("tree-sitter/"), lib_base_name), | 520 | Fexpand_file_name (concat2 (build_string ("tree-sitter/"), lib_base_name), |
| 518 | Fsymbol_value (Quser_emacs_directory)); | 521 | Fsymbol_value (Quser_emacs_directory)); |
| 519 | ts_load_language_push_for_each_suffix (lib_name, &path_candidates); | 522 | treesit_load_language_push_for_each_suffix (lib_name, &path_candidates); |
| 520 | /* Then push paths from treesit-extra-load-path. */ | 523 | /* Then push paths from treesit-extra-load-path. */ |
| 521 | for (Lisp_Object tail = Freverse (Vtreesit_extra_load_path); | 524 | for (Lisp_Object tail = Freverse (Vtreesit_extra_load_path); |
| 522 | !NILP (tail); tail = XCDR (tail)) | 525 | !NILP (tail); tail = XCDR (tail)) |
| 523 | { | 526 | { |
| 524 | ts_load_language_push_for_each_suffix (Fexpand_file_name (lib_base_name, | 527 | Lisp_Object expanded_lib = Fexpand_file_name (lib_base_name, XCAR (tail)); |
| 525 | XCAR (tail)), | 528 | treesit_load_language_push_for_each_suffix (expanded_lib, |
| 526 | &path_candidates); | 529 | &path_candidates); |
| 527 | } | 530 | } |
| 528 | 531 | ||
| 529 | /* Try loading the dynamic library by each path candidate. Stop | 532 | /* Try loading the dynamic library by each path candidate. Stop |
| @@ -590,10 +593,10 @@ If DETAIL is non-nil, return (t . nil) when LANGUAGE is available, | |||
| 590 | (Lisp_Object language, Lisp_Object detail) | 593 | (Lisp_Object language, Lisp_Object detail) |
| 591 | { | 594 | { |
| 592 | CHECK_SYMBOL (language); | 595 | CHECK_SYMBOL (language); |
| 593 | ts_initialize (); | 596 | treesit_initialize (); |
| 594 | Lisp_Object signal_symbol = Qnil; | 597 | Lisp_Object signal_symbol = Qnil; |
| 595 | Lisp_Object signal_data = Qnil; | 598 | Lisp_Object signal_data = Qnil; |
| 596 | if (ts_load_language (language, &signal_symbol, &signal_data) == NULL) | 599 | if (treesit_load_language (language, &signal_symbol, &signal_data) == NULL) |
| 597 | { | 600 | { |
| 598 | if (NILP (detail)) | 601 | if (NILP (detail)) |
| 599 | return Qnil; | 602 | return Qnil; |
| @@ -630,7 +633,7 @@ is non-nil, return the oldest compatible ABI version. */) | |||
| 630 | /*** Parsing functions */ | 633 | /*** Parsing functions */ |
| 631 | 634 | ||
| 632 | static void | 635 | static void |
| 633 | ts_check_parser (Lisp_Object obj) | 636 | treesit_check_parser (Lisp_Object obj) |
| 634 | { | 637 | { |
| 635 | CHECK_TS_PARSER (obj); | 638 | CHECK_TS_PARSER (obj); |
| 636 | if (XTS_PARSER (obj)->deleted) | 639 | if (XTS_PARSER (obj)->deleted) |
| @@ -640,8 +643,8 @@ ts_check_parser (Lisp_Object obj) | |||
| 640 | /* An auxiliary function that saves a few lines of code. Assumes TREE | 643 | /* An auxiliary function that saves a few lines of code. Assumes TREE |
| 641 | is not NULL. */ | 644 | is not NULL. */ |
| 642 | static inline void | 645 | static inline void |
| 643 | ts_tree_edit_1 (TSTree *tree, ptrdiff_t start_byte, | 646 | treesit_tree_edit_1 (TSTree *tree, ptrdiff_t start_byte, |
| 644 | ptrdiff_t old_end_byte, ptrdiff_t new_end_byte) | 647 | ptrdiff_t old_end_byte, ptrdiff_t new_end_byte) |
| 645 | { | 648 | { |
| 646 | eassert (start_byte >= 0); | 649 | eassert (start_byte >= 0); |
| 647 | eassert (start_byte <= old_end_byte); | 650 | eassert (start_byte <= old_end_byte); |
| @@ -660,8 +663,8 @@ ts_tree_edit_1 (TSTree *tree, ptrdiff_t start_byte, | |||
| 660 | function does not parse the buffer and only updates the tree. (So it | 663 | function does not parse the buffer and only updates the tree. (So it |
| 661 | should be very fast.) */ | 664 | should be very fast.) */ |
| 662 | void | 665 | void |
| 663 | ts_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, | 666 | treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, |
| 664 | ptrdiff_t new_end_byte) | 667 | ptrdiff_t new_end_byte) |
| 665 | { | 668 | { |
| 666 | for (Lisp_Object parser_list = BVAR (current_buffer, ts_parser_list); | 669 | for (Lisp_Object parser_list = BVAR (current_buffer, ts_parser_list); |
| 667 | !NILP (parser_list); | 670 | !NILP (parser_list); |
| @@ -669,7 +672,7 @@ ts_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, | |||
| 669 | { | 672 | { |
| 670 | CHECK_CONS (parser_list); | 673 | CHECK_CONS (parser_list); |
| 671 | Lisp_Object lisp_parser = XCAR (parser_list); | 674 | Lisp_Object lisp_parser = XCAR (parser_list); |
| 672 | ts_check_parser (lisp_parser); | 675 | treesit_check_parser (lisp_parser); |
| 673 | TSTree *tree = XTS_PARSER (lisp_parser)->tree; | 676 | TSTree *tree = XTS_PARSER (lisp_parser)->tree; |
| 674 | if (tree != NULL) | 677 | if (tree != NULL) |
| 675 | { | 678 | { |
| @@ -700,8 +703,8 @@ ts_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, | |||
| 700 | eassert (start_offset <= old_end_offset); | 703 | eassert (start_offset <= old_end_offset); |
| 701 | eassert (start_offset <= new_end_offset); | 704 | eassert (start_offset <= new_end_offset); |
| 702 | 705 | ||
| 703 | ts_tree_edit_1 (tree, start_offset, old_end_offset, | 706 | treesit_tree_edit_1 (tree, start_offset, old_end_offset, |
| 704 | new_end_offset); | 707 | new_end_offset); |
| 705 | XTS_PARSER (lisp_parser)->need_reparse = true; | 708 | XTS_PARSER (lisp_parser)->need_reparse = true; |
| 706 | XTS_PARSER (lisp_parser)->timestamp++; | 709 | XTS_PARSER (lisp_parser)->timestamp++; |
| 707 | 710 | ||
| @@ -733,7 +736,7 @@ ts_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, | |||
| 733 | } | 736 | } |
| 734 | 737 | ||
| 735 | static void | 738 | static void |
| 736 | ts_ensure_position_synced (Lisp_Object parser) | 739 | treesit_ensure_position_synced (Lisp_Object parser) |
| 737 | { | 740 | { |
| 738 | TSTree *tree = XTS_PARSER (parser)->tree; | 741 | TSTree *tree = XTS_PARSER (parser)->tree; |
| 739 | 742 | ||
| @@ -758,7 +761,7 @@ ts_ensure_position_synced (Lisp_Object parser) | |||
| 758 | if (visible_beg > BUF_BEGV_BYTE (buffer)) | 761 | if (visible_beg > BUF_BEGV_BYTE (buffer)) |
| 759 | { | 762 | { |
| 760 | /* Tree-sitter sees: insert at the beginning. */ | 763 | /* Tree-sitter sees: insert at the beginning. */ |
| 761 | ts_tree_edit_1 (tree, 0, 0, visible_beg - BUF_BEGV_BYTE (buffer)); | 764 | treesit_tree_edit_1 (tree, 0, 0, visible_beg - BUF_BEGV_BYTE (buffer)); |
| 762 | visible_beg = BUF_BEGV_BYTE (buffer); | 765 | visible_beg = BUF_BEGV_BYTE (buffer); |
| 763 | eassert (visible_beg <= visible_end); | 766 | eassert (visible_beg <= visible_end); |
| 764 | } | 767 | } |
| @@ -766,18 +769,18 @@ ts_ensure_position_synced (Lisp_Object parser) | |||
| 766 | if (visible_end < BUF_ZV_BYTE (buffer)) | 769 | if (visible_end < BUF_ZV_BYTE (buffer)) |
| 767 | { | 770 | { |
| 768 | /* Tree-sitter sees: insert at the end. */ | 771 | /* Tree-sitter sees: insert at the end. */ |
| 769 | ts_tree_edit_1 (tree, visible_end - visible_beg, | 772 | treesit_tree_edit_1 (tree, visible_end - visible_beg, |
| 770 | visible_end - visible_beg, | 773 | visible_end - visible_beg, |
| 771 | BUF_ZV_BYTE (buffer) - visible_beg); | 774 | BUF_ZV_BYTE (buffer) - visible_beg); |
| 772 | visible_end = BUF_ZV_BYTE (buffer); | 775 | visible_end = BUF_ZV_BYTE (buffer); |
| 773 | eassert (visible_beg <= visible_end); | 776 | eassert (visible_beg <= visible_end); |
| 774 | } | 777 | } |
| 775 | else if (visible_end > BUF_ZV_BYTE (buffer)) | 778 | else if (visible_end > BUF_ZV_BYTE (buffer)) |
| 776 | { | 779 | { |
| 777 | /* Tree-sitter sees: delete at the end. */ | 780 | /* Tree-sitter sees: delete at the end. */ |
| 778 | ts_tree_edit_1 (tree, BUF_ZV_BYTE (buffer) - visible_beg, | 781 | treesit_tree_edit_1 (tree, BUF_ZV_BYTE (buffer) - visible_beg, |
| 779 | visible_end - visible_beg, | 782 | visible_end - visible_beg, |
| 780 | BUF_ZV_BYTE (buffer) - visible_beg); | 783 | BUF_ZV_BYTE (buffer) - visible_beg); |
| 781 | visible_end = BUF_ZV_BYTE (buffer); | 784 | visible_end = BUF_ZV_BYTE (buffer); |
| 782 | eassert (visible_beg <= visible_end); | 785 | eassert (visible_beg <= visible_end); |
| 783 | } | 786 | } |
| @@ -785,7 +788,7 @@ ts_ensure_position_synced (Lisp_Object parser) | |||
| 785 | if (visible_beg < BUF_BEGV_BYTE (buffer)) | 788 | if (visible_beg < BUF_BEGV_BYTE (buffer)) |
| 786 | { | 789 | { |
| 787 | /* Tree-sitter sees: delete at the beginning. */ | 790 | /* Tree-sitter sees: delete at the beginning. */ |
| 788 | ts_tree_edit_1 (tree, 0, BUF_BEGV_BYTE (buffer) - visible_beg, 0); | 791 | treesit_tree_edit_1 (tree, 0, BUF_BEGV_BYTE (buffer) - visible_beg, 0); |
| 789 | visible_beg = BUF_BEGV_BYTE (buffer); | 792 | visible_beg = BUF_BEGV_BYTE (buffer); |
| 790 | eassert (visible_beg <= visible_end); | 793 | eassert (visible_beg <= visible_end); |
| 791 | } | 794 | } |
| @@ -797,7 +800,7 @@ ts_ensure_position_synced (Lisp_Object parser) | |||
| 797 | } | 800 | } |
| 798 | 801 | ||
| 799 | static void | 802 | static void |
| 800 | ts_check_buffer_size (struct buffer *buffer) | 803 | treesit_check_buffer_size (struct buffer *buffer) |
| 801 | { | 804 | { |
| 802 | ptrdiff_t buffer_size = (BUF_Z (buffer) - BUF_BEG (buffer)); | 805 | ptrdiff_t buffer_size = (BUF_Z (buffer) - BUF_BEG (buffer)); |
| 803 | if (buffer_size > UINT32_MAX) | 806 | if (buffer_size > UINT32_MAX) |
| @@ -809,20 +812,20 @@ ts_check_buffer_size (struct buffer *buffer) | |||
| 809 | /* Parse the buffer. We don't parse until we have to. When we have | 812 | /* Parse the buffer. We don't parse until we have to. When we have |
| 810 | to, we call this function to parse and update the tree. */ | 813 | to, we call this function to parse and update the tree. */ |
| 811 | static void | 814 | static void |
| 812 | ts_ensure_parsed (Lisp_Object parser) | 815 | treesit_ensure_parsed (Lisp_Object parser) |
| 813 | { | 816 | { |
| 814 | if (!XTS_PARSER (parser)->need_reparse) | 817 | if (!XTS_PARSER (parser)->need_reparse) |
| 815 | return; | 818 | return; |
| 816 | TSParser *ts_parser = XTS_PARSER (parser)->parser; | 819 | TSParser *treesit_parser = XTS_PARSER (parser)->parser; |
| 817 | TSTree *tree = XTS_PARSER(parser)->tree; | 820 | TSTree *tree = XTS_PARSER (parser)->tree; |
| 818 | TSInput input = XTS_PARSER (parser)->input; | 821 | TSInput input = XTS_PARSER (parser)->input; |
| 819 | struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); | 822 | struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); |
| 820 | ts_check_buffer_size (buffer); | 823 | treesit_check_buffer_size (buffer); |
| 821 | 824 | ||
| 822 | /* Before we parse, catch up with the narrowing situation. */ | 825 | /* Before we parse, catch up with the narrowing situation. */ |
| 823 | ts_ensure_position_synced (parser); | 826 | treesit_ensure_position_synced (parser); |
| 824 | 827 | ||
| 825 | TSTree *new_tree = ts_parser_parse (ts_parser, tree, input); | 828 | TSTree *new_tree = ts_parser_parse (treesit_parser, tree, input); |
| 826 | /* This should be very rare (impossible, really): it only happens | 829 | /* This should be very rare (impossible, really): it only happens |
| 827 | when 1) language is not set (impossible in Emacs because the user | 830 | when 1) language is not set (impossible in Emacs because the user |
| 828 | has to supply a language to create a parser), 2) parse canceled | 831 | has to supply a language to create a parser), 2) parse canceled |
| @@ -847,15 +850,15 @@ ts_ensure_parsed (Lisp_Object parser) | |||
| 847 | buffer. It reads one character at a time and automatically skips | 850 | buffer. It reads one character at a time and automatically skips |
| 848 | the gap. */ | 851 | the gap. */ |
| 849 | static const char* | 852 | static const char* |
| 850 | ts_read_buffer (void *parser, uint32_t byte_index, | 853 | treesit_read_buffer (void *parser, uint32_t byte_index, |
| 851 | TSPoint position, uint32_t *bytes_read) | 854 | TSPoint position, uint32_t *bytes_read) |
| 852 | { | 855 | { |
| 853 | struct buffer *buffer = XBUFFER (((struct Lisp_TS_Parser *) parser)->buffer); | 856 | struct buffer *buffer = XBUFFER (((struct Lisp_TS_Parser *) parser)->buffer); |
| 854 | ptrdiff_t visible_beg = ((struct Lisp_TS_Parser *) parser)->visible_beg; | 857 | ptrdiff_t visible_beg = ((struct Lisp_TS_Parser *) parser)->visible_beg; |
| 855 | ptrdiff_t visible_end = ((struct Lisp_TS_Parser *) parser)->visible_end; | 858 | ptrdiff_t visible_end = ((struct Lisp_TS_Parser *) parser)->visible_end; |
| 856 | ptrdiff_t byte_pos = byte_index + visible_beg; | 859 | ptrdiff_t byte_pos = byte_index + visible_beg; |
| 857 | /* We will make sure visible_beg = BUF_BEGV_BYTE before re-parse (in | 860 | /* We will make sure visible_beg = BUF_BEGV_BYTE before re-parse (in |
| 858 | ts_ensure_parsed), so byte_pos will never be smaller than | 861 | treesit_ensure_parsed), so byte_pos will never be smaller than |
| 859 | BUF_BEG_BYTE. */ | 862 | BUF_BEG_BYTE. */ |
| 860 | eassert (visible_beg = BUF_BEGV_BYTE (buffer)); | 863 | eassert (visible_beg = BUF_BEGV_BYTE (buffer)); |
| 861 | eassert (visible_end = BUF_ZV_BYTE (buffer)); | 864 | eassert (visible_end = BUF_ZV_BYTE (buffer)); |
| @@ -895,8 +898,8 @@ ts_read_buffer (void *parser, uint32_t byte_index, | |||
| 895 | 898 | ||
| 896 | /* Wrap the parser in a Lisp_Object to be used in the Lisp machine. */ | 899 | /* Wrap the parser in a Lisp_Object to be used in the Lisp machine. */ |
| 897 | Lisp_Object | 900 | Lisp_Object |
| 898 | make_ts_parser (Lisp_Object buffer, TSParser *parser, | 901 | make_treesit_parser (Lisp_Object buffer, TSParser *parser, |
| 899 | TSTree *tree, Lisp_Object language_symbol) | 902 | TSTree *tree, Lisp_Object language_symbol) |
| 900 | { | 903 | { |
| 901 | struct Lisp_TS_Parser *lisp_parser = | 904 | struct Lisp_TS_Parser *lisp_parser = |
| 902 | ALLOCATE_PSEUDOVECTOR (struct Lisp_TS_Parser, buffer, PVEC_TS_PARSER); | 905 | ALLOCATE_PSEUDOVECTOR (struct Lisp_TS_Parser, buffer, PVEC_TS_PARSER); |
| @@ -905,7 +908,7 @@ make_ts_parser (Lisp_Object buffer, TSParser *parser, | |||
| 905 | lisp_parser->buffer = buffer; | 908 | lisp_parser->buffer = buffer; |
| 906 | lisp_parser->parser = parser; | 909 | lisp_parser->parser = parser; |
| 907 | lisp_parser->tree = tree; | 910 | lisp_parser->tree = tree; |
| 908 | TSInput input = {lisp_parser, ts_read_buffer, TSInputEncodingUTF8}; | 911 | TSInput input = {lisp_parser, treesit_read_buffer, TSInputEncodingUTF8}; |
| 909 | lisp_parser->input = input; | 912 | lisp_parser->input = input; |
| 910 | lisp_parser->need_reparse = true; | 913 | lisp_parser->need_reparse = true; |
| 911 | lisp_parser->visible_beg = BUF_BEGV (XBUFFER (buffer)); | 914 | lisp_parser->visible_beg = BUF_BEGV (XBUFFER (buffer)); |
| @@ -918,7 +921,7 @@ make_ts_parser (Lisp_Object buffer, TSParser *parser, | |||
| 918 | 921 | ||
| 919 | /* Wrap the node in a Lisp_Object to be used in the Lisp machine. */ | 922 | /* Wrap the node in a Lisp_Object to be used in the Lisp machine. */ |
| 920 | Lisp_Object | 923 | Lisp_Object |
| 921 | make_ts_node (Lisp_Object parser, TSNode node) | 924 | make_treesit_node (Lisp_Object parser, TSNode node) |
| 922 | { | 925 | { |
| 923 | struct Lisp_TS_Node *lisp_node = | 926 | struct Lisp_TS_Node *lisp_node = |
| 924 | ALLOCATE_PSEUDOVECTOR (struct Lisp_TS_Node, parser, PVEC_TS_NODE); | 927 | ALLOCATE_PSEUDOVECTOR (struct Lisp_TS_Node, parser, PVEC_TS_NODE); |
| @@ -931,9 +934,9 @@ make_ts_node (Lisp_Object parser, TSNode node) | |||
| 931 | /* Make a compiled query. QUERY has to be either a cons or a | 934 | /* Make a compiled query. QUERY has to be either a cons or a |
| 932 | string. */ | 935 | string. */ |
| 933 | static Lisp_Object | 936 | static Lisp_Object |
| 934 | make_ts_query (Lisp_Object query, Lisp_Object language) | 937 | make_treesit_query (Lisp_Object query, Lisp_Object language) |
| 935 | { | 938 | { |
| 936 | TSQueryCursor *ts_cursor = ts_query_cursor_new (); | 939 | TSQueryCursor *treesit_cursor = ts_query_cursor_new (); |
| 937 | struct Lisp_TS_Query *lisp_query = | 940 | struct Lisp_TS_Query *lisp_query = |
| 938 | ALLOCATE_PSEUDOVECTOR (struct Lisp_TS_Query, source, | 941 | ALLOCATE_PSEUDOVECTOR (struct Lisp_TS_Query, source, |
| 939 | PVEC_TS_COMPILED_QUERY); | 942 | PVEC_TS_COMPILED_QUERY); |
| @@ -941,20 +944,20 @@ make_ts_query (Lisp_Object query, Lisp_Object language) | |||
| 941 | lisp_query->language = language; | 944 | lisp_query->language = language; |
| 942 | lisp_query->source = query; | 945 | lisp_query->source = query; |
| 943 | lisp_query->query = NULL; | 946 | lisp_query->query = NULL; |
| 944 | lisp_query->cursor = ts_cursor; | 947 | lisp_query->cursor = treesit_cursor; |
| 945 | return make_lisp_ptr (lisp_query, Lisp_Vectorlike); | 948 | return make_lisp_ptr (lisp_query, Lisp_Vectorlike); |
| 946 | } | 949 | } |
| 947 | 950 | ||
| 948 | /* The following two functions are called from alloc.c:cleanup_vector. */ | 951 | /* The following two functions are called from alloc.c:cleanup_vector. */ |
| 949 | void | 952 | void |
| 950 | ts_delete_parser (struct Lisp_TS_Parser *lisp_parser) | 953 | treesit_delete_parser (struct Lisp_TS_Parser *lisp_parser) |
| 951 | { | 954 | { |
| 952 | ts_tree_delete (lisp_parser->tree); | 955 | ts_tree_delete (lisp_parser->tree); |
| 953 | ts_parser_delete (lisp_parser->parser); | 956 | ts_parser_delete (lisp_parser->parser); |
| 954 | } | 957 | } |
| 955 | 958 | ||
| 956 | void | 959 | void |
| 957 | ts_delete_query (struct Lisp_TS_Query *lisp_query) | 960 | treesit_delete_query (struct Lisp_TS_Query *lisp_query) |
| 958 | { | 961 | { |
| 959 | ts_query_delete (lisp_query->query); | 962 | ts_query_delete (lisp_query->query); |
| 960 | ts_query_cursor_delete (lisp_query->cursor); | 963 | ts_query_cursor_delete (lisp_query->cursor); |
| @@ -962,13 +965,13 @@ ts_delete_query (struct Lisp_TS_Query *lisp_query) | |||
| 962 | 965 | ||
| 963 | /* The following function is called from print.c:print_vectorlike. */ | 966 | /* The following function is called from print.c:print_vectorlike. */ |
| 964 | bool | 967 | bool |
| 965 | ts_named_node_p (TSNode node) | 968 | treesit_named_node_p (TSNode node) |
| 966 | { | 969 | { |
| 967 | return ts_node_is_named (node); | 970 | return ts_node_is_named (node); |
| 968 | } | 971 | } |
| 969 | 972 | ||
| 970 | static const char* | 973 | static const char* |
| 971 | ts_query_error_to_string (TSQueryError error) | 974 | treesit_query_error_to_string (TSQueryError error) |
| 972 | { | 975 | { |
| 973 | switch (error) | 976 | switch (error) |
| 974 | { | 977 | { |
| @@ -990,11 +993,12 @@ ts_query_error_to_string (TSQueryError error) | |||
| 990 | } | 993 | } |
| 991 | 994 | ||
| 992 | static Lisp_Object | 995 | static Lisp_Object |
| 993 | ts_compose_query_signal_data (uint32_t error_offset, TSQueryError error_type) | 996 | treesit_compose_query_signal_data (uint32_t error_offset, |
| 997 | TSQueryError error_type) | ||
| 994 | { | 998 | { |
| 995 | return list3 (build_string (ts_query_error_to_string (error_type)), | 999 | return list3 (build_string (treesit_query_error_to_string (error_type)), |
| 996 | make_fixnum (error_offset + 1), | 1000 | make_fixnum (error_offset + 1), |
| 997 | build_pure_c_string("Debug the query with `treesit-query-validate'")); | 1001 | build_pure_c_string ("Debug the query with `treesit-query-validate'")); |
| 998 | } | 1002 | } |
| 999 | 1003 | ||
| 1000 | /* Ensure the QUERY is compiled. Return the TSQuery. It could be | 1004 | /* Ensure the QUERY is compiled. Return the TSQuery. It could be |
| @@ -1002,23 +1006,23 @@ ts_compose_query_signal_data (uint32_t error_offset, TSQueryError error_type) | |||
| 1002 | bound. If error occures, return NULL, and assign SIGNAL_SYMBOL and | 1006 | bound. If error occures, return NULL, and assign SIGNAL_SYMBOL and |
| 1003 | SIGNAL_DATA accordingly. */ | 1007 | SIGNAL_DATA accordingly. */ |
| 1004 | static TSQuery * | 1008 | static TSQuery * |
| 1005 | ts_ensure_query_compiled (Lisp_Object query, Lisp_Object *signal_symbol, | 1009 | treesit_ensure_query_compiled (Lisp_Object query, Lisp_Object *signal_symbol, |
| 1006 | Lisp_Object *signal_data) | 1010 | Lisp_Object *signal_data) |
| 1007 | { | 1011 | { |
| 1008 | /* If query is already compiled (not null), return that, otherwise | 1012 | /* If query is already compiled (not null), return that, otherwise |
| 1009 | compile and return it. */ | 1013 | compile and return it. */ |
| 1010 | TSQuery *ts_query = XTS_COMPILED_QUERY (query)->query; | 1014 | TSQuery *treesit_query = XTS_COMPILED_QUERY (query)->query; |
| 1011 | if (ts_query != NULL) | 1015 | if (treesit_query != NULL) |
| 1012 | return ts_query; | 1016 | return treesit_query; |
| 1013 | 1017 | ||
| 1014 | /* Get query source and TSLanguage ready. */ | 1018 | /* Get query source and TSLanguage ready. */ |
| 1015 | Lisp_Object source = XTS_COMPILED_QUERY (query)->source; | 1019 | Lisp_Object source = XTS_COMPILED_QUERY (query)->source; |
| 1016 | Lisp_Object language = XTS_COMPILED_QUERY (query)->language; | 1020 | Lisp_Object language = XTS_COMPILED_QUERY (query)->language; |
| 1017 | /* This is the main reason why we compile query lazily: to avoid | 1021 | /* This is the main reason why we compile query lazily: to avoid |
| 1018 | loading languages early. */ | 1022 | loading languages early. */ |
| 1019 | TSLanguage *ts_lang = ts_load_language (language, signal_symbol, | 1023 | TSLanguage *treesit_lang = treesit_load_language (language, signal_symbol, |
| 1020 | signal_data); | 1024 | signal_data); |
| 1021 | if (ts_lang == NULL) | 1025 | if (treesit_lang == NULL) |
| 1022 | return NULL; | 1026 | return NULL; |
| 1023 | 1027 | ||
| 1024 | if (CONSP (source)) | 1028 | if (CONSP (source)) |
| @@ -1027,17 +1031,18 @@ ts_ensure_query_compiled (Lisp_Object query, Lisp_Object *signal_symbol, | |||
| 1027 | /* Create TSQuery. */ | 1031 | /* Create TSQuery. */ |
| 1028 | uint32_t error_offset; | 1032 | uint32_t error_offset; |
| 1029 | TSQueryError error_type; | 1033 | TSQueryError error_type; |
| 1030 | char *ts_source = SSDATA (source); | 1034 | char *treesit_source = SSDATA (source); |
| 1031 | ts_query = ts_query_new (ts_lang, ts_source, strlen (ts_source), | 1035 | treesit_query = ts_query_new (treesit_lang, treesit_source, |
| 1032 | &error_offset, &error_type); | 1036 | strlen (treesit_source), |
| 1033 | if (ts_query == NULL) | 1037 | &error_offset, &error_type); |
| 1038 | if (treesit_query == NULL) | ||
| 1034 | { | 1039 | { |
| 1035 | *signal_symbol = Qtreesit_query_error; | 1040 | *signal_symbol = Qtreesit_query_error; |
| 1036 | *signal_data = ts_compose_query_signal_data | 1041 | *signal_data = treesit_compose_query_signal_data (error_offset, |
| 1037 | (error_offset, error_type); | 1042 | error_type); |
| 1038 | } | 1043 | } |
| 1039 | XTS_COMPILED_QUERY (query)->query = ts_query; | 1044 | XTS_COMPILED_QUERY (query)->query = treesit_query; |
| 1040 | return ts_query; | 1045 | return treesit_query; |
| 1041 | } | 1046 | } |
| 1042 | 1047 | ||
| 1043 | DEFUN ("treesit-parser-p", | 1048 | DEFUN ("treesit-parser-p", |
| @@ -1092,7 +1097,7 @@ QUERY has to be a compiled query. */) | |||
| 1092 | (Lisp_Object query) | 1097 | (Lisp_Object query) |
| 1093 | { | 1098 | { |
| 1094 | CHECK_TS_COMPILED_QUERY (query); | 1099 | CHECK_TS_COMPILED_QUERY (query); |
| 1095 | return XTS_COMPILED_QUERY(query)->language; | 1100 | return XTS_COMPILED_QUERY (query)->language; |
| 1096 | } | 1101 | } |
| 1097 | 1102 | ||
| 1098 | DEFUN ("treesit-node-parser", | 1103 | DEFUN ("treesit-node-parser", |
| @@ -1118,7 +1123,7 @@ LANGUAGE, return that parser, but if NO-REUSE is non-nil, always | |||
| 1118 | create a new parser. */) | 1123 | create a new parser. */) |
| 1119 | (Lisp_Object language, Lisp_Object buffer, Lisp_Object no_reuse) | 1124 | (Lisp_Object language, Lisp_Object buffer, Lisp_Object no_reuse) |
| 1120 | { | 1125 | { |
| 1121 | ts_initialize (); | 1126 | treesit_initialize (); |
| 1122 | 1127 | ||
| 1123 | CHECK_SYMBOL (language); | 1128 | CHECK_SYMBOL (language); |
| 1124 | struct buffer *buf; | 1129 | struct buffer *buf; |
| @@ -1129,7 +1134,7 @@ create a new parser. */) | |||
| 1129 | CHECK_BUFFER (buffer); | 1134 | CHECK_BUFFER (buffer); |
| 1130 | buf = XBUFFER (buffer); | 1135 | buf = XBUFFER (buffer); |
| 1131 | } | 1136 | } |
| 1132 | ts_check_buffer_size (buf); | 1137 | treesit_check_buffer_size (buf); |
| 1133 | 1138 | ||
| 1134 | /* See if we can reuse a parser. */ | 1139 | /* See if we can reuse a parser. */ |
| 1135 | for (Lisp_Object tail = BVAR (buf, ts_parser_list); | 1140 | for (Lisp_Object tail = BVAR (buf, ts_parser_list); |
| @@ -1145,8 +1150,8 @@ create a new parser. */) | |||
| 1145 | Lisp_Object signal_symbol = Qnil; | 1150 | Lisp_Object signal_symbol = Qnil; |
| 1146 | Lisp_Object signal_data = Qnil; | 1151 | Lisp_Object signal_data = Qnil; |
| 1147 | TSParser *parser = ts_parser_new (); | 1152 | TSParser *parser = ts_parser_new (); |
| 1148 | TSLanguage *lang = ts_load_language (language, &signal_symbol, | 1153 | TSLanguage *lang = treesit_load_language (language, &signal_symbol, |
| 1149 | &signal_data); | 1154 | &signal_data); |
| 1150 | if (lang == NULL) | 1155 | if (lang == NULL) |
| 1151 | xsignal (signal_symbol, signal_data); | 1156 | xsignal (signal_symbol, signal_data); |
| 1152 | /* We check language version when loading a language, so this should | 1157 | /* We check language version when loading a language, so this should |
| @@ -1155,7 +1160,7 @@ create a new parser. */) | |||
| 1155 | 1160 | ||
| 1156 | /* Create parser. */ | 1161 | /* Create parser. */ |
| 1157 | Lisp_Object lisp_parser | 1162 | Lisp_Object lisp_parser |
| 1158 | = make_ts_parser (Fcurrent_buffer (), parser, NULL, language); | 1163 | = make_treesit_parser (Fcurrent_buffer (), parser, NULL, language); |
| 1159 | 1164 | ||
| 1160 | /* Update parser-list. */ | 1165 | /* Update parser-list. */ |
| 1161 | BVAR (buf, ts_parser_list) = Fcons (lisp_parser, BVAR (buf, ts_parser_list)); | 1166 | BVAR (buf, ts_parser_list) = Fcons (lisp_parser, BVAR (buf, ts_parser_list)); |
| @@ -1170,7 +1175,7 @@ DEFUN ("treesit-parser-delete", | |||
| 1170 | See `treesit-parser-list' for the buffer's parser list. */) | 1175 | See `treesit-parser-list' for the buffer's parser list. */) |
| 1171 | (Lisp_Object parser) | 1176 | (Lisp_Object parser) |
| 1172 | { | 1177 | { |
| 1173 | ts_check_parser (parser); | 1178 | treesit_check_parser (parser); |
| 1174 | 1179 | ||
| 1175 | Lisp_Object buffer = XTS_PARSER (parser)->buffer; | 1180 | Lisp_Object buffer = XTS_PARSER (parser)->buffer; |
| 1176 | struct buffer *buf = XBUFFER (buffer); | 1181 | struct buffer *buf = XBUFFER (buffer); |
| @@ -1213,7 +1218,7 @@ DEFUN ("treesit-parser-buffer", | |||
| 1213 | doc: /* Return the buffer of PARSER. */) | 1218 | doc: /* Return the buffer of PARSER. */) |
| 1214 | (Lisp_Object parser) | 1219 | (Lisp_Object parser) |
| 1215 | { | 1220 | { |
| 1216 | ts_check_parser (parser); | 1221 | treesit_check_parser (parser); |
| 1217 | Lisp_Object buf; | 1222 | Lisp_Object buf; |
| 1218 | XSETBUFFER (buf, XBUFFER (XTS_PARSER (parser)->buffer)); | 1223 | XSETBUFFER (buf, XBUFFER (XTS_PARSER (parser)->buffer)); |
| 1219 | return buf; | 1224 | return buf; |
| @@ -1226,7 +1231,7 @@ DEFUN ("treesit-parser-language", | |||
| 1226 | This symbol is the one used to create the parser. */) | 1231 | This symbol is the one used to create the parser. */) |
| 1227 | (Lisp_Object parser) | 1232 | (Lisp_Object parser) |
| 1228 | { | 1233 | { |
| 1229 | ts_check_parser (parser); | 1234 | treesit_check_parser (parser); |
| 1230 | return XTS_PARSER (parser)->language_symbol; | 1235 | return XTS_PARSER (parser)->language_symbol; |
| 1231 | } | 1236 | } |
| 1232 | 1237 | ||
| @@ -1238,17 +1243,17 @@ DEFUN ("treesit-parser-root-node", | |||
| 1238 | doc: /* Return the root node of PARSER. */) | 1243 | doc: /* Return the root node of PARSER. */) |
| 1239 | (Lisp_Object parser) | 1244 | (Lisp_Object parser) |
| 1240 | { | 1245 | { |
| 1241 | ts_check_parser (parser); | 1246 | treesit_check_parser (parser); |
| 1242 | ts_initialize (); | 1247 | treesit_initialize (); |
| 1243 | ts_ensure_parsed (parser); | 1248 | treesit_ensure_parsed (parser); |
| 1244 | TSNode root_node = ts_tree_root_node (XTS_PARSER (parser)->tree); | 1249 | TSNode root_node = ts_tree_root_node (XTS_PARSER (parser)->tree); |
| 1245 | return make_ts_node (parser, root_node); | 1250 | return make_treesit_node (parser, root_node); |
| 1246 | } | 1251 | } |
| 1247 | 1252 | ||
| 1248 | /* Checks that the RANGES argument of | 1253 | /* Checks that the RANGES argument of |
| 1249 | treesit-parser-set-included-ranges is valid. */ | 1254 | treesit-parser-set-included-ranges is valid. */ |
| 1250 | static void | 1255 | static void |
| 1251 | ts_check_range_argument (Lisp_Object ranges) | 1256 | treesit_check_range_argument (Lisp_Object ranges) |
| 1252 | { | 1257 | { |
| 1253 | struct buffer *buffer = current_buffer; | 1258 | struct buffer *buffer = current_buffer; |
| 1254 | ptrdiff_t point_min = BUF_BEGV (buffer); | 1259 | ptrdiff_t point_min = BUF_BEGV (buffer); |
| @@ -1285,13 +1290,13 @@ if the argument is invalid, or something else went wrong. If RANGES | |||
| 1285 | is nil, the PARSER is to parse the whole buffer. */) | 1290 | is nil, the PARSER is to parse the whole buffer. */) |
| 1286 | (Lisp_Object parser, Lisp_Object ranges) | 1291 | (Lisp_Object parser, Lisp_Object ranges) |
| 1287 | { | 1292 | { |
| 1288 | ts_check_parser (parser); | 1293 | treesit_check_parser (parser); |
| 1289 | CHECK_CONS (ranges); | 1294 | CHECK_CONS (ranges); |
| 1290 | ts_check_range_argument (ranges); | 1295 | treesit_check_range_argument (ranges); |
| 1291 | 1296 | ||
| 1292 | ts_initialize (); | 1297 | treesit_initialize (); |
| 1293 | /* Before we parse, catch up with narrowing/widening. */ | 1298 | /* Before we parse, catch up with narrowing/widening. */ |
| 1294 | ts_ensure_position_synced (parser); | 1299 | treesit_ensure_position_synced (parser); |
| 1295 | 1300 | ||
| 1296 | bool success; | 1301 | bool success; |
| 1297 | if (NILP (ranges)) | 1302 | if (NILP (ranges)) |
| @@ -1299,16 +1304,16 @@ is nil, the PARSER is to parse the whole buffer. */) | |||
| 1299 | /* If RANGES is nil, make parser to parse the whole document. | 1304 | /* If RANGES is nil, make parser to parse the whole document. |
| 1300 | To do that we give tree-sitter a 0 length, the range is a | 1305 | To do that we give tree-sitter a 0 length, the range is a |
| 1301 | dummy. */ | 1306 | dummy. */ |
| 1302 | TSRange ts_range = {{0, 0}, {0, 0}, 0, 0}; | 1307 | TSRange treesit_range = {{0, 0}, {0, 0}, 0, 0}; |
| 1303 | success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser, | 1308 | success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser, |
| 1304 | &ts_range , 0); | 1309 | &treesit_range , 0); |
| 1305 | } | 1310 | } |
| 1306 | else | 1311 | else |
| 1307 | { | 1312 | { |
| 1308 | /* Set ranges for PARSER. */ | 1313 | /* Set ranges for PARSER. */ |
| 1309 | ptrdiff_t len = list_length (ranges); | 1314 | ptrdiff_t len = list_length (ranges); |
| 1310 | /* FIXME: We should test the return value of malloc below. */ | 1315 | /* FIXME: We should test the return value of malloc below. */ |
| 1311 | TSRange *ts_ranges = malloc (sizeof(TSRange) * len); | 1316 | TSRange *treesit_ranges = malloc (sizeof(TSRange) * len); |
| 1312 | struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); | 1317 | struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); |
| 1313 | 1318 | ||
| 1314 | for (int idx = 0; !NILP (ranges); idx++, ranges = XCDR (ranges)) | 1319 | for (int idx = 0; !NILP (ranges); idx++, ranges = XCDR (ranges)) |
| @@ -1323,16 +1328,16 @@ is nil, the PARSER is to parse the whole buffer. */) | |||
| 1323 | TSRange rg = {{0,0}, {0,0}, | 1328 | TSRange rg = {{0,0}, {0,0}, |
| 1324 | (uint32_t) beg_byte - BUF_BEGV_BYTE (buffer), | 1329 | (uint32_t) beg_byte - BUF_BEGV_BYTE (buffer), |
| 1325 | (uint32_t) end_byte - BUF_BEGV_BYTE (buffer)}; | 1330 | (uint32_t) end_byte - BUF_BEGV_BYTE (buffer)}; |
| 1326 | ts_ranges[idx] = rg; | 1331 | treesit_ranges[idx] = rg; |
| 1327 | } | 1332 | } |
| 1328 | /* FIXME: 'len' below is ptrdiff_t, so can overflow a 32-bit | 1333 | /* FIXME: 'len' below is ptrdiff_t, so can overflow a 32-bit |
| 1329 | unsigned data type. */ | 1334 | unsigned data type. */ |
| 1330 | success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser, | 1335 | success = ts_parser_set_included_ranges (XTS_PARSER (parser)->parser, |
| 1331 | ts_ranges, (uint32_t) len); | 1336 | treesit_ranges, (uint32_t) len); |
| 1332 | /* Although XFIXNUM could signal, it should be impossible | 1337 | /* Although XFIXNUM could signal, it should be impossible |
| 1333 | because we have checked the input by ts_check_range_argument. | 1338 | because we have checked the input by treesit_check_range_argument. |
| 1334 | So there is no need for unwind-protect. */ | 1339 | So there is no need for unwind-protect. */ |
| 1335 | free (ts_ranges); | 1340 | free (treesit_ranges); |
| 1336 | } | 1341 | } |
| 1337 | 1342 | ||
| 1338 | if (!success) | 1343 | if (!success) |
| @@ -1353,8 +1358,8 @@ See `treesit-parser-set-ranges'. If no ranges are set for PARSER, | |||
| 1353 | return nil. */) | 1358 | return nil. */) |
| 1354 | (Lisp_Object parser) | 1359 | (Lisp_Object parser) |
| 1355 | { | 1360 | { |
| 1356 | ts_check_parser (parser); | 1361 | treesit_check_parser (parser); |
| 1357 | ts_initialize (); | 1362 | treesit_initialize (); |
| 1358 | uint32_t len; | 1363 | uint32_t len; |
| 1359 | const TSRange *ranges = | 1364 | const TSRange *ranges = |
| 1360 | ts_parser_included_ranges (XTS_PARSER (parser)->parser, &len); | 1365 | ts_parser_included_ranges (XTS_PARSER (parser)->parser, &len); |
| @@ -1363,7 +1368,7 @@ return nil. */) | |||
| 1363 | 1368 | ||
| 1364 | /* Our return value depends on the buffer state (BUF_BEGV_BYTE, | 1369 | /* Our return value depends on the buffer state (BUF_BEGV_BYTE, |
| 1365 | etc), so we need to sync up. */ | 1370 | etc), so we need to sync up. */ |
| 1366 | ts_ensure_position_synced (parser); | 1371 | treesit_ensure_position_synced (parser); |
| 1367 | 1372 | ||
| 1368 | struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); | 1373 | struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); |
| 1369 | 1374 | ||
| @@ -1390,7 +1395,7 @@ return nil. */) | |||
| 1390 | /* Check that OBJ is a positive integer and signal an error if | 1395 | /* Check that OBJ is a positive integer and signal an error if |
| 1391 | otherwise. */ | 1396 | otherwise. */ |
| 1392 | static void | 1397 | static void |
| 1393 | ts_check_positive_integer (Lisp_Object obj) | 1398 | treesit_check_positive_integer (Lisp_Object obj) |
| 1394 | { | 1399 | { |
| 1395 | CHECK_INTEGER (obj); | 1400 | CHECK_INTEGER (obj); |
| 1396 | if (XFIXNUM (obj) < 0) | 1401 | if (XFIXNUM (obj) < 0) |
| @@ -1398,7 +1403,7 @@ ts_check_positive_integer (Lisp_Object obj) | |||
| 1398 | } | 1403 | } |
| 1399 | 1404 | ||
| 1400 | static void | 1405 | static void |
| 1401 | ts_check_node (Lisp_Object obj) | 1406 | treesit_check_node (Lisp_Object obj) |
| 1402 | { | 1407 | { |
| 1403 | CHECK_TS_NODE (obj); | 1408 | CHECK_TS_NODE (obj); |
| 1404 | Lisp_Object lisp_parser = XTS_NODE (obj)->parser; | 1409 | Lisp_Object lisp_parser = XTS_NODE (obj)->parser; |
| @@ -1413,11 +1418,11 @@ If NODE is nil, return nil. */) | |||
| 1413 | (Lisp_Object node) | 1418 | (Lisp_Object node) |
| 1414 | { | 1419 | { |
| 1415 | if (NILP (node)) return Qnil; | 1420 | if (NILP (node)) return Qnil; |
| 1416 | ts_check_node (node); | 1421 | treesit_check_node (node); |
| 1417 | ts_initialize (); | 1422 | treesit_initialize (); |
| 1418 | 1423 | ||
| 1419 | TSNode ts_node = XTS_NODE (node)->node; | 1424 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1420 | const char *type = ts_node_type (ts_node); | 1425 | const char *type = ts_node_type (treesit_node); |
| 1421 | return build_string (type); | 1426 | return build_string (type); |
| 1422 | } | 1427 | } |
| 1423 | 1428 | ||
| @@ -1428,12 +1433,12 @@ If NODE is nil, return nil. */) | |||
| 1428 | (Lisp_Object node) | 1433 | (Lisp_Object node) |
| 1429 | { | 1434 | { |
| 1430 | if (NILP (node)) return Qnil; | 1435 | if (NILP (node)) return Qnil; |
| 1431 | ts_check_node (node); | 1436 | treesit_check_node (node); |
| 1432 | ts_initialize (); | 1437 | treesit_initialize (); |
| 1433 | 1438 | ||
| 1434 | TSNode ts_node = XTS_NODE (node)->node; | 1439 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1435 | ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg; | 1440 | ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg; |
| 1436 | uint32_t start_byte_offset = ts_node_start_byte (ts_node); | 1441 | uint32_t start_byte_offset = ts_node_start_byte (treesit_node); |
| 1437 | struct buffer *buffer = | 1442 | struct buffer *buffer = |
| 1438 | XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer); | 1443 | XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer); |
| 1439 | ptrdiff_t start_pos = | 1444 | ptrdiff_t start_pos = |
| @@ -1448,12 +1453,12 @@ If NODE is nil, return nil. */) | |||
| 1448 | (Lisp_Object node) | 1453 | (Lisp_Object node) |
| 1449 | { | 1454 | { |
| 1450 | if (NILP (node)) return Qnil; | 1455 | if (NILP (node)) return Qnil; |
| 1451 | ts_check_node (node); | 1456 | treesit_check_node (node); |
| 1452 | ts_initialize (); | 1457 | treesit_initialize (); |
| 1453 | 1458 | ||
| 1454 | TSNode ts_node = XTS_NODE (node)->node; | 1459 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1455 | ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg; | 1460 | ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg; |
| 1456 | uint32_t end_byte_offset = ts_node_end_byte (ts_node); | 1461 | uint32_t end_byte_offset = ts_node_end_byte (treesit_node); |
| 1457 | struct buffer *buffer = | 1462 | struct buffer *buffer = |
| 1458 | XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer); | 1463 | XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer); |
| 1459 | ptrdiff_t end_pos = | 1464 | ptrdiff_t end_pos = |
| @@ -1468,11 +1473,11 @@ If NODE is nil, return nil. */) | |||
| 1468 | (Lisp_Object node) | 1473 | (Lisp_Object node) |
| 1469 | { | 1474 | { |
| 1470 | if (NILP (node)) return Qnil; | 1475 | if (NILP (node)) return Qnil; |
| 1471 | ts_check_node (node); | 1476 | treesit_check_node (node); |
| 1472 | ts_initialize (); | 1477 | treesit_initialize (); |
| 1473 | 1478 | ||
| 1474 | TSNode ts_node = XTS_NODE (node)->node; | 1479 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1475 | char *string = ts_node_string (ts_node); | 1480 | char *string = ts_node_string (treesit_node); |
| 1476 | return build_string (string); | 1481 | return build_string (string); |
| 1477 | } | 1482 | } |
| 1478 | 1483 | ||
| @@ -1483,16 +1488,16 @@ Return nil if NODE has no parent. If NODE is nil, return nil. */) | |||
| 1483 | (Lisp_Object node) | 1488 | (Lisp_Object node) |
| 1484 | { | 1489 | { |
| 1485 | if (NILP (node)) return Qnil; | 1490 | if (NILP (node)) return Qnil; |
| 1486 | ts_check_node (node); | 1491 | treesit_check_node (node); |
| 1487 | ts_initialize (); | 1492 | treesit_initialize (); |
| 1488 | 1493 | ||
| 1489 | TSNode ts_node = XTS_NODE (node)->node; | 1494 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1490 | TSNode parent = ts_node_parent (ts_node); | 1495 | TSNode parent = ts_node_parent (treesit_node); |
| 1491 | 1496 | ||
| 1492 | if (ts_node_is_null (parent)) | 1497 | if (ts_node_is_null (parent)) |
| 1493 | return Qnil; | 1498 | return Qnil; |
| 1494 | 1499 | ||
| 1495 | return make_ts_node (XTS_NODE (node)->parser, parent); | 1500 | return make_treesit_node (XTS_NODE (node)->parser, parent); |
| 1496 | } | 1501 | } |
| 1497 | 1502 | ||
| 1498 | DEFUN ("treesit-node-child", | 1503 | DEFUN ("treesit-node-child", |
| @@ -1504,24 +1509,24 @@ child only. NAMED defaults to nil. If NODE is nil, return nil. */) | |||
| 1504 | (Lisp_Object node, Lisp_Object n, Lisp_Object named) | 1509 | (Lisp_Object node, Lisp_Object n, Lisp_Object named) |
| 1505 | { | 1510 | { |
| 1506 | if (NILP (node)) return Qnil; | 1511 | if (NILP (node)) return Qnil; |
| 1507 | ts_check_node (node); | 1512 | treesit_check_node (node); |
| 1508 | ts_check_positive_integer (n); | 1513 | treesit_check_positive_integer (n); |
| 1509 | EMACS_INT idx = XFIXNUM (n); | 1514 | EMACS_INT idx = XFIXNUM (n); |
| 1510 | if (idx > UINT32_MAX) | 1515 | if (idx > UINT32_MAX) |
| 1511 | xsignal1 (Qargs_out_of_range, n); | 1516 | xsignal1 (Qargs_out_of_range, n); |
| 1512 | ts_initialize (); | 1517 | treesit_initialize (); |
| 1513 | 1518 | ||
| 1514 | TSNode ts_node = XTS_NODE (node)->node; | 1519 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1515 | TSNode child; | 1520 | TSNode child; |
| 1516 | if (NILP (named)) | 1521 | if (NILP (named)) |
| 1517 | child = ts_node_child (ts_node, (uint32_t) idx); | 1522 | child = ts_node_child (treesit_node, (uint32_t) idx); |
| 1518 | else | 1523 | else |
| 1519 | child = ts_node_named_child (ts_node, (uint32_t) idx); | 1524 | child = ts_node_named_child (treesit_node, (uint32_t) idx); |
| 1520 | 1525 | ||
| 1521 | if (ts_node_is_null (child)) | 1526 | if (ts_node_is_null (child)) |
| 1522 | return Qnil; | 1527 | return Qnil; |
| 1523 | 1528 | ||
| 1524 | return make_ts_node (XTS_NODE (node)->parser, child); | 1529 | return make_treesit_node (XTS_NODE (node)->parser, child); |
| 1525 | } | 1530 | } |
| 1526 | 1531 | ||
| 1527 | DEFUN ("treesit-node-check", | 1532 | DEFUN ("treesit-node-check", |
| @@ -1548,22 +1553,22 @@ errors. */) | |||
| 1548 | (Lisp_Object node, Lisp_Object property) | 1553 | (Lisp_Object node, Lisp_Object property) |
| 1549 | { | 1554 | { |
| 1550 | if (NILP (node)) return Qnil; | 1555 | if (NILP (node)) return Qnil; |
| 1551 | ts_check_node (node); | 1556 | treesit_check_node (node); |
| 1552 | CHECK_SYMBOL (property); | 1557 | CHECK_SYMBOL (property); |
| 1553 | ts_initialize (); | 1558 | treesit_initialize (); |
| 1554 | 1559 | ||
| 1555 | TSNode ts_node = XTS_NODE (node)->node; | 1560 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1556 | bool result; | 1561 | bool result; |
| 1557 | if (EQ (property, Qnamed)) | 1562 | if (EQ (property, Qnamed)) |
| 1558 | result = ts_node_is_named (ts_node); | 1563 | result = ts_node_is_named (treesit_node); |
| 1559 | else if (EQ (property, Qmissing)) | 1564 | else if (EQ (property, Qmissing)) |
| 1560 | result = ts_node_is_missing (ts_node); | 1565 | result = ts_node_is_missing (treesit_node); |
| 1561 | else if (EQ (property, Qextra)) | 1566 | else if (EQ (property, Qextra)) |
| 1562 | result = ts_node_is_extra (ts_node); | 1567 | result = ts_node_is_extra (treesit_node); |
| 1563 | else if (EQ (property, Qhas_error)) | 1568 | else if (EQ (property, Qhas_error)) |
| 1564 | result = ts_node_has_error (ts_node); | 1569 | result = ts_node_has_error (treesit_node); |
| 1565 | else if (EQ (property, Qhas_changes)) | 1570 | else if (EQ (property, Qhas_changes)) |
| 1566 | result = ts_node_has_changes (ts_node); | 1571 | result = ts_node_has_changes (treesit_node); |
| 1567 | else | 1572 | else |
| 1568 | signal_error ("Expecting `named', `missing', `extra', `has-changes' or `has-error', but got", | 1573 | signal_error ("Expecting `named', `missing', `extra', `has-changes' or `has-error', but got", |
| 1569 | property); | 1574 | property); |
| @@ -1581,16 +1586,16 @@ If NODE is nil, return nil. */) | |||
| 1581 | { | 1586 | { |
| 1582 | if (NILP (node)) | 1587 | if (NILP (node)) |
| 1583 | return Qnil; | 1588 | return Qnil; |
| 1584 | ts_check_node (node); | 1589 | treesit_check_node (node); |
| 1585 | ts_check_positive_integer (n); | 1590 | treesit_check_positive_integer (n); |
| 1586 | EMACS_INT idx = XFIXNUM (n); | 1591 | EMACS_INT idx = XFIXNUM (n); |
| 1587 | if (idx > UINT32_MAX) | 1592 | if (idx > UINT32_MAX) |
| 1588 | xsignal1 (Qargs_out_of_range, n); | 1593 | xsignal1 (Qargs_out_of_range, n); |
| 1589 | ts_initialize (); | 1594 | treesit_initialize (); |
| 1590 | 1595 | ||
| 1591 | TSNode ts_node = XTS_NODE (node)->node; | 1596 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1592 | const char *name | 1597 | const char *name |
| 1593 | = ts_node_field_name_for_child (ts_node, (uint32_t) idx); | 1598 | = ts_node_field_name_for_child (treesit_node, (uint32_t) idx); |
| 1594 | 1599 | ||
| 1595 | if (name == NULL) | 1600 | if (name == NULL) |
| 1596 | return Qnil; | 1601 | return Qnil; |
| @@ -1609,15 +1614,15 @@ nil. If NODE is nil, return nil. */) | |||
| 1609 | { | 1614 | { |
| 1610 | if (NILP (node)) | 1615 | if (NILP (node)) |
| 1611 | return Qnil; | 1616 | return Qnil; |
| 1612 | ts_check_node (node); | 1617 | treesit_check_node (node); |
| 1613 | ts_initialize (); | 1618 | treesit_initialize (); |
| 1614 | 1619 | ||
| 1615 | TSNode ts_node = XTS_NODE (node)->node; | 1620 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1616 | uint32_t count; | 1621 | uint32_t count; |
| 1617 | if (NILP (named)) | 1622 | if (NILP (named)) |
| 1618 | count = ts_node_child_count (ts_node); | 1623 | count = ts_node_child_count (treesit_node); |
| 1619 | else | 1624 | else |
| 1620 | count = ts_node_named_child_count (ts_node); | 1625 | count = ts_node_named_child_count (treesit_node); |
| 1621 | return make_fixnum (count); | 1626 | return make_fixnum (count); |
| 1622 | } | 1627 | } |
| 1623 | 1628 | ||
| @@ -1630,19 +1635,19 @@ Return nil if there is no such child. If NODE is nil, return nil. */) | |||
| 1630 | { | 1635 | { |
| 1631 | if (NILP (node)) | 1636 | if (NILP (node)) |
| 1632 | return Qnil; | 1637 | return Qnil; |
| 1633 | ts_check_node (node); | 1638 | treesit_check_node (node); |
| 1634 | CHECK_STRING (field_name); | 1639 | CHECK_STRING (field_name); |
| 1635 | ts_initialize (); | 1640 | treesit_initialize (); |
| 1636 | 1641 | ||
| 1637 | char *name_str = SSDATA (field_name); | 1642 | char *name_str = SSDATA (field_name); |
| 1638 | TSNode ts_node = XTS_NODE (node)->node; | 1643 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1639 | TSNode child | 1644 | TSNode child |
| 1640 | = ts_node_child_by_field_name (ts_node, name_str, strlen (name_str)); | 1645 | = ts_node_child_by_field_name (treesit_node, name_str, strlen (name_str)); |
| 1641 | 1646 | ||
| 1642 | if (ts_node_is_null (child)) | 1647 | if (ts_node_is_null (child)) |
| 1643 | return Qnil; | 1648 | return Qnil; |
| 1644 | 1649 | ||
| 1645 | return make_ts_node(XTS_NODE (node)->parser, child); | 1650 | return make_treesit_node (XTS_NODE (node)->parser, child); |
| 1646 | } | 1651 | } |
| 1647 | 1652 | ||
| 1648 | DEFUN ("treesit-node-next-sibling", | 1653 | DEFUN ("treesit-node-next-sibling", |
| @@ -1655,20 +1660,20 @@ siblings only. NAMED defaults to nil. If NODE is nil, return nil. */) | |||
| 1655 | (Lisp_Object node, Lisp_Object named) | 1660 | (Lisp_Object node, Lisp_Object named) |
| 1656 | { | 1661 | { |
| 1657 | if (NILP (node)) return Qnil; | 1662 | if (NILP (node)) return Qnil; |
| 1658 | ts_check_node (node); | 1663 | treesit_check_node (node); |
| 1659 | ts_initialize (); | 1664 | treesit_initialize (); |
| 1660 | 1665 | ||
| 1661 | TSNode ts_node = XTS_NODE (node)->node; | 1666 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1662 | TSNode sibling; | 1667 | TSNode sibling; |
| 1663 | if (NILP (named)) | 1668 | if (NILP (named)) |
| 1664 | sibling = ts_node_next_sibling (ts_node); | 1669 | sibling = ts_node_next_sibling (treesit_node); |
| 1665 | else | 1670 | else |
| 1666 | sibling = ts_node_next_named_sibling (ts_node); | 1671 | sibling = ts_node_next_named_sibling (treesit_node); |
| 1667 | 1672 | ||
| 1668 | if (ts_node_is_null(sibling)) | 1673 | if (ts_node_is_null (sibling)) |
| 1669 | return Qnil; | 1674 | return Qnil; |
| 1670 | 1675 | ||
| 1671 | return make_ts_node(XTS_NODE (node)->parser, sibling); | 1676 | return make_treesit_node (XTS_NODE (node)->parser, sibling); |
| 1672 | } | 1677 | } |
| 1673 | 1678 | ||
| 1674 | DEFUN ("treesit-node-prev-sibling", | 1679 | DEFUN ("treesit-node-prev-sibling", |
| @@ -1682,21 +1687,21 @@ return nil. */) | |||
| 1682 | (Lisp_Object node, Lisp_Object named) | 1687 | (Lisp_Object node, Lisp_Object named) |
| 1683 | { | 1688 | { |
| 1684 | if (NILP (node)) return Qnil; | 1689 | if (NILP (node)) return Qnil; |
| 1685 | ts_check_node (node); | 1690 | treesit_check_node (node); |
| 1686 | ts_initialize (); | 1691 | treesit_initialize (); |
| 1687 | 1692 | ||
| 1688 | TSNode ts_node = XTS_NODE (node)->node; | 1693 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1689 | TSNode sibling; | 1694 | TSNode sibling; |
| 1690 | 1695 | ||
| 1691 | if (NILP (named)) | 1696 | if (NILP (named)) |
| 1692 | sibling = ts_node_prev_sibling (ts_node); | 1697 | sibling = ts_node_prev_sibling (treesit_node); |
| 1693 | else | 1698 | else |
| 1694 | sibling = ts_node_prev_named_sibling (ts_node); | 1699 | sibling = ts_node_prev_named_sibling (treesit_node); |
| 1695 | 1700 | ||
| 1696 | if (ts_node_is_null(sibling)) | 1701 | if (ts_node_is_null (sibling)) |
| 1697 | return Qnil; | 1702 | return Qnil; |
| 1698 | 1703 | ||
| 1699 | return make_ts_node(XTS_NODE (node)->parser, sibling); | 1704 | return make_treesit_node (XTS_NODE (node)->parser, sibling); |
| 1700 | } | 1705 | } |
| 1701 | 1706 | ||
| 1702 | DEFUN ("treesit-node-first-child-for-pos", | 1707 | DEFUN ("treesit-node-first-child-for-pos", |
| @@ -1713,8 +1718,8 @@ Note that this function returns an immediate child, not the smallest | |||
| 1713 | { | 1718 | { |
| 1714 | if (NILP (node)) | 1719 | if (NILP (node)) |
| 1715 | return Qnil; | 1720 | return Qnil; |
| 1716 | ts_check_node (node); | 1721 | treesit_check_node (node); |
| 1717 | ts_check_positive_integer (pos); | 1722 | treesit_check_positive_integer (pos); |
| 1718 | 1723 | ||
| 1719 | struct buffer *buf = XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer); | 1724 | struct buffer *buf = XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer); |
| 1720 | ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg; | 1725 | ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg; |
| @@ -1723,20 +1728,20 @@ Note that this function returns an immediate child, not the smallest | |||
| 1723 | if (byte_pos < BUF_BEGV_BYTE (buf) || byte_pos > BUF_ZV_BYTE (buf)) | 1728 | if (byte_pos < BUF_BEGV_BYTE (buf) || byte_pos > BUF_ZV_BYTE (buf)) |
| 1724 | xsignal1 (Qargs_out_of_range, pos); | 1729 | xsignal1 (Qargs_out_of_range, pos); |
| 1725 | 1730 | ||
| 1726 | ts_initialize (); | 1731 | treesit_initialize (); |
| 1727 | 1732 | ||
| 1728 | TSNode ts_node = XTS_NODE (node)->node; | 1733 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1729 | TSNode child; | 1734 | TSNode child; |
| 1730 | if (NILP (named)) | 1735 | if (NILP (named)) |
| 1731 | child = ts_node_first_child_for_byte (ts_node, byte_pos - visible_beg); | 1736 | child = ts_node_first_child_for_byte (treesit_node, byte_pos - visible_beg); |
| 1732 | else | 1737 | else |
| 1733 | child = ts_node_first_named_child_for_byte (ts_node, | 1738 | child = ts_node_first_named_child_for_byte (treesit_node, |
| 1734 | byte_pos - visible_beg); | 1739 | byte_pos - visible_beg); |
| 1735 | 1740 | ||
| 1736 | if (ts_node_is_null (child)) | 1741 | if (ts_node_is_null (child)) |
| 1737 | return Qnil; | 1742 | return Qnil; |
| 1738 | 1743 | ||
| 1739 | return make_ts_node (XTS_NODE (node)->parser, child); | 1744 | return make_treesit_node (XTS_NODE (node)->parser, child); |
| 1740 | } | 1745 | } |
| 1741 | 1746 | ||
| 1742 | DEFUN ("treesit-node-descendant-for-range", | 1747 | DEFUN ("treesit-node-descendant-for-range", |
| @@ -1751,7 +1756,7 @@ If NODE is nil, return nil. */) | |||
| 1751 | (Lisp_Object node, Lisp_Object beg, Lisp_Object end, Lisp_Object named) | 1756 | (Lisp_Object node, Lisp_Object beg, Lisp_Object end, Lisp_Object named) |
| 1752 | { | 1757 | { |
| 1753 | if (NILP (node)) return Qnil; | 1758 | if (NILP (node)) return Qnil; |
| 1754 | ts_check_node (node); | 1759 | treesit_check_node (node); |
| 1755 | CHECK_INTEGER (beg); | 1760 | CHECK_INTEGER (beg); |
| 1756 | CHECK_INTEGER (end); | 1761 | CHECK_INTEGER (end); |
| 1757 | 1762 | ||
| @@ -1766,22 +1771,22 @@ If NODE is nil, return nil. */) | |||
| 1766 | && byte_end <= BUF_ZV_BYTE (buf))) | 1771 | && byte_end <= BUF_ZV_BYTE (buf))) |
| 1767 | xsignal2 (Qargs_out_of_range, beg, end); | 1772 | xsignal2 (Qargs_out_of_range, beg, end); |
| 1768 | 1773 | ||
| 1769 | ts_initialize (); | 1774 | treesit_initialize (); |
| 1770 | 1775 | ||
| 1771 | TSNode ts_node = XTS_NODE (node)->node; | 1776 | TSNode treesit_node = XTS_NODE (node)->node; |
| 1772 | TSNode child; | 1777 | TSNode child; |
| 1773 | if (NILP (named)) | 1778 | if (NILP (named)) |
| 1774 | child = ts_node_descendant_for_byte_range (ts_node, byte_beg - visible_beg, | 1779 | child = ts_node_descendant_for_byte_range (treesit_node, byte_beg - visible_beg, |
| 1775 | byte_end - visible_beg); | 1780 | byte_end - visible_beg); |
| 1776 | else | 1781 | else |
| 1777 | child = ts_node_named_descendant_for_byte_range (ts_node, | 1782 | child = ts_node_named_descendant_for_byte_range (treesit_node, |
| 1778 | byte_beg - visible_beg, | 1783 | byte_beg - visible_beg, |
| 1779 | byte_end - visible_beg); | 1784 | byte_end - visible_beg); |
| 1780 | 1785 | ||
| 1781 | if (ts_node_is_null (child)) | 1786 | if (ts_node_is_null (child)) |
| 1782 | return Qnil; | 1787 | return Qnil; |
| 1783 | 1788 | ||
| 1784 | return make_ts_node (XTS_NODE (node)->parser, child); | 1789 | return make_treesit_node (XTS_NODE (node)->parser, child); |
| 1785 | } | 1790 | } |
| 1786 | 1791 | ||
| 1787 | DEFUN ("treesit-node-eq", | 1792 | DEFUN ("treesit-node-eq", |
| @@ -1796,12 +1801,12 @@ If any one of NODE1 and NODE2 is nil, return nil. */) | |||
| 1796 | CHECK_TS_NODE (node1); | 1801 | CHECK_TS_NODE (node1); |
| 1797 | CHECK_TS_NODE (node2); | 1802 | CHECK_TS_NODE (node2); |
| 1798 | 1803 | ||
| 1799 | ts_initialize (); | 1804 | treesit_initialize (); |
| 1800 | 1805 | ||
| 1801 | TSNode ts_node_1 = XTS_NODE (node1)->node; | 1806 | TSNode treesit_node_1 = XTS_NODE (node1)->node; |
| 1802 | TSNode ts_node_2 = XTS_NODE (node2)->node; | 1807 | TSNode treesit_node_2 = XTS_NODE (node2)->node; |
| 1803 | 1808 | ||
| 1804 | bool same_node = ts_node_eq (ts_node_1, ts_node_2); | 1809 | bool same_node = ts_node_eq (treesit_node_1, treesit_node_2); |
| 1805 | return same_node ? Qt : Qnil; | 1810 | return same_node ? Qt : Qnil; |
| 1806 | } | 1811 | } |
| 1807 | 1812 | ||
| @@ -1832,17 +1837,17 @@ See Info node `(elisp)Pattern Matching' for detailed explanation. */) | |||
| 1832 | (Lisp_Object pattern) | 1837 | (Lisp_Object pattern) |
| 1833 | { | 1838 | { |
| 1834 | if (EQ (pattern, intern_c_string (":anchor"))) | 1839 | if (EQ (pattern, intern_c_string (":anchor"))) |
| 1835 | return build_pure_c_string("."); | 1840 | return build_pure_c_string ("."); |
| 1836 | if (EQ (pattern, intern_c_string (":?"))) | 1841 | if (EQ (pattern, intern_c_string (":?"))) |
| 1837 | return build_pure_c_string("?"); | 1842 | return build_pure_c_string ("?"); |
| 1838 | if (EQ (pattern, intern_c_string (":*"))) | 1843 | if (EQ (pattern, intern_c_string (":*"))) |
| 1839 | return build_pure_c_string("*"); | 1844 | return build_pure_c_string ("*"); |
| 1840 | if (EQ (pattern, intern_c_string (":+"))) | 1845 | if (EQ (pattern, intern_c_string (":+"))) |
| 1841 | return build_pure_c_string("+"); | 1846 | return build_pure_c_string ("+"); |
| 1842 | if (EQ (pattern, intern_c_string (":equal"))) | 1847 | if (EQ (pattern, intern_c_string (":equal"))) |
| 1843 | return build_pure_c_string("#equal"); | 1848 | return build_pure_c_string ("#equal"); |
| 1844 | if (EQ (pattern, intern_c_string (":match"))) | 1849 | if (EQ (pattern, intern_c_string (":match"))) |
| 1845 | return build_pure_c_string("#match"); | 1850 | return build_pure_c_string ("#match"); |
| 1846 | Lisp_Object opening_delimeter = | 1851 | Lisp_Object opening_delimeter = |
| 1847 | build_pure_c_string (VECTORP (pattern) ? "[" : "("); | 1852 | build_pure_c_string (VECTORP (pattern) ? "[" : "("); |
| 1848 | Lisp_Object closing_delimiter = | 1853 | Lisp_Object closing_delimiter = |
| @@ -1853,7 +1858,7 @@ See Info node `(elisp)Pattern Matching' for detailed explanation. */) | |||
| 1853 | pattern, | 1858 | pattern, |
| 1854 | build_pure_c_string (" ")), | 1859 | build_pure_c_string (" ")), |
| 1855 | closing_delimiter); | 1860 | closing_delimiter); |
| 1856 | return CALLN (Fformat, build_pure_c_string("%S"), pattern); | 1861 | return CALLN (Fformat, build_pure_c_string ("%S"), pattern); |
| 1857 | } | 1862 | } |
| 1858 | 1863 | ||
| 1859 | DEFUN ("treesit-query-expand", | 1864 | DEFUN ("treesit-query-expand", |
| @@ -1902,8 +1907,7 @@ struct capture_range | |||
| 1902 | /* Collect predicates for this match and return them in a list. Each | 1907 | /* Collect predicates for this match and return them in a list. Each |
| 1903 | predicate is a list of strings and symbols. */ | 1908 | predicate is a list of strings and symbols. */ |
| 1904 | static Lisp_Object | 1909 | static Lisp_Object |
| 1905 | ts_predicates_for_pattern | 1910 | treesit_predicates_for_pattern (TSQuery *query, uint32_t pattern_index) |
| 1906 | (TSQuery *query, uint32_t pattern_index) | ||
| 1907 | { | 1911 | { |
| 1908 | uint32_t len; | 1912 | uint32_t len; |
| 1909 | const TSQueryPredicateStep *predicate_list = | 1913 | const TSQueryPredicateStep *predicate_list = |
| @@ -1946,8 +1950,8 @@ ts_predicates_for_pattern | |||
| 1946 | /* Translate a capture NAME (symbol) to the text of the captured node. | 1950 | /* Translate a capture NAME (symbol) to the text of the captured node. |
| 1947 | Signals treesit-query-error if such node is not captured. */ | 1951 | Signals treesit-query-error if such node is not captured. */ |
| 1948 | static Lisp_Object | 1952 | static Lisp_Object |
| 1949 | ts_predicate_capture_name_to_text (Lisp_Object name, | 1953 | treesit_predicate_capture_name_to_text (Lisp_Object name, |
| 1950 | struct capture_range captures) | 1954 | struct capture_range captures) |
| 1951 | { | 1955 | { |
| 1952 | Lisp_Object node = Qnil; | 1956 | Lisp_Object node = Qnil; |
| 1953 | for (Lisp_Object tail = captures.start; !EQ (tail, captures.end); | 1957 | for (Lisp_Object tail = captures.start; !EQ (tail, captures.end); |
| @@ -1978,7 +1982,7 @@ ts_predicate_capture_name_to_text (Lisp_Object name, | |||
| 1978 | The capture name evaluates to the text its captured node spans in | 1982 | The capture name evaluates to the text its captured node spans in |
| 1979 | the buffer. */ | 1983 | the buffer. */ |
| 1980 | static bool | 1984 | static bool |
| 1981 | ts_predicate_equal (Lisp_Object args, struct capture_range captures) | 1985 | treesit_predicate_equal (Lisp_Object args, struct capture_range captures) |
| 1982 | { | 1986 | { |
| 1983 | if (XFIXNUM (Flength (args)) != 2) | 1987 | if (XFIXNUM (Flength (args)) != 2) |
| 1984 | xsignal2 (Qtreesit_query_error, | 1988 | xsignal2 (Qtreesit_query_error, |
| @@ -1988,9 +1992,11 @@ ts_predicate_equal (Lisp_Object args, struct capture_range captures) | |||
| 1988 | Lisp_Object arg1 = XCAR (args); | 1992 | Lisp_Object arg1 = XCAR (args); |
| 1989 | Lisp_Object arg2 = XCAR (XCDR (args)); | 1993 | Lisp_Object arg2 = XCAR (XCDR (args)); |
| 1990 | Lisp_Object text1 = | 1994 | Lisp_Object text1 = |
| 1991 | STRINGP (arg1) ? arg1 : ts_predicate_capture_name_to_text (arg1, captures); | 1995 | STRINGP (arg1) ? arg1 : treesit_predicate_capture_name_to_text (arg1, |
| 1996 | captures); | ||
| 1992 | Lisp_Object text2 = | 1997 | Lisp_Object text2 = |
| 1993 | STRINGP (arg2) ? arg2 : ts_predicate_capture_name_to_text (arg2, captures); | 1998 | STRINGP (arg2) ? arg2 : treesit_predicate_capture_name_to_text (arg2, |
| 1999 | captures); | ||
| 1994 | 2000 | ||
| 1995 | return !NILP (Fstring_equal (text1, text2)); | 2001 | return !NILP (Fstring_equal (text1, text2)); |
| 1996 | } | 2002 | } |
| @@ -1999,8 +2005,7 @@ ts_predicate_equal (Lisp_Object args, struct capture_range captures) | |||
| 1999 | matches the text spanned by @node; return false otherwise. Matching | 2005 | matches the text spanned by @node; return false otherwise. Matching |
| 2000 | is case-sensitive. */ | 2006 | is case-sensitive. */ |
| 2001 | static bool | 2007 | static bool |
| 2002 | ts_predicate_match | 2008 | treesit_predicate_match (Lisp_Object args, struct capture_range captures) |
| 2003 | (Lisp_Object args, struct capture_range captures) | ||
| 2004 | { | 2009 | { |
| 2005 | if (XFIXNUM (Flength (args)) != 2) | 2010 | if (XFIXNUM (Flength (args)) != 2) |
| 2006 | xsignal2 (Qtreesit_query_error, | 2011 | xsignal2 (Qtreesit_query_error, |
| @@ -2009,7 +2014,8 @@ ts_predicate_match | |||
| 2009 | 2014 | ||
| 2010 | Lisp_Object regexp = XCAR (args); | 2015 | Lisp_Object regexp = XCAR (args); |
| 2011 | Lisp_Object capture_name = XCAR (XCDR (args)); | 2016 | Lisp_Object capture_name = XCAR (XCDR (args)); |
| 2012 | Lisp_Object text = ts_predicate_capture_name_to_text (capture_name, captures); | 2017 | Lisp_Object text = treesit_predicate_capture_name_to_text (capture_name, |
| 2018 | captures); | ||
| 2013 | 2019 | ||
| 2014 | /* It's probably common to get the argument order backwards. Catch | 2020 | /* It's probably common to get the argument order backwards. Catch |
| 2015 | this mistake early and show helpful explanation, because Emacs | 2021 | this mistake early and show helpful explanation, because Emacs |
| @@ -2039,7 +2045,7 @@ ts_predicate_match | |||
| 2039 | /* If all predicates in PREDICATES passes, return true; otherwise | 2045 | /* If all predicates in PREDICATES passes, return true; otherwise |
| 2040 | return false. */ | 2046 | return false. */ |
| 2041 | static bool | 2047 | static bool |
| 2042 | ts_eval_predicates (struct capture_range captures, Lisp_Object predicates) | 2048 | treesit_eval_predicates (struct capture_range captures, Lisp_Object predicates) |
| 2043 | { | 2049 | { |
| 2044 | bool pass = true; | 2050 | bool pass = true; |
| 2045 | /* Evaluate each predicates. */ | 2051 | /* Evaluate each predicates. */ |
| @@ -2049,10 +2055,10 @@ ts_eval_predicates (struct capture_range captures, Lisp_Object predicates) | |||
| 2049 | Lisp_Object predicate = XCAR (tail); | 2055 | Lisp_Object predicate = XCAR (tail); |
| 2050 | Lisp_Object fn = XCAR (predicate); | 2056 | Lisp_Object fn = XCAR (predicate); |
| 2051 | Lisp_Object args = XCDR (predicate); | 2057 | Lisp_Object args = XCDR (predicate); |
| 2052 | if (!NILP (Fstring_equal (fn, build_pure_c_string("equal")))) | 2058 | if (!NILP (Fstring_equal (fn, build_pure_c_string ("equal")))) |
| 2053 | pass = ts_predicate_equal (args, captures); | 2059 | pass = treesit_predicate_equal (args, captures); |
| 2054 | else if (!NILP (Fstring_equal (fn, build_pure_c_string("match")))) | 2060 | else if (!NILP (Fstring_equal (fn, build_pure_c_string ("match")))) |
| 2055 | pass = ts_predicate_match (args, captures); | 2061 | pass = treesit_predicate_match (args, captures); |
| 2056 | else | 2062 | else |
| 2057 | xsignal3 (Qtreesit_query_error, | 2063 | xsignal3 (Qtreesit_query_error, |
| 2058 | build_pure_c_string ("Invalid predicate"), | 2064 | build_pure_c_string ("Invalid predicate"), |
| @@ -2084,9 +2090,9 @@ You can use `treesit-query-validate' to validate and debug a query. */) | |||
| 2084 | if (TS_COMPILED_QUERY_P (query)) | 2090 | if (TS_COMPILED_QUERY_P (query)) |
| 2085 | return query; | 2091 | return query; |
| 2086 | 2092 | ||
| 2087 | ts_initialize (); | 2093 | treesit_initialize (); |
| 2088 | 2094 | ||
| 2089 | Lisp_Object lisp_query = make_ts_query (query, language); | 2095 | Lisp_Object lisp_query = make_treesit_query (query, language); |
| 2090 | 2096 | ||
| 2091 | /* Maybe actually compile. */ | 2097 | /* Maybe actually compile. */ |
| 2092 | if (NILP (eager)) | 2098 | if (NILP (eager)) |
| @@ -2095,10 +2101,11 @@ You can use `treesit-query-validate' to validate and debug a query. */) | |||
| 2095 | { | 2101 | { |
| 2096 | Lisp_Object signal_symbol = Qnil; | 2102 | Lisp_Object signal_symbol = Qnil; |
| 2097 | Lisp_Object signal_data = Qnil; | 2103 | Lisp_Object signal_data = Qnil; |
| 2098 | TSQuery *ts_query = ts_ensure_query_compiled (lisp_query, &signal_symbol, | 2104 | TSQuery *treesit_query = treesit_ensure_query_compiled (lisp_query, |
| 2099 | &signal_data); | 2105 | &signal_symbol, |
| 2106 | &signal_data); | ||
| 2100 | 2107 | ||
| 2101 | if (ts_query == NULL) | 2108 | if (treesit_query == NULL) |
| 2102 | xsignal (signal_symbol, signal_data); | 2109 | xsignal (signal_symbol, signal_data); |
| 2103 | 2110 | ||
| 2104 | return lisp_query; | 2111 | return lisp_query; |
| @@ -2162,10 +2169,10 @@ the query. */) | |||
| 2162 | list4 (Qor, Qtreesit_node_p, Qtreesit_parser_p, Qsymbolp), | 2169 | list4 (Qor, Qtreesit_node_p, Qtreesit_parser_p, Qsymbolp), |
| 2163 | node); | 2170 | node); |
| 2164 | 2171 | ||
| 2165 | ts_initialize (); | 2172 | treesit_initialize (); |
| 2166 | 2173 | ||
| 2167 | /* Extract C values from Lisp objects. */ | 2174 | /* Extract C values from Lisp objects. */ |
| 2168 | TSNode ts_node = XTS_NODE (lisp_node)->node; | 2175 | TSNode treesit_node = XTS_NODE (lisp_node)->node; |
| 2169 | Lisp_Object lisp_parser = XTS_NODE (lisp_node)->parser; | 2176 | Lisp_Object lisp_parser = XTS_NODE (lisp_node)->parser; |
| 2170 | ptrdiff_t visible_beg = | 2177 | ptrdiff_t visible_beg = |
| 2171 | XTS_PARSER (XTS_NODE (lisp_node)->parser)->visible_beg; | 2178 | XTS_PARSER (XTS_NODE (lisp_node)->parser)->visible_beg; |
| @@ -2174,19 +2181,20 @@ the query. */) | |||
| 2174 | 2181 | ||
| 2175 | /* Initialize query objects. At the end of this block, we should | 2182 | /* Initialize query objects. At the end of this block, we should |
| 2176 | have a working TSQuery and a TSQueryCursor. */ | 2183 | have a working TSQuery and a TSQueryCursor. */ |
| 2177 | TSQuery *ts_query; | 2184 | TSQuery *treesit_query; |
| 2178 | TSQueryCursor *cursor; | 2185 | TSQueryCursor *cursor; |
| 2179 | bool needs_to_free_query_and_cursor; | 2186 | bool needs_to_free_query_and_cursor; |
| 2180 | if (TS_COMPILED_QUERY_P (query)) | 2187 | if (TS_COMPILED_QUERY_P (query)) |
| 2181 | { | 2188 | { |
| 2182 | Lisp_Object signal_symbol = Qnil; | 2189 | Lisp_Object signal_symbol = Qnil; |
| 2183 | Lisp_Object signal_data = Qnil; | 2190 | Lisp_Object signal_data = Qnil; |
| 2184 | ts_query = ts_ensure_query_compiled (query, &signal_symbol, &signal_data); | 2191 | treesit_query = treesit_ensure_query_compiled (query, &signal_symbol, |
| 2192 | &signal_data); | ||
| 2185 | cursor = XTS_COMPILED_QUERY (query)->cursor; | 2193 | cursor = XTS_COMPILED_QUERY (query)->cursor; |
| 2186 | /* We don't need to free ts_query and cursor because they | 2194 | /* We don't need to free ts_query and cursor because they |
| 2187 | are stored in a lisp object, which is tracked by gc. */ | 2195 | are stored in a lisp object, which is tracked by gc. */ |
| 2188 | needs_to_free_query_and_cursor = false; | 2196 | needs_to_free_query_and_cursor = false; |
| 2189 | if (ts_query == NULL) | 2197 | if (treesit_query == NULL) |
| 2190 | xsignal (signal_symbol, signal_data); | 2198 | xsignal (signal_symbol, signal_data); |
| 2191 | } | 2199 | } |
| 2192 | else | 2200 | else |
| @@ -2198,16 +2206,16 @@ the query. */) | |||
| 2198 | char *query_string = SSDATA (query); | 2206 | char *query_string = SSDATA (query); |
| 2199 | uint32_t error_offset; | 2207 | uint32_t error_offset; |
| 2200 | TSQueryError error_type; | 2208 | TSQueryError error_type; |
| 2201 | ts_query = ts_query_new (lang, query_string, strlen (query_string), | 2209 | treesit_query = ts_query_new (lang, query_string, strlen (query_string), |
| 2202 | &error_offset, &error_type); | 2210 | &error_offset, &error_type); |
| 2203 | if (ts_query == NULL) | 2211 | if (treesit_query == NULL) |
| 2204 | xsignal (Qtreesit_query_error, | 2212 | xsignal (Qtreesit_query_error, |
| 2205 | ts_compose_query_signal_data (error_offset, error_type)); | 2213 | treesit_compose_query_signal_data (error_offset, error_type)); |
| 2206 | cursor = ts_query_cursor_new (); | 2214 | cursor = ts_query_cursor_new (); |
| 2207 | needs_to_free_query_and_cursor = true; | 2215 | needs_to_free_query_and_cursor = true; |
| 2208 | } | 2216 | } |
| 2209 | 2217 | ||
| 2210 | /* WARN: After this point, free ts_query and cursor before every | 2218 | /* WARN: After this point, free treesit_query and cursor before every |
| 2211 | signal and return. */ | 2219 | signal and return. */ |
| 2212 | 2220 | ||
| 2213 | /* Set query range. */ | 2221 | /* Set query range. */ |
| @@ -2221,7 +2229,7 @@ the query. */) | |||
| 2221 | } | 2229 | } |
| 2222 | 2230 | ||
| 2223 | /* Execute query. */ | 2231 | /* Execute query. */ |
| 2224 | ts_query_cursor_exec (cursor, ts_query, ts_node); | 2232 | ts_query_cursor_exec (cursor, treesit_query, treesit_node); |
| 2225 | TSQueryMatch match; | 2233 | TSQueryMatch match; |
| 2226 | 2234 | ||
| 2227 | /* Go over each match, collect captures and predicates. Include the | 2235 | /* Go over each match, collect captures and predicates. Include the |
| @@ -2245,13 +2253,14 @@ the query. */) | |||
| 2245 | { | 2253 | { |
| 2246 | uint32_t capture_name_len; | 2254 | uint32_t capture_name_len; |
| 2247 | TSQueryCapture capture = captures[idx]; | 2255 | TSQueryCapture capture = captures[idx]; |
| 2248 | Lisp_Object captured_node = make_ts_node(lisp_parser, capture.node); | 2256 | Lisp_Object captured_node = make_treesit_node (lisp_parser, |
| 2257 | capture.node); | ||
| 2249 | 2258 | ||
| 2250 | Lisp_Object cap; | 2259 | Lisp_Object cap; |
| 2251 | if (NILP (node_only)) | 2260 | if (NILP (node_only)) |
| 2252 | { | 2261 | { |
| 2253 | const char *capture_name = | 2262 | const char *capture_name = |
| 2254 | ts_query_capture_name_for_id (ts_query, capture.index, | 2263 | ts_query_capture_name_for_id (treesit_query, capture.index, |
| 2255 | &capture_name_len); | 2264 | &capture_name_len); |
| 2256 | cap = Fcons (intern_c_string_1 (capture_name, capture_name_len), | 2265 | cap = Fcons (intern_c_string_1 (capture_name, capture_name_len), |
| 2257 | captured_node); | 2266 | captured_node); |
| @@ -2263,11 +2272,11 @@ the query. */) | |||
| 2263 | } | 2272 | } |
| 2264 | /* Get predicates. */ | 2273 | /* Get predicates. */ |
| 2265 | Lisp_Object predicates = | 2274 | Lisp_Object predicates = |
| 2266 | ts_predicates_for_pattern (ts_query, match.pattern_index); | 2275 | treesit_predicates_for_pattern (treesit_query, match.pattern_index); |
| 2267 | 2276 | ||
| 2268 | /* captures_lisp = Fnreverse (captures_lisp); */ | 2277 | /* captures_lisp = Fnreverse (captures_lisp); */ |
| 2269 | struct capture_range captures_range = { result, prev_result }; | 2278 | struct capture_range captures_range = { result, prev_result }; |
| 2270 | if (!ts_eval_predicates (captures_range, predicates)) | 2279 | if (!treesit_eval_predicates (captures_range, predicates)) |
| 2271 | { | 2280 | { |
| 2272 | /* Predicates didn't pass, roll back. */ | 2281 | /* Predicates didn't pass, roll back. */ |
| 2273 | result = prev_result; | 2282 | result = prev_result; |
| @@ -2275,7 +2284,7 @@ the query. */) | |||
| 2275 | } | 2284 | } |
| 2276 | if (needs_to_free_query_and_cursor) | 2285 | if (needs_to_free_query_and_cursor) |
| 2277 | { | 2286 | { |
| 2278 | ts_query_delete (ts_query); | 2287 | ts_query_delete (treesit_query); |
| 2279 | ts_query_cursor_delete (cursor); | 2288 | ts_query_cursor_delete (cursor); |
| 2280 | } | 2289 | } |
| 2281 | return Fnreverse (result); | 2290 | return Fnreverse (result); |
| @@ -2287,7 +2296,7 @@ the query. */) | |||
| 2287 | controls the direction and NAMED controls the nameness. | 2296 | controls the direction and NAMED controls the nameness. |
| 2288 | */ | 2297 | */ |
| 2289 | static TSNode | 2298 | static TSNode |
| 2290 | ts_traverse_sibling_helper (TSNode node, bool forward, bool named) | 2299 | treesit_traverse_sibling_helper (TSNode node, bool forward, bool named) |
| 2291 | { | 2300 | { |
| 2292 | if (forward) | 2301 | if (forward) |
| 2293 | { | 2302 | { |
| @@ -2308,7 +2317,8 @@ ts_traverse_sibling_helper (TSNode node, bool forward, bool named) | |||
| 2308 | /* Return true if NODE matches PRED. PRED can be a string or a | 2317 | /* Return true if NODE matches PRED. PRED can be a string or a |
| 2309 | function. This function doesn't check for PRED's type. */ | 2318 | function. This function doesn't check for PRED's type. */ |
| 2310 | static bool | 2319 | static bool |
| 2311 | ts_traverse_match_predicate (TSNode node, Lisp_Object pred, Lisp_Object parser) | 2320 | treesit_traverse_match_predicate (TSNode node, Lisp_Object pred, |
| 2321 | Lisp_Object parser) | ||
| 2312 | { | 2322 | { |
| 2313 | if (STRINGP (pred)) | 2323 | if (STRINGP (pred)) |
| 2314 | { | 2324 | { |
| @@ -2317,7 +2327,7 @@ ts_traverse_match_predicate (TSNode node, Lisp_Object pred, Lisp_Object parser) | |||
| 2317 | } | 2327 | } |
| 2318 | else | 2328 | else |
| 2319 | { | 2329 | { |
| 2320 | Lisp_Object lisp_node = make_ts_node (parser, node); | 2330 | Lisp_Object lisp_node = make_treesit_node (parser, node); |
| 2321 | return !NILP (CALLN (Ffuncall, pred, lisp_node)); | 2331 | return !NILP (CALLN (Ffuncall, pred, lisp_node)); |
| 2322 | } | 2332 | } |
| 2323 | 2333 | ||
| @@ -2337,16 +2347,16 @@ ts_traverse_match_predicate (TSNode node, Lisp_Object pred, Lisp_Object parser) | |||
| 2337 | is true, only traverse named nodes, if false, all nodes. If | 2347 | is true, only traverse named nodes, if false, all nodes. If |
| 2338 | SKIP_ROOT is true, don't match ROOT. */ | 2348 | SKIP_ROOT is true, don't match ROOT. */ |
| 2339 | static bool | 2349 | static bool |
| 2340 | ts_search_dfs (TSNode *root, Lisp_Object pred, Lisp_Object parser, | 2350 | treesit_search_dfs (TSNode *root, Lisp_Object pred, Lisp_Object parser, |
| 2341 | bool named, bool forward, ptrdiff_t limit, bool no_limit, | 2351 | bool named, bool forward, ptrdiff_t limit, bool no_limit, |
| 2342 | bool skip_root) | 2352 | bool skip_root) |
| 2343 | { | 2353 | { |
| 2344 | /* TSTreeCursor doesn't allow us to move backward, so we can't use | 2354 | /* TSTreeCursor doesn't allow us to move backward, so we can't use |
| 2345 | it. We could use limit == -1 to indicate no_limit == true, but | 2355 | it. We could use limit == -1 to indicate no_limit == true, but |
| 2346 | separating them is safer. */ | 2356 | separating them is safer. */ |
| 2347 | TSNode node = *root; | 2357 | TSNode node = *root; |
| 2348 | 2358 | ||
| 2349 | if (!skip_root && ts_traverse_match_predicate (node, pred, parser)) | 2359 | if (!skip_root && treesit_traverse_match_predicate (node, pred, parser)) |
| 2350 | { | 2360 | { |
| 2351 | *root = node; | 2361 | *root = node; |
| 2352 | return true; | 2362 | return true; |
| @@ -2357,15 +2367,15 @@ ts_search_dfs (TSNode *root, Lisp_Object pred, Lisp_Object parser, | |||
| 2357 | else | 2367 | else |
| 2358 | { | 2368 | { |
| 2359 | int count = | 2369 | int count = |
| 2360 | named ? ts_node_named_child_count(node) : ts_node_child_count (node); | 2370 | named ? ts_node_named_child_count (node) : ts_node_child_count (node); |
| 2361 | for (int offset = 0; offset < count; offset++) | 2371 | for (int offset = 0; offset < count; offset++) |
| 2362 | { | 2372 | { |
| 2363 | uint32_t idx = forward ? offset : count - offset - 1; | 2373 | uint32_t idx = forward ? offset : count - offset - 1; |
| 2364 | TSNode child = ts_node_child (node, idx); | 2374 | TSNode child = ts_node_child (node, idx); |
| 2365 | 2375 | ||
| 2366 | if (!ts_node_is_null (child) | 2376 | if (!ts_node_is_null (child) |
| 2367 | && ts_search_dfs (&child, pred, parser, named, | 2377 | && treesit_search_dfs (&child, pred, parser, named, |
| 2368 | forward, limit - 1, no_limit, false)) | 2378 | forward, limit - 1, no_limit, false)) |
| 2369 | { | 2379 | { |
| 2370 | *root = child; | 2380 | *root = child; |
| 2371 | return true; | 2381 | return true; |
| @@ -2381,31 +2391,32 @@ ts_search_dfs (TSNode *root, Lisp_Object pred, Lisp_Object parser, | |||
| 2381 | sibling and parents. If SKIP_START is true, don'tt match | 2391 | sibling and parents. If SKIP_START is true, don'tt match |
| 2382 | START. */ | 2392 | START. */ |
| 2383 | static bool | 2393 | static bool |
| 2384 | ts_search_forward (TSNode *start, Lisp_Object pred, Lisp_Object parser, | 2394 | treesit_search_forward (TSNode *start, Lisp_Object pred, Lisp_Object parser, |
| 2385 | bool named, bool forward, bool up_only, bool skip_start) | 2395 | bool named, bool forward, bool up_only, bool skip_start) |
| 2386 | { | 2396 | { |
| 2387 | TSNode node = *start; | 2397 | TSNode node = *start; |
| 2388 | 2398 | ||
| 2389 | if (!up_only | 2399 | if (!up_only |
| 2390 | && ts_search_dfs (start, pred, parser, named, forward, 0, true, | 2400 | && treesit_search_dfs (start, pred, parser, named, forward, 0, true, |
| 2391 | skip_start)) | 2401 | skip_start)) |
| 2392 | return true; | 2402 | return true; |
| 2393 | 2403 | ||
| 2394 | TSNode next = ts_traverse_sibling_helper (node, forward, named); | 2404 | TSNode next = treesit_traverse_sibling_helper (node, forward, named); |
| 2395 | while (ts_node_is_null (next)) | 2405 | while (ts_node_is_null (next)) |
| 2396 | { | 2406 | { |
| 2397 | node = ts_node_parent (node); | 2407 | node = ts_node_parent (node); |
| 2398 | if (ts_node_is_null (node)) | 2408 | if (ts_node_is_null (node)) |
| 2399 | return false; | 2409 | return false; |
| 2400 | 2410 | ||
| 2401 | if (ts_traverse_match_predicate (node, pred, parser)) | 2411 | if (treesit_traverse_match_predicate (node, pred, parser)) |
| 2402 | { | 2412 | { |
| 2403 | *start = node; | 2413 | *start = node; |
| 2404 | return true; | 2414 | return true; |
| 2405 | } | 2415 | } |
| 2406 | next = ts_traverse_sibling_helper (node, forward, named); | 2416 | next = treesit_traverse_sibling_helper (node, forward, named); |
| 2407 | } | 2417 | } |
| 2408 | if (ts_search_forward (&next, pred, parser, named, forward, up_only, false)) | 2418 | if (treesit_search_forward (&next, pred, parser, named, forward, up_only, |
| 2419 | false)) | ||
| 2409 | { | 2420 | { |
| 2410 | *start = next; | 2421 | *start = next; |
| 2411 | return true; | 2422 | return true; |
| @@ -2448,13 +2459,13 @@ Return the first matched node, or nil if none matches. */) | |||
| 2448 | the_limit = XFIXNUM (limit); | 2459 | the_limit = XFIXNUM (limit); |
| 2449 | } | 2460 | } |
| 2450 | 2461 | ||
| 2451 | ts_initialize (); | 2462 | treesit_initialize (); |
| 2452 | 2463 | ||
| 2453 | TSNode ts_node = XTS_NODE (node)->node; | 2464 | TSNode treesit_node = XTS_NODE (node)->node; |
| 2454 | Lisp_Object parser = XTS_NODE (node)->parser; | 2465 | Lisp_Object parser = XTS_NODE (node)->parser; |
| 2455 | if (ts_search_dfs (&ts_node, predicate, parser, NILP (all), | 2466 | if (treesit_search_dfs (&treesit_node, predicate, parser, NILP (all), |
| 2456 | NILP (backward), the_limit, no_limit, false)) | 2467 | NILP (backward), the_limit, no_limit, false)) |
| 2457 | return make_ts_node (parser, ts_node); | 2468 | return make_treesit_node (parser, treesit_node); |
| 2458 | else | 2469 | else |
| 2459 | return Qnil; | 2470 | return Qnil; |
| 2460 | } | 2471 | } |
| @@ -2498,13 +2509,13 @@ case, only the nodes 1, 3, 4, 8, and 16 would be traversed. */) | |||
| 2498 | CHECK_SYMBOL (backward); | 2509 | CHECK_SYMBOL (backward); |
| 2499 | CHECK_SYMBOL (up); | 2510 | CHECK_SYMBOL (up); |
| 2500 | 2511 | ||
| 2501 | ts_initialize (); | 2512 | treesit_initialize (); |
| 2502 | 2513 | ||
| 2503 | TSNode ts_start = XTS_NODE (start)->node; | 2514 | TSNode treesit_start = XTS_NODE (start)->node; |
| 2504 | Lisp_Object parser = XTS_NODE (start)->parser; | 2515 | Lisp_Object parser = XTS_NODE (start)->parser; |
| 2505 | if (ts_search_forward (&ts_start, predicate, parser, NILP (all), | 2516 | if (treesit_search_forward (&treesit_start, predicate, parser, NILP (all), |
| 2506 | NILP (backward), !NILP (up), true)) | 2517 | NILP (backward), !NILP (up), true)) |
| 2507 | return make_ts_node (parser, ts_start); | 2518 | return make_treesit_node (parser, treesit_start); |
| 2508 | else | 2519 | else |
| 2509 | return Qnil; | 2520 | return Qnil; |
| 2510 | } | 2521 | } |
| @@ -2514,18 +2525,18 @@ case, only the nodes 1, 3, 4, 8, and 16 would be traversed. */) | |||
| 2514 | Note that the top-level children list is reversed, because | 2525 | Note that the top-level children list is reversed, because |
| 2515 | reasons. */ | 2526 | reasons. */ |
| 2516 | static void | 2527 | static void |
| 2517 | ts_build_sparse_tree (TSTreeCursor *cursor, Lisp_Object parent, | 2528 | treesit_build_sparse_tree (TSTreeCursor *cursor, Lisp_Object parent, |
| 2518 | Lisp_Object pred, Lisp_Object process_fn, ptrdiff_t limit, | 2529 | Lisp_Object pred, Lisp_Object process_fn, |
| 2519 | bool no_limit, Lisp_Object parser) | 2530 | ptrdiff_t limit, bool no_limit, Lisp_Object parser) |
| 2520 | { | 2531 | { |
| 2521 | 2532 | ||
| 2522 | TSNode node = ts_tree_cursor_current_node (cursor); | 2533 | TSNode node = ts_tree_cursor_current_node (cursor); |
| 2523 | bool match = ts_traverse_match_predicate (node, pred, parser); | 2534 | bool match = treesit_traverse_match_predicate (node, pred, parser); |
| 2524 | if (match) | 2535 | if (match) |
| 2525 | { | 2536 | { |
| 2526 | /* If this node matches pred, add a new node to the parent's | 2537 | /* If this node matches pred, add a new node to the parent's |
| 2527 | children list. */ | 2538 | children list. */ |
| 2528 | Lisp_Object lisp_node = make_ts_node (parser, node); | 2539 | Lisp_Object lisp_node = make_treesit_node (parser, node); |
| 2529 | if (!NILP (process_fn)) | 2540 | if (!NILP (process_fn)) |
| 2530 | lisp_node = CALLN (Ffuncall, process_fn, lisp_node); | 2541 | lisp_node = CALLN (Ffuncall, process_fn, lisp_node); |
| 2531 | 2542 | ||
| @@ -2543,8 +2554,8 @@ ts_build_sparse_tree (TSTreeCursor *cursor, Lisp_Object parent, | |||
| 2543 | /* Make sure not to use node after the recursive funcall. | 2554 | /* Make sure not to use node after the recursive funcall. |
| 2544 | Then C compilers should be smart enough not to copy NODE | 2555 | Then C compilers should be smart enough not to copy NODE |
| 2545 | to stack. */ | 2556 | to stack. */ |
| 2546 | ts_build_sparse_tree (cursor, parent, pred, process_fn, | 2557 | treesit_build_sparse_tree (cursor, parent, pred, process_fn, |
| 2547 | limit - 1, no_limit, parser); | 2558 | limit - 1, no_limit, parser); |
| 2548 | } | 2559 | } |
| 2549 | while (ts_tree_cursor_goto_next_sibling (cursor)); | 2560 | while (ts_tree_cursor_goto_next_sibling (cursor)); |
| 2550 | /* Don't forget to come back to this node. */ | 2561 | /* Don't forget to come back to this node. */ |
| @@ -2617,13 +2628,13 @@ a regexp. */) | |||
| 2617 | the_limit = XFIXNUM (limit); | 2628 | the_limit = XFIXNUM (limit); |
| 2618 | } | 2629 | } |
| 2619 | 2630 | ||
| 2620 | ts_initialize (); | 2631 | treesit_initialize (); |
| 2621 | 2632 | ||
| 2622 | TSTreeCursor cursor = ts_tree_cursor_new (XTS_NODE (root)->node); | 2633 | TSTreeCursor cursor = ts_tree_cursor_new (XTS_NODE (root)->node); |
| 2623 | Lisp_Object parser = XTS_NODE (root)->parser; | 2634 | Lisp_Object parser = XTS_NODE (root)->parser; |
| 2624 | Lisp_Object parent = Fcons (Qnil, Qnil); | 2635 | Lisp_Object parent = Fcons (Qnil, Qnil); |
| 2625 | ts_build_sparse_tree (&cursor, parent, predicate, process_fn, | 2636 | treesit_build_sparse_tree (&cursor, parent, predicate, process_fn, |
| 2626 | the_limit, no_limit, parser); | 2637 | the_limit, no_limit, parser); |
| 2627 | Fsetcdr (parent, Fnreverse (Fcdr (parent))); | 2638 | Fsetcdr (parent, Fnreverse (Fcdr (parent))); |
| 2628 | if (NILP (Fcdr (parent))) | 2639 | if (NILP (Fcdr (parent))) |
| 2629 | return Qnil; | 2640 | return Qnil; |
diff --git a/src/treesit.h b/src/treesit.h index ebde6ccf673..e609ad46b07 100644 --- a/src/treesit.h +++ b/src/treesit.h | |||
| @@ -58,7 +58,7 @@ struct Lisp_TS_Parser | |||
| 58 | ptrdiff_t visible_beg; | 58 | ptrdiff_t visible_beg; |
| 59 | ptrdiff_t visible_end; | 59 | ptrdiff_t visible_end; |
| 60 | /* This counter is incremented every time a change is made to the | 60 | /* This counter is incremented every time a change is made to the |
| 61 | buffer in ts_record_change. The node retrieved from this parser | 61 | buffer in treesit_record_change. The node retrieved from this parser |
| 62 | inherits this timestamp. This way we can make sure the node is | 62 | inherits this timestamp. This way we can make sure the node is |
| 63 | not outdated when we access its information. */ | 63 | not outdated when we access its information. */ |
| 64 | ptrdiff_t timestamp; | 64 | ptrdiff_t timestamp; |
| @@ -170,19 +170,19 @@ CHECK_TS_COMPILED_QUERY (Lisp_Object query) | |||
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | void | 172 | void |
| 173 | ts_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, | 173 | treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte, |
| 174 | ptrdiff_t new_end_byte); | 174 | ptrdiff_t new_end_byte); |
| 175 | 175 | ||
| 176 | Lisp_Object | 176 | Lisp_Object |
| 177 | make_ts_parser (Lisp_Object buffer, TSParser *parser, | 177 | make_treesit_parser (Lisp_Object buffer, TSParser *parser, |
| 178 | TSTree *tree, Lisp_Object language_symbol); | 178 | TSTree *tree, Lisp_Object language_symbol); |
| 179 | 179 | ||
| 180 | Lisp_Object | 180 | Lisp_Object |
| 181 | make_ts_node (Lisp_Object parser, TSNode node); | 181 | make_treesit_node (Lisp_Object parser, TSNode node); |
| 182 | 182 | ||
| 183 | extern void ts_delete_parser (struct Lisp_TS_Parser *); | 183 | extern void treesit_delete_parser (struct Lisp_TS_Parser *); |
| 184 | extern void ts_delete_query (struct Lisp_TS_Query *); | 184 | extern void treesit_delete_query (struct Lisp_TS_Query *); |
| 185 | extern bool ts_named_node_p (TSNode); | 185 | extern bool treesit_named_node_p (TSNode); |
| 186 | 186 | ||
| 187 | extern void syms_of_treesit (void); | 187 | extern void syms_of_treesit (void); |
| 188 | 188 | ||