Path: blob/main/editors/emacs/files/patch-src_treesit.c
46591 views
--- src/treesit.c.orig 2025-07-05 09:56:00 UTC1+++ src/treesit.c2@@ -415,17 +415,17 @@ static Lisp_Object Vtreesit_str_plus;3static Lisp_Object Vtreesit_str_question_mark;4static Lisp_Object Vtreesit_str_star;5static Lisp_Object Vtreesit_str_plus;6-static Lisp_Object Vtreesit_str_pound_equal;7-static Lisp_Object Vtreesit_str_pound_match;8-static Lisp_Object Vtreesit_str_pound_pred;9+static Lisp_Object Vtreesit_str_pound_eq_question_mark;10+static Lisp_Object Vtreesit_str_pound_match_question_mark;11+static Lisp_Object Vtreesit_str_pound_pred_question_mark;12static Lisp_Object Vtreesit_str_open_bracket;13static Lisp_Object Vtreesit_str_close_bracket;14static Lisp_Object Vtreesit_str_open_paren;15static Lisp_Object Vtreesit_str_close_paren;16static Lisp_Object Vtreesit_str_space;17-static Lisp_Object Vtreesit_str_equal;18-static Lisp_Object Vtreesit_str_match;19-static Lisp_Object Vtreesit_str_pred;20+static Lisp_Object Vtreesit_str_eq_question_mark;21+static Lisp_Object Vtreesit_str_match_question_mark;22+static Lisp_Object Vtreesit_str_pred_question_mark;23static Lisp_Object Vtreesit_str_empty;2425/* This is the limit on recursion levels for some tree-sitter26@@ -632,6 +632,22 @@ treesit_load_language_push_for_each_suffix (Lisp_Objec27}28}2930+/* This function is a compatibility shim. Tree-sitter 0.25 introduced31+ ts_language_abi_version as a replacement for ts_language_version, and32+ tree-sitter 0.26 removed ts_language_version. Here we use the fact33+ that 0.25 bumped TREE_SITTER_LANGUAGE_VERSION to 15, to use the new34+ function instead of the old one, when Emacs is compiled against35+ tree-sitter version 0.25 or newer. */36+static uint32_t37+treesit_language_abi_version (const TSLanguage *ts_lang)38+{39+#if TREE_SITTER_LANGUAGE_VERSION >= 1540+ return ts_language_abi_version (ts_lang);41+#else42+ return ts_language_version (ts_lang);43+#endif44+}45+46/* Load the dynamic library of LANGUAGE_SYMBOL and return the pointer47to the language definition.4849@@ -746,7 +762,7 @@ treesit_load_language (Lisp_Object language_symbol,50{51*signal_symbol = Qtreesit_load_language_error;52*signal_data = list2 (Qversion_mismatch,53- make_fixnum (ts_language_version (lang)));54+ make_fixnum (treesit_language_abi_version (lang)));55return NULL;56}57return lang;58@@ -817,7 +833,7 @@ Return nil if a grammar library for LANGUAGE is not av59&signal_data);60if (ts_language == NULL)61return Qnil;62- uint32_t version = ts_language_version (ts_language);63+ uint32_t version = treesit_language_abi_version (ts_language);64return make_fixnum((ptrdiff_t) version);65}66}67@@ -2604,12 +2620,12 @@ See Info node `(elisp)Pattern Matching' for detailed e68return Vtreesit_str_star;69if (BASE_EQ (pattern, QCplus))70return Vtreesit_str_plus;71- if (BASE_EQ (pattern, QCequal))72- return Vtreesit_str_pound_equal;73- if (BASE_EQ (pattern, QCmatch))74- return Vtreesit_str_pound_match;75- if (BASE_EQ (pattern, QCpred))76- return Vtreesit_str_pound_pred;77+ if (BASE_EQ (pattern, QCequal) || BASE_EQ (pattern, QCeq_q))78+ return Vtreesit_str_pound_eq_question_mark;79+ if (BASE_EQ (pattern, QCmatch) || BASE_EQ (pattern, QCmatch_q))80+ return Vtreesit_str_pound_match_question_mark;81+ if (BASE_EQ (pattern, QCpred) || BASE_EQ (pattern, QCpred_q))82+ return Vtreesit_str_pound_pred_question_mark;83Lisp_Object opening_delimeter84= VECTORP (pattern)85? Vtreesit_str_open_bracket : Vtreesit_str_open_paren;86@@ -2640,7 +2656,9 @@ A PATTERN in QUERY can be87:*88:+89:equal90+ :eq?91:match92+ :match?93(TYPE PATTERN...)94[PATTERN...]95FIELD-NAME:96@@ -2803,7 +2821,7 @@ treesit_predicate_equal (Lisp_Object args, struct capt97return !NILP (Fstring_equal (text1, text2));98}99100-/* Handles predicate (#match "regexp" @node). Return true if "regexp"101+/* Handles predicate (#match? "regexp" @node). Return true if "regexp"102matches the text spanned by @node; return false otherwise.103Matching is case-sensitive. If everything goes fine, don't touch104SIGNAL_DATA; if error occurs, set it to a suitable signal data. */105@@ -2813,26 +2831,24 @@ treesit_predicate_match (Lisp_Object args, struct capt106{107if (list_length (args) != 2)108{109- *signal_data = list2 (build_string ("Predicate `match' requires two "110+ *signal_data = list2 (build_string ("Predicate `match?' requires two "111"arguments but got"),112Flength (args));113return false;114}115- Lisp_Object regexp = XCAR (args);116- Lisp_Object capture_name = XCAR (XCDR (args));117+ Lisp_Object arg1 = XCAR (args);118+ Lisp_Object arg2 = XCAR (XCDR (args));119+ Lisp_Object regexp = SYMBOLP (arg2) ? arg1 : arg2;120+ Lisp_Object capture_name = SYMBOLP (arg2) ? arg2 : arg1;121122- /* It's probably common to get the argument order backwards. Catch123- this mistake early and show helpful explanation, because Emacs124- loves you. (We put the regexp first because that's what125- string-match does.) */126- if (!STRINGP (regexp))127- xsignal1 (Qtreesit_query_error,128- build_string ("The first argument to `match' should "129- "be a regexp string, not a capture name"));130- if (!SYMBOLP (capture_name))131- xsignal1 (Qtreesit_query_error,132- build_string ("The second argument to `match' should "133- "be a capture name, not a string"));134+ if (!STRINGP (regexp) || !SYMBOLP (capture_name))135+ {136+ *signal_data = list2 (build_string ("Predicate `match?' takes a regexp "137+ "and a node capture (order doesn't "138+ "matter), but got"),139+ Flength (args));140+ return false;141+ }142143Lisp_Object node = Qnil;144if (!treesit_predicate_capture_name_to_node (capture_name, captures, &node,145@@ -2916,11 +2932,11 @@ treesit_eval_predicates (struct capture_range captures146Lisp_Object predicate = XCAR (tail);147Lisp_Object fn = XCAR (predicate);148Lisp_Object args = XCDR (predicate);149- if (!NILP (Fstring_equal (fn, Vtreesit_str_equal)))150+ if (!NILP (Fstring_equal (fn, Vtreesit_str_eq_question_mark)))151pass &= treesit_predicate_equal (args, captures, signal_data);152- else if (!NILP (Fstring_equal (fn, Vtreesit_str_match)))153+ else if (!NILP (Fstring_equal (fn, Vtreesit_str_match_question_mark)))154pass &= treesit_predicate_match (args, captures, signal_data);155- else if (!NILP (Fstring_equal (fn, Vtreesit_str_pred)))156+ else if (!NILP (Fstring_equal (fn, Vtreesit_str_pred_question_mark)))157pass &= treesit_predicate_pred (args, captures, signal_data);158else159{160@@ -4192,8 +4208,11 @@ syms_of_treesit (void)161DEFSYM (QCstar, ":*");162DEFSYM (QCplus, ":+");163DEFSYM (QCequal, ":equal");164+ DEFSYM (QCeq_q, ":eq?");165DEFSYM (QCmatch, ":match");166+ DEFSYM (QCmatch_q, ":match?");167DEFSYM (QCpred, ":pred");168+ DEFSYM (QCpred_q, ":pred?");169170DEFSYM (Qnot_found, "not-found");171DEFSYM (Qsymbol_error, "symbol-error");172@@ -4324,12 +4343,12 @@ the symbol of that THING. For example, (or sexp sente173Vtreesit_str_star = build_pure_c_string ("*");174staticpro (&Vtreesit_str_plus);175Vtreesit_str_plus = build_pure_c_string ("+");176- staticpro (&Vtreesit_str_pound_equal);177- Vtreesit_str_pound_equal = build_pure_c_string ("#equal");178- staticpro (&Vtreesit_str_pound_match);179- Vtreesit_str_pound_match = build_pure_c_string ("#match");180- staticpro (&Vtreesit_str_pound_pred);181- Vtreesit_str_pound_pred = build_pure_c_string ("#pred");182+ staticpro (&Vtreesit_str_pound_eq_question_mark);183+ Vtreesit_str_pound_eq_question_mark = build_pure_c_string ("#eq?");184+ staticpro (&Vtreesit_str_pound_match_question_mark);185+ Vtreesit_str_pound_match_question_mark = build_pure_c_string ("#match?");186+ staticpro (&Vtreesit_str_pound_pred_question_mark);187+ Vtreesit_str_pound_pred_question_mark = build_pure_c_string ("#pred?");188staticpro (&Vtreesit_str_open_bracket);189Vtreesit_str_open_bracket = build_pure_c_string ("[");190staticpro (&Vtreesit_str_close_bracket);191@@ -4340,12 +4359,12 @@ the symbol of that THING. For example, (or sexp sente192Vtreesit_str_close_paren = build_pure_c_string (")");193staticpro (&Vtreesit_str_space);194Vtreesit_str_space = build_pure_c_string (" ");195- staticpro (&Vtreesit_str_equal);196- Vtreesit_str_equal = build_pure_c_string ("equal");197- staticpro (&Vtreesit_str_match);198- Vtreesit_str_match = build_pure_c_string ("match");199- staticpro (&Vtreesit_str_pred);200- Vtreesit_str_pred = build_pure_c_string ("pred");201+ staticpro (&Vtreesit_str_eq_question_mark);202+ Vtreesit_str_eq_question_mark = build_pure_c_string ("eq?");203+ staticpro (&Vtreesit_str_match_question_mark);204+ Vtreesit_str_match_question_mark = build_pure_c_string ("match?");205+ staticpro (&Vtreesit_str_pred_question_mark);206+ Vtreesit_str_pred_question_mark = build_pure_c_string ("pred?");207staticpro (&Vtreesit_str_empty);208Vtreesit_str_empty = build_pure_c_string ("");209210211212