aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2024-07-24 11:41:58 +0800
committerPo Lu2024-07-24 11:41:58 +0800
commit6d22bd4d3a0a9cb55bbfffb29ed3e3190c63b565 (patch)
tree16d76ac65a47a7fef96bee8f3c528cfff234a26a /src
parent19a18e487b8e2f0c1627b9cc98e601327e884eb2 (diff)
parentc66bda1a19afd7d8391765e2ed207e44107d8a50 (diff)
downloademacs-6d22bd4d3a0a9cb55bbfffb29ed3e3190c63b565.tar.gz
emacs-6d22bd4d3a0a9cb55bbfffb29ed3e3190c63b565.zip
Merge from savannah/emacs-30
c66bda1a19a Improve treesit-node-child-by-field-name docstring 85773ab9771 Minor copyedits in tree-sitter starting guide 2dacec1609a Update tag for prebuilt tree-sitter grammars 68615a38669 Fix punctuation and doc style in treesit.c 00adee897ac ; Fix punctuation in docs ab29b28d4ba Fix DocView with PostScript files
Diffstat (limited to 'src')
-rw-r--r--src/treesit.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/treesit.c b/src/treesit.c
index c95a9fb9b01..baa1b8dfd11 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -404,7 +404,7 @@ init_treesit_functions (void)
404 buffer's parser list. The discussion can be found in bug#59693. */ 404 buffer's parser list. The discussion can be found in bug#59693. */
405 405
406 406
407/*** Initialization */ 407/*** Initialization */
408 408
409static Lisp_Object Vtreesit_str_libtree_sitter; 409static Lisp_Object Vtreesit_str_libtree_sitter;
410static Lisp_Object Vtreesit_str_tree_sitter; 410static Lisp_Object Vtreesit_str_tree_sitter;
@@ -431,7 +431,7 @@ static Lisp_Object Vtreesit_str_pred;
431 functions. Remember to update docstrings when changing this value. 431 functions. Remember to update docstrings when changing this value.
432 432
433 If we think of programs and AST, it is very rare for any program to 433 If we think of programs and AST, it is very rare for any program to
434 have a very deep AST. For example, you would need 1000+ levels of 434 have a very deep AST. For example, you would need 1000+ levels of
435 nested if-statements, or a struct somehow nested for 1000+ levels. 435 nested if-statements, or a struct somehow nested for 1000+ levels.
436 It's hard for me to imagine any hand-written or machine generated 436 It's hard for me to imagine any hand-written or machine generated
437 program to be like that. So I think 1000 is already generous. If 437 program to be like that. So I think 1000 is already generous. If
@@ -485,10 +485,9 @@ treesit_initialize (void)
485} 485}
486 486
487 487
488/*** Loading language library */ 488/*** Loading language library */
489 489
490/* Translates a symbol treesit-<lang> to a C name 490/* Translate a symbol treesit-<lang> to a C name treesit_<lang>. */
491 treesit_<lang>. */
492static void 491static void
493treesit_symbol_to_c_name (char *symbol_name) 492treesit_symbol_to_c_name (char *symbol_name)
494{ 493{
@@ -758,7 +757,7 @@ Return nil if a grammar library for LANGUAGE is not available. */)
758} 757}
759 758
760 759
761/*** Parsing functions */ 760/*** Parsing functions */
762 761
763static void 762static void
764treesit_check_parser (Lisp_Object obj) 763treesit_check_parser (Lisp_Object obj)
@@ -873,7 +872,7 @@ treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte,
873 } 872 }
874} 873}
875 874
876/* Comment (ref:visible-beg-null) The purpose of visible_beg/end is to 875/* Comment (ref:visible-beg-null) The purpose of visible_beg/end is to
877 keep track of "which part of the buffer does the tree-sitter tree 876 keep track of "which part of the buffer does the tree-sitter tree
878 see", in order to update the tree correctly. Visible_beg/end have 877 see", in order to update the tree correctly. Visible_beg/end have
879 two purposes: they "clip" buffer changes within them, and they 878 two purposes: they "clip" buffer changes within them, and they
@@ -1150,7 +1149,7 @@ treesit_read_buffer (void *parser, uint32_t byte_index,
1150} 1149}
1151 1150
1152 1151
1153/*** Functions for parser and node object */ 1152/*** Functions for parser and node object */
1154 1153
1155/* Wrap the parser in a Lisp_Object to be used in the Lisp 1154/* Wrap the parser in a Lisp_Object to be used in the Lisp
1156 machine. */ 1155 machine. */
@@ -1575,7 +1574,7 @@ treesit_parser_live_p (Lisp_Object parser)
1575} 1574}
1576 1575
1577 1576
1578/*** Parser API */ 1577/*** Parser API */
1579 1578
1580DEFUN ("treesit-parser-root-node", 1579DEFUN ("treesit-parser-root-node",
1581 Ftreesit_parser_root_node, Streesit_parser_root_node, 1580 Ftreesit_parser_root_node, Streesit_parser_root_node,
@@ -1748,7 +1747,7 @@ See also `treesit-parser-set-included-ranges'. */)
1748 1747
1749 /* When the parser doesn't have a range set and we call 1748 /* When the parser doesn't have a range set and we call
1750 ts_parser_included_ranges on it, it doesn't return an empty list, 1749 ts_parser_included_ranges on it, it doesn't return an empty list,
1751 but rather return DEFAULT_RANGE. (A single range where start_byte 1750 but rather return DEFAULT_RANGE. (A single range where start_byte
1752 = 0, end_byte = UINT32_MAX). So we need to track whether the 1751 = 0, end_byte = UINT32_MAX). So we need to track whether the
1753 parser is ranged ourselves. */ 1752 parser is ranged ourselves. */
1754 if (NILP (XTS_PARSER (parser)->last_set_ranges)) 1753 if (NILP (XTS_PARSER (parser)->last_set_ranges))
@@ -1851,8 +1850,8 @@ treesit_check_node (Lisp_Object obj)
1851 xsignal1 (Qtreesit_node_buffer_killed, obj); 1850 xsignal1 (Qtreesit_node_buffer_killed, obj);
1852} 1851}
1853 1852
1854/* Checks that OBJ is a positive integer and it is within the visible 1853/* Check that OBJ is a positive integer and it is within the visible
1855 portion of BUF. */ 1854 portion of BUF. */
1856static void 1855static void
1857treesit_check_position (Lisp_Object obj, struct buffer *buf) 1856treesit_check_position (Lisp_Object obj, struct buffer *buf)
1858{ 1857{
@@ -2147,7 +2146,7 @@ nil. If NODE is nil, return nil. */)
2147DEFUN ("treesit-node-child-by-field-name", 2146DEFUN ("treesit-node-child-by-field-name",
2148 Ftreesit_node_child_by_field_name, 2147 Ftreesit_node_child_by_field_name,
2149 Streesit_node_child_by_field_name, 2, 2, 0, 2148 Streesit_node_child_by_field_name, 2, 2, 0,
2150 doc: /* Return the child of NODE with FIELD-NAME. 2149 doc: /* Return the child of NODE with FIELD-NAME (a string).
2151Return nil if there is no such child. If NODE is nil, return nil. */) 2150Return nil if there is no such child. If NODE is nil, return nil. */)
2152 (Lisp_Object node, Lisp_Object field_name) 2151 (Lisp_Object node, Lisp_Object field_name)
2153{ 2152{
@@ -2368,7 +2367,7 @@ produced by tree-sitter. */)
2368} 2367}
2369 2368
2370 2369
2371/*** Query functions */ 2370/*** Query functions */
2372 2371
2373/* Convert a Lisp string to its printed representation in the tree-sitter 2372/* Convert a Lisp string to its printed representation in the tree-sitter
2374 query syntax. */ 2373 query syntax. */
@@ -3005,7 +3004,7 @@ the query. */)
3005 test for predicates. If predicates pass, then all good, if 3004 test for predicates. If predicates pass, then all good, if
3006 predicates don't pass, revert the result back to the result 3005 predicates don't pass, revert the result back to the result
3007 before this loop (PREV_RESULT). (Predicates control the entire 3006 before this loop (PREV_RESULT). (Predicates control the entire
3008 match.) This way we don't need to create a list of captures in 3007 match.) This way we don't need to create a list of captures in
3009 every for loop and nconc it to RESULT every time. That is indeed 3008 every for loop and nconc it to RESULT every time. That is indeed
3010 the initial implementation in which Yoav found nconc being the 3009 the initial implementation in which Yoav found nconc being the
3011 bottleneck (98.4% of the running time spent on nconc). */ 3010 bottleneck (98.4% of the running time spent on nconc). */
@@ -3083,7 +3082,7 @@ the query. */)
3083} 3082}
3084 3083
3085 3084
3086/*** Navigation */ 3085/*** Navigation */
3087 3086
3088static inline void 3087static inline void
3089treesit_assume_true (bool val) 3088treesit_assume_true (bool val)
@@ -3200,7 +3199,7 @@ treesit_traverse_sibling_helper (TSTreeCursor *cursor,
3200 if (ts_node_eq (first_child, start)) 3199 if (ts_node_eq (first_child, start))
3201 return false; 3200 return false;
3202 3201
3203 /* PROBE is always DELTA siblings ahead of CURSOR. */ 3202 /* PROBE is always DELTA siblings ahead of CURSOR. */
3204 TSTreeCursor probe = ts_tree_cursor_copy (cursor); 3203 TSTreeCursor probe = ts_tree_cursor_copy (cursor);
3205 /* This is position of PROBE minus position of CURSOR. */ 3204 /* This is position of PROBE minus position of CURSOR. */
3206 ptrdiff_t delta = 0; 3205 ptrdiff_t delta = 0;
@@ -3484,7 +3483,7 @@ treesit_traverse_match_predicate (TSTreeCursor *cursor, Lisp_Object pred,
3484 return true; 3483 return true;
3485 } 3484 }
3486 } 3485 }
3487 /* Returning false is better than UB. */ 3486 /* Returning false is better than UB. */
3488 return false; 3487 return false;
3489} 3488}
3490 3489
@@ -3997,7 +3996,7 @@ DEFUN ("treesit-available-p", Ftreesit_available_p,
3997} 3996}
3998 3997
3999 3998
4000/*** Initialization */ 3999/*** Initialization */
4001 4000
4002/* Initialize the tree-sitter routines. */ 4001/* Initialize the tree-sitter routines. */
4003void 4002void