From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: How to add pseudo vector types Date: Thu, 29 Jul 2021 10:35:10 -0400 Message-ID: References: <83h7gw6pyj.fsf@gnu.org> <46BBFF88-76C3-4818-8805-5437409BEA93@gmail.com> <83wnpq46uk.fsf@gnu.org> <533BD53B-4E85-4E9E-B46A-346A5BBAD0F5@gmail.com> <258CB68D-1CC1-42C8-BDCD-2A8A8099B783@gmail.com> <1a776770-50b7-93cd-6591-c9a5b3a56eb8@gmail.com> <8335s64v10.fsf@gnu.org> <5380C92B-6C15-4490-A1E0-1C3132DBB16A@gmail.com> <83k0li2shw.fsf@gnu.org> <86wnpg82v3.fsf@stephe-leake.org> <83lf5wyn0z.fsf@gnu.org> <86pmv66yqg.fsf@stephe-leake.org> <83a6maw705.fsf@gnu.org> <83r1fluikh.fsf@gnu.org> <88007ACB-31E5-440F-876D-9F43C8EE02CC@gmail.com> <86fsw05lom.fsf@stephe-leake.org> <8A3823DD-5D5A-4A33-8EF9-93F05497CE4C@gmail.com> <864kcf5cmv.fsf_-_@stephe-leake.org> <18D745F5-DBB1-46CC-91D3-4ADAA9D37AB9@gmail.com> <834kcetmly.fsf@gnu.org> <831r7itjc8.fsf@gnu.org> <24808548-23F4-4068-877E-37C7190A02B0@gmail.com> <83wnpas1q7.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_F1BE1A5A-CFA3-48AC-B229-73A2EF7F336F" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7498"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?Q?Cl=C3=A9ment_Pit-Claudel?= , Stephen Leake , Stefan Monnier , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Jul 29 16:36:18 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m978y-0001mS-Pl for ged-emacs-devel@m.gmane-mx.org; Thu, 29 Jul 2021 16:36:16 +0200 Original-Received: from localhost ([::1]:58284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m978x-0003HB-Gl for ged-emacs-devel@m.gmane-mx.org; Thu, 29 Jul 2021 10:36:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9781-0002GG-4b for emacs-devel@gnu.org; Thu, 29 Jul 2021 10:35:17 -0400 Original-Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]:33487) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m977y-00063J-If; Thu, 29 Jul 2021 10:35:16 -0400 Original-Received: by mail-qk1-x72c.google.com with SMTP id t66so6202548qkb.0; Thu, 29 Jul 2021 07:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=6bhjJ4Ca3Jc6kSn1brX5tXxjhA6RNY7WLxZhH/o99Rw=; b=Gm6sod/EKwZaSGdHSNW854LStG76151bVQshe1Cbg1hyz5Q9UBXcQgTPoBf5tdw/Ev RxKFlEWe2vxoC5m4LP1ZcyGeBXwTG6ASgfJsmD5NZ2O3r6R6b2BFVC+mGOT8wjpEVjeA 8ZXqUXVlI1hQgsi26R+TrT2hY16hYuuwVruYpvNAG4XsxMKlToZitRlW1Af1MoQqT2Hh HssULSVIoprizjkC76dPX2XIYlmPsuqttlWSCZX9sCMUnVs6dUj5x8aU8G4PHRKkAmT0 UiTjzyu3gc+9pQYLeQV96QsloimRZLzPAjWasXGAIjN+jxgHfcTo6KzNUsva1MekW+U7 ZGog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=6bhjJ4Ca3Jc6kSn1brX5tXxjhA6RNY7WLxZhH/o99Rw=; b=Q/H8I+JewNOsPwcYDHN1j8HWWc5o9vVNn9Pnm7cGwZ/YfOQ9C8h+bcyPyycFTOghLt 5nyXFlrnw4IE7y/qst2r7XCM86gKHj8OmDS7g5W9XTrx2UIYVmzu/NqSbBxYKU2slfLK 8dU9Xq5AsL31VX5mykQ2r6k4WQLdzeUh+IctR5+rq24uP0nyxfG2Ak/hh4sy54OhpOik xrvPhGSdsakAwCXBVaJ9jL6zj6rud/ktLRIFyCtdpq9oNOvIrpASko6AM4StQVr6GoFP u9CvdRwVuC499cOcw4EylmyrJBQZ6y1fjYLHKDneNMPO2Zt7DDGyECSvKfkpsUWP4xQQ Gpxg== X-Gm-Message-State: AOAM5301VbrHO2Qez/vQmNIFgdCBG23T92Ua2x7oKsP4Pu8vpHncLmb4 n3fTsvnR7+ac1aEEYVrKx+qR9Dt60wN4Tw== X-Google-Smtp-Source: ABdhPJxVB4Yw/90MTpAuOu6LETJYPdVIN3OaY47mz4AV6Vqrkclx2lHn1z12IrPOJ56pHdEnEnWCbw== X-Received: by 2002:a37:9ace:: with SMTP id c197mr5285323qke.461.1627569312855; Thu, 29 Jul 2021 07:35:12 -0700 (PDT) Original-Received: from 2603-7080-0302-635e-540d-2222-3fe9-1314.res6.spectrum.com (2603-7080-0302-635e-540d-2222-3fe9-1314.res6.spectrum.com. [2603:7080:302:635e:540d:2222:3fe9:1314]) by smtp.gmail.com with ESMTPSA id o27sm1761406qkk.124.2021.07.29.07.35.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jul 2021 07:35:12 -0700 (PDT) In-Reply-To: <83wnpas1q7.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.60.0.2.21) Received-SPF: pass client-ip=2607:f8b0:4864:20::72c; envelope-from=casouri@gmail.com; helo=mail-qk1-x72c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:271789 Archived-At: --Apple-Mail=_F1BE1A5A-CFA3-48AC-B229-73A2EF7F336F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 >>=20 >> That makes sense. However it bring up a problem. Consider such a = buffer: XXAAXX. Say lisp narrows to AA and creates a tree-sitter parser. = Then lisp widens the buffer, and user inserts B in front of AA. Now the = buffer is XXBAAXX. Emacs has two options to convey this change to the = tree-sitter parser: 1) it does not, then tree-sitter still thinks the = buffer is AA, essentially the portion where tree-sitter sees is pushed = forward by one character, 2) it tells tree-sitter the user inserted a = character at the beginning, then tree-sitter thinks the buffer is BAA. = Which option is correct depends on how does lisp later narrows: if lisp = narrows to AA, then option 1 is correct, if lisp narrows to BAA, then = option 2 is correct. But how do we know which option is correct before = lisp narrows? >=20 > We don't need to know. The Lisp program which needs to handle this > situation will have to figure out what is right in that case, "right" > in the sense that it produces the desired results after communicating > the changes to TS. The difficulty is that what tree-sitter sees must be consistent. If = Emacs updates tree-sitter with option 1 and lisp later choose option 2, = the content that tree-sitter sees is not consistent. Anyway, I found a = way that avoids this issue: the bounds of tree-sitter=E2=80=99s visible = region never changes, and the next time when lisp narrows to a different = region, we update tree-sitter=E2=80=99s bound to match that of the = narrowing. Here is the latest patch. If the code is not entirely = straightforward, I=E2=80=99m happy to add more comment to explain it. I set up a linux machine and tried to debug the crashing problem, but it = didn=E2=80=99t crash. Seems the crash only appears on my Mac... Yuan --Apple-Mail=_F1BE1A5A-CFA3-48AC-B229-73A2EF7F336F Content-Disposition: attachment; filename=ts.5.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="ts.5.patch" Content-Transfer-Encoding: quoted-printable =46rom=2062fc019a7f57119329d53b9b8a3e8b5c1e61b27f=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Yuan=20Fu=20=0ADate:=20Wed,=20= 28=20Jul=202021=2021:08:43=20-0400=0ASubject:=20[PATCH]=20checkpoint=205=0A= =0A-=20Move=20define_error=20out=20of=20json.c=0A-=20Add=20narrowing=20= support=0A---=0A=20lisp/tree-sitter.el=20=20=20=20=20=20=20=20=20=20=20|=20= =2011=20+-=0A=20src/eval.c=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20|=20=2013=20++=0A=20src/json.c=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20|=20=2016=20---=0A=20src/lisp.h=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20=20=205=20+=0A=20= src/tree_sitter.c=20=20=20=20=20=20=20=20=20=20=20=20=20|=20231=20= +++++++++++++++++++++++-----------=0A=20src/tree_sitter.h=20=20=20=20=20=20= =20=20=20=20=20=20=20|=20=2015=20++-=0A=20test/src/tree-sitter-tests.el=20= |=20=2053=20++++++++=0A=207=20files=20changed,=20251=20insertions(+),=20= 93=20deletions(-)=0A=0Adiff=20--git=20a/lisp/tree-sitter.el=20= b/lisp/tree-sitter.el=0Aindex=20a6ecb09386..8a887bb406=20100644=0A---=20= a/lisp/tree-sitter.el=0A+++=20b/lisp/tree-sitter.el=0A@@=20-102,12=20= +102,13=20@@=20tree-sitter-font-lock-settings=0A=20=0A=20PATTERN=20is=20= a=20tree-sitter=20query=20pattern.=20(See=20manual=20for=20how=20to=0A=20= write=20query=20patterns.)=20=20This=20pattern=20should=20capture=20= nodes=20with=0A-either=20face=20names=20or=20function=20names.=20=20If=20= captured=20with=20a=20face=0A-name,=20the=20node's=20corresponding=20= text=20in=20the=20buffer=20is=20fontified=0A-with=20that=20face;=20if=20= captured=20with=20a=20function=20name,=20the=20function=20is=0A-called=20= with=20three=20arguments,=20BEG=20END=20NODE,=20where=20BEG=20and=20END=0A= +either=20face=20symbols=20or=20function=20symbols.=20=20If=20captured=20= with=20a=20face=0A+symbol,=20the=20node's=20corresponding=20text=20in=20= the=20buffer=20is=20fontified=0A+with=20that=20face;=20if=20captured=20= with=20a=20function=20symbol,=20the=20function=0A+is=20called=20with=20= three=20arguments,=20BEG=20END=20NODE,=20where=20BEG=20and=20END=0A=20= marks=20the=20span=20of=20the=20corresponding=20text,=20and=20NODE=20is=20= the=20node=0A-itself.")=0A+itself.=20=20If=20a=20symbol=20is=20both=20a=20= face=20and=20a=20function,=20it=20is=20treated=0A+as=20a=20face.")=0A=20=0A= =20(defun=20tree-sitter-fontify-region-function=20(beg=20end=20&optional=20= verbose)=0A=20=20=20"Fontify=20the=20region=20between=20BEG=20and=20END.=0A= diff=20--git=20a/src/eval.c=20b/src/eval.c=0Aindex=20= 18faa0b9b1..33c0763f38=20100644=0A---=20a/src/eval.c=0A+++=20= b/src/eval.c=0A@@=20-1956,6=20+1956,19=20@@=20signal_error=20(const=20= char=20*s,=20Lisp_Object=20arg)=0A=20=20=20xsignal=20(Qerror,=20Fcons=20= (build_string=20(s),=20arg));=0A=20}=0A=20=0A+void=0A+define_error=20= (Lisp_Object=20name,=20const=20char=20*message,=20Lisp_Object=20parent)=0A= +{=0A+=20=20eassert=20(SYMBOLP=20(name));=0A+=20=20eassert=20(SYMBOLP=20= (parent));=0A+=20=20Lisp_Object=20parent_conditions=20=3D=20Fget=20= (parent,=20Qerror_conditions);=0A+=20=20eassert=20(CONSP=20= (parent_conditions));=0A+=20=20eassert=20(!NILP=20(Fmemq=20(parent,=20= parent_conditions)));=0A+=20=20eassert=20(NILP=20(Fmemq=20(name,=20= parent_conditions)));=0A+=20=20Fput=20(name,=20Qerror_conditions,=20= pure_cons=20(name,=20parent_conditions));=0A+=20=20Fput=20(name,=20= Qerror_message,=20build_pure_c_string=20(message));=0A+}=0A+=0A=20/*=20= Use=20this=20for=20arithmetic=20overflow,=20e.g.,=20when=20an=20integer=20= result=20is=0A=20=20=20=20too=20large=20even=20for=20a=20bignum.=20=20*/=0A= =20void=0Adiff=20--git=20a/src/json.c=20b/src/json.c=0Aindex=20= 3f1d27ad7f..ff28143a3c=20100644=0A---=20a/src/json.c=0A+++=20= b/src/json.c=0A@@=20-1098,22=20+1098,6=20@@=20DEFUN=20= ("json-parse-buffer",=20Fjson_parse_buffer,=20Sjson_parse_buffer,=0A=20=20= =20return=20unbind_to=20(count,=20lisp);=0A=20}=0A=20=0A-/*=20Simplified=20= version=20of=20'define-error'=20that=20works=20with=20pure=0A-=20=20=20= objects.=20=20*/=0A-=0A-static=20void=0A-define_error=20(Lisp_Object=20= name,=20const=20char=20*message,=20Lisp_Object=20parent)=0A-{=0A-=20=20= eassert=20(SYMBOLP=20(name));=0A-=20=20eassert=20(SYMBOLP=20(parent));=0A= -=20=20Lisp_Object=20parent_conditions=20=3D=20Fget=20(parent,=20= Qerror_conditions);=0A-=20=20eassert=20(CONSP=20(parent_conditions));=0A= -=20=20eassert=20(!NILP=20(Fmemq=20(parent,=20parent_conditions)));=0A-=20= =20eassert=20(NILP=20(Fmemq=20(name,=20parent_conditions)));=0A-=20=20= Fput=20(name,=20Qerror_conditions,=20pure_cons=20(name,=20= parent_conditions));=0A-=20=20Fput=20(name,=20Qerror_message,=20= build_pure_c_string=20(message));=0A-}=0A-=0A=20void=0A=20syms_of_json=20= (void)=0A=20{=0Adiff=20--git=20a/src/lisp.h=20b/src/lisp.h=0Aindex=20= e439447283..d30509b61a=20100644=0A---=20a/src/lisp.h=0A+++=20= b/src/lisp.h=0A@@=20-5127,6=20+5127,11=20@@=20maybe_gc=20(void)=0A=20=20=20= =20=20maybe_garbage_collect=20();=0A=20}=0A=20=0A+/*=20Simplified=20= version=20of=20'define-error'=20that=20works=20with=20pure=0A+=20=20=20= objects.=20=20*/=0A+void=0A+define_error=20(Lisp_Object=20name,=20const=20= char=20*message,=20Lisp_Object=20parent);=0A+=0A=20INLINE_HEADER_END=0A=20= =0A=20#endif=20/*=20EMACS_LISP_H=20*/=0Adiff=20--git=20= a/src/tree_sitter.c=20b/src/tree_sitter.c=0Aindex=20= e9f8ddc7e3..5e16df7758=20100644=0A---=20a/src/tree_sitter.c=0A+++=20= b/src/tree_sitter.c=0A@@=20-19,17=20+19,8=20@@=20Copyright=20(C)=202021=20= Free=20Software=20Foundation,=20Inc.=0A=20=0A=20#include=20=0A=20= =0A-#include=20=0A-#include=20=0A-#include=20= =0A-#include=20=0A-#include=20=0A= -#include=20=0A-#include=20=0A-=0A=20#include=20= "lisp.h"=0A=20#include=20"buffer.h"=0A-#include=20"coding.h"=0A=20= #include=20"tree_sitter.h"=0A=20=0A=20/*=20parser.h=20defines=20a=20= macro=20ADVANCE=20that=20conflicts=20with=20alloc.c.=20=20*/=0A@@=20= -61,6=20+52,16=20@@=20DEFUN=20("tree-sitter-node-p",=0A=20=0A=20/***=20= Parsing=20functions=20*/=0A=20=0A+static=20inline=20void=0A= +ts_tree_edit_1=20(TSTree=20*tree,=20ptrdiff_t=20start_byte,=0A+=09=09= ptrdiff_t=20old_end_byte,=20ptrdiff_t=20new_end_byte)=0A+{=0A+=20=20= TSPoint=20dummy_point=20=3D=20{0,=200};=0A+=20=20TSInputEdit=20edit=20=3D=20= {start_byte,=20old_end_byte,=20new_end_byte,=0A+=09=09=20=20=20=20=20=20= dummy_point,=20dummy_point,=20dummy_point};=0A+=20=20ts_tree_edit=20= (tree,=20&edit);=0A+}=0A+=0A=20/*=20Update=20each=20parser's=20tree=20= after=20the=20user=20made=20an=20edit.=20=20This=0A=20function=20does=20= not=20parse=20the=20buffer=20and=20only=20updates=20the=20tree.=20(So=20= it=0A=20should=20be=20very=20fast.)=20=20*/=0A@@=20-68,18=20+69,38=20@@=20= DEFUN=20("tree-sitter-node-p",=0A=20ts_record_change=20(ptrdiff_t=20= start_byte,=20ptrdiff_t=20old_end_byte,=0A=20=09=09=20=20ptrdiff_t=20= new_end_byte)=0A=20{=0A+=20=20eassert(start_byte=20<=3D=20old_end_byte);=0A= +=20=20eassert(start_byte=20<=3D=20new_end_byte);=0A+=0A=20=20=20= Lisp_Object=20parser_list=20=3D=20Fsymbol_value=20= (Qtree_sitter_parser_list);=0A-=20=20TSPoint=20dummy_point=20=3D=20{0,=20= 0};=0A-=20=20TSInputEdit=20edit=20=3D=20{start_byte,=20old_end_byte,=20= new_end_byte,=0A-=09=09=20=20=20=20=20=20dummy_point,=20dummy_point,=20= dummy_point};=0A+=0A=20=20=20while=20(!NILP=20(parser_list))=0A=20=20=20=20= =20{=0A=20=20=20=20=20=20=20Lisp_Object=20lisp_parser=20=3D=20Fcar=20= (parser_list);=0A=20=20=20=20=20=20=20TSTree=20*tree=20=3D=20XTS_PARSER=20= (lisp_parser)->tree;=0A=20=20=20=20=20=20=20if=20(tree=20!=3D=20NULL)=0A= -=09ts_tree_edit=20(tree,=20&edit);=0A-=20=20=20=20=20=20XTS_PARSER=20= (lisp_parser)->need_reparse=20=3D=20true;=0A-=20=20=20=20=20=20= parser_list=20=3D=20Fcdr=20(parser_list);=0A+=09{=0A+=09=20=20/*=20We=20= "clip"=20the=20change=20to=20between=20visible_beg=20and=0A+=09=20=20=20=20= =20visible_end.=20=20It=20is=20okay=20if=20visible_end=20ends=20up=20= larger=0A+=09=20=20=20=20=20than=20BUF_Z,=20tree-sitter=20only=20access=20= buffer=20text=20during=0A+=09=20=20=20=20=20re-parse,=20and=20we=20will=20= adjust=20visible_beg/end=20before=0A+=09=20=20=20=20=20re-parse.=20=20*/=0A= +=09=20=20ptrdiff_t=20visible_beg=20=3D=20XTS_PARSER=20= (lisp_parser)->visible_beg;=0A+=09=20=20ptrdiff_t=20visible_end=20=3D=20= XTS_PARSER=20(lisp_parser)->visible_end;=0A+=0A+=09=20=20ptrdiff_t=20= visible_start=20=3D=0A+=09=20=20=20=20max=20(visible_beg,=20start_byte)=20= -=20visible_beg;=0A+=09=20=20ptrdiff_t=20visible_old_end=20=3D=0A+=09=20=20= =20=20min=20(visible_end,=20old_end_byte)=20-=20visible_beg;=0A+=09=20=20= ptrdiff_t=20visible_new_end=20=3D=0A+=09=20=20=20=20min=20(visible_end,=20= new_end_byte)=20-=20visible_beg;=0A+=0A+=09=20=20ts_tree_edit_1=20(tree,=20= visible_start,=20visible_old_end,=0A+=09=09=09=20=20visible_new_end);=0A= +=09=20=20XTS_PARSER=20(lisp_parser)->need_reparse=20=3D=20true;=0A+=0A+=09= =20=20parser_list=20=3D=20Fcdr=20(parser_list);=0A+=09}=0A=20=20=20=20=20= }=0A=20}=0A=20=0A@@=20-93,16=20+114,67=20@@=20ts_ensure_parsed=20= (Lisp_Object=20parser)=0A=20=20=20TSParser=20*ts_parser=20=3D=20= XTS_PARSER=20(parser)->parser;=0A=20=20=20TSTree=20*tree=20=3D=20= XTS_PARSER(parser)->tree;=0A=20=20=20TSInput=20input=20=3D=20XTS_PARSER=20= (parser)->input;=0A+=20=20struct=20buffer=20*buffer=20=3D=20XTS_PARSER=20= (parser)->buffer;=0A+=0A+=20=20/*=20Before=20we=20parse,=20catch=20up=20= with=20the=20narrowing=20situation.=20=20We=0A+=20=20=20=20=20change=20= visible_beg=20and=20visible_end=20to=20match=20BUF_BEGV_BYTE=20and=0A+=20= =20=20=20=20BUF_ZV_BYTE,=20and=20inform=20tree-sitter=20of=20the=20= change.=20=20*/=0A+=20=20ptrdiff_t=20visible_beg=20=3D=20XTS_PARSER=20= (parser)->visible_beg;=0A+=20=20ptrdiff_t=20visible_end=20=3D=20= XTS_PARSER=20(parser)->visible_end;=0A+=20=20/*=20Before=20re-parse,=20= we=20want=20to=20move=20the=20visible=20range=20of=20tree-sitter=0A+=20=20= =20=20=20to=20matched=20the=20narrowed=20range.=20For=20example:=0A+=20=20= =20=20=20Move=20________|____|__=0A+=20=20=20=20=20to=20=20=20= |____|__________=20*/=0A+=0A+=20=20/*=201.=20Make=20sure=20visible_beg=20= <=3D=20BUF_BEGV_BYTE.=20=20*/=0A+=20=20if=20(visible_beg=20>=20= BUF_BEGV_BYTE=20(buffer))=0A+=20=20=20=20{=0A+=20=20=20=20=20=20/*=20= Tree-sitter=20sees:=20insert=20at=20the=20beginning.=20*/=0A+=20=20=20=20= =20=20ts_tree_edit_1=20(tree,=200,=200,=20visible_beg=20-=20= BUF_BEGV_BYTE=20(buffer));=0A+=20=20=20=20=20=20visible_beg=20=3D=20= BUF_BEGV_BYTE=20(buffer);=0A+=20=20=20=20}=0A+=20=20/*=202.=20Make=20= sure=20visible_end=20=3D=20BUF_ZV_BYTE.=20=20*/=0A+=20=20if=20= (visible_end=20<=20BUF_ZV_BYTE=20(buffer))=0A+=20=20=20=20{=0A+=20=20=20=20= =20=20/*=20Tree-sitter=20sees:=20insert=20at=20the=20end.=20=20*/=0A+=20=20= =20=20=20=20ts_tree_edit_1=20(tree,=20visible_end=20-=20visible_beg,=0A+=09= =09=20=20=20=20=20=20visible_end=20-=20visible_beg,=0A+=09=09=20=20=20=20= =20=20BUF_ZV_BYTE=20(buffer)=20-=20visible_beg);=0A+=20=20=20=20=20=20= visible_end=20=3D=20BUF_ZV_BYTE=20(buffer);=0A+=20=20=20=20}=0A+=20=20= else=20if=20(visible_end=20>=20BUF_ZV_BYTE=20(buffer))=0A+=20=20=20=20{=0A= +=20=20=20=20=20=20/*=20Tree-sitter=20sees:=20delete=20at=20the=20end.=20= =20*/=0A+=20=20=20=20=20=20ts_tree_edit_1=20(tree,=20BUF_ZV_BYTE=20= (buffer)=20-=20visible_beg,=0A+=09=09=20=20=20=20=20=20visible_end=20-=20= visible_beg,=0A+=09=09=20=20=20=20=20=20BUF_ZV_BYTE=20(buffer)=20-=20= visible_beg);=0A+=20=20=20=20=20=20visible_end=20=3D=20BUF_ZV_BYTE=20= (buffer);=0A+=20=20=20=20}=0A+=20=20/*=203.=20Make=20sure=20visible_beg=20= =3D=20BUF_BEGV_BYTE.=20=20*/=0A+=20=20if=20(visible_beg=20<=20= BUF_BEGV_BYTE=20(buffer))=0A+=20=20=20=20{=0A+=20=20=20=20=20=20/*=20= Tree-sitter=20sees:=20delete=20at=20the=20beginning.=20=20*/=0A+=20=20=20= =20=20=20ts_tree_edit_1=20(tree,=200,=20BUF_BEGV_BYTE=20(buffer)=20-=20= visible_beg,=200);=0A+=20=20=20=20=20=20visible_beg=20=3D=20= BUF_BEGV_BYTE=20(buffer);=0A+=20=20=20=20}=0A+=20=20XTS_PARSER=20= (parser)->visible_beg=20=3D=20visible_beg;=0A+=20=20XTS_PARSER=20= (parser)->visible_end=20=3D=20visible_end;=0A+=0A=20=20=20TSTree=20= *new_tree=20=3D=20ts_parser_parse(ts_parser,=20tree,=20input);=0A-=20=20= /*=20This=20should=20be=20very=20rare:=20it=20only=20happens=20when=201)=20= language=20is=20not=0A-=20=20=20=20=20set=20(impossible=20in=20Emacs=20= because=20the=20user=20has=20to=20supply=20a=0A-=20=20=20=20=20language=20= to=20create=20a=20parser),=202)=20parse=20canceled=20due=20to=20timeout=0A= -=20=20=20=20=20(impossible=20because=20we=20don't=20set=20a=20timeout),=20= 3)=20parse=20canceled=0A-=20=20=20=20=20due=20to=20cancellation=20flag=20= (impossible=20because=20we=20don't=20set=20the=0A-=20=20=20=20=20flag).=20= =20(See=20comments=20for=20ts_parser_parse=20in=0A+=20=20/*=20This=20= should=20be=20very=20rare=20(impossible,=20really):=20it=20only=20= happens=0A+=20=20=20=20=20when=201)=20language=20is=20not=20set=20= (impossible=20in=20Emacs=20because=20the=20user=0A+=20=20=20=20=20has=20= to=20supply=20a=20language=20to=20create=20a=20parser),=202)=20parse=20= canceled=0A+=20=20=20=20=20due=20to=20timeout=20(impossible=20because=20= we=20don't=20set=20a=20timeout),=203)=0A+=20=20=20=20=20parse=20canceled=20= due=20to=20cancellation=20flag=20(impossible=20because=20we=0A+=20=20=20=20= =20don't=20set=20the=20flag).=20=20(See=20comments=20for=20= ts_parser_parse=20in=0A=20=20=20=20=20=20tree_sitter/api.h.)=20=20*/=0A=20= =20=20if=20(new_tree=20=3D=3D=20NULL)=0A-=20=20=20=20signal_error=20= ("Parse=20failed",=20parser);=0A+=20=20=20=20{=0A+=20=20=20=20=20=20= Lisp_Object=20buf;=0A+=20=20=20=20=20=20XSETBUFFER(buf,=20buffer);=0A+=20= =20=20=20=20=20xsignal1=20(Qtree_sitter_parse_error,=20buf);=0A+=20=20=20= =20}=0A+=0A=20=20=20ts_tree_delete=20(tree);=0A=20=20=20XTS_PARSER=20= (parser)->tree=20=3D=20new_tree;=0A=20=20=20XTS_PARSER=20= (parser)->need_reparse=20=3D=20false;=0A@@=20-110,13=20+182,18=20@@=20= ts_ensure_parsed=20(Lisp_Object=20parser)=0A=20}=0A=20=0A=20/*=20This=20= is=20the=20read=20function=20provided=20to=20tree-sitter=20to=20read=20= from=20a=0A-=20=20=20buffer.=20=20It=20reads=20one=20character=20at=20a=20= time=20and=20automatically=20skip=0A+=20=20=20buffer.=20=20It=20reads=20= one=20character=20at=20a=20time=20and=20automatically=20skips=0A=20=20=20= =20the=20gap.=20=20*/=0A=20const=20char*=0A-ts_read_buffer=20(void=20= *buffer,=20uint32_t=20byte_index,=0A+ts_read_buffer=20(void=20*parser,=20= uint32_t=20byte_index,=0A=20=09=09TSPoint=20position,=20uint32_t=20= *bytes_read)=0A=20{=0A-=20=20ptrdiff_t=20byte_pos=20=3D=20byte_index=20+=20= 1;=0A+=20=20struct=20buffer=20*buffer=20=3D=20((struct=20Lisp_TS_Parser=20= *)=20parser)->buffer;=0A+=20=20ptrdiff_t=20visible_beg=20=3D=20((struct=20= Lisp_TS_Parser=20*)=20parser)->visible_beg;=0A+=20=20ptrdiff_t=20= byte_pos=20=3D=20byte_index=20+=20visible_beg;=0A+=20=20/*=20We=20will=20= make=20sure=20visible_beg=20>=3D=20BUF_BEG_BYTE=20before=20re-parse=20= (in=0A+=20=20=20=20=20ts_ensure_parsed),=20so=20byte_pos=20will=20never=20= be=20smaller=20than=0A+=20=20=20=20=20BUF_BEG_BYTE=20(unless=20= byte_index=20<=200).=20=20*/=0A=20=0A=20=20=20/*=20Read=20one=20= character.=20=20Tree-sitter=20wants=20us=20to=20set=20bytes_read=20to=20= 0=0A=20=20=20=20=20=20if=20it=20reads=20to=20the=20end=20of=20buffer.=20=20= It=20doesn't=20say=20what=20it=20wants=0A@@=20-126,26=20+203,26=20@@=20= ts_read_buffer=20(void=20*buffer,=20uint32_t=20byte_index,=0A=20=20=20= int=20len;=0A=20=20=20/*=20This=20function=20could=20run=20from=20a=20= user=20command,=20so=20it=20is=20better=20to=0A=20=20=20=20=20=20do=20= nothing=20instead=20of=20raising=20an=20error.=20(It=20was=20a=20pain=20= in=20the=20a**=0A-=20=20=20=20=20to=20read=20mega-if-conditions=20in=20= Emacs=20source,=20so=20I=20write=20the=20two=0A-=20=20=20=20=20branches=20= separately,=20hoping=20the=20compiler=20can=20merge=20them.)=20=20*/=0A-=20= =20if=20(!BUFFER_LIVE_P=20((struct=20buffer=20*)=20buffer))=0A+=20=20=20=20= =20to=20decrypt=20mega-if-conditions=20in=20Emacs=20source,=20so=20I=20= wrote=20the=20two=0A+=20=20=20=20=20branches=20separately.)=20=20*/=0A+=20= =20if=20(!BUFFER_LIVE_P=20(buffer))=0A=20=20=20=20=20{=0A=20=20=20=20=20=20= =20beg=20=3D=20"";=0A=20=20=20=20=20=20=20len=20=3D=200;=0A=20=20=20=20=20= }=0A-=20=20//=20TODO=20BUF_ZV_BYTE?=0A-=20=20else=20if=20(byte_pos=20>=3D=20= BUF_Z_BYTE=20((struct=20buffer=20*)=20buffer))=0A+=20=20/*=20Reached=20= visible=20end-of-buffer,=20tell=20tree-sitter=20to=20read=20no=20more.=20= =20*/=0A+=20=20else=20if=20(byte_pos=20>=3D=20BUF_ZV_BYTE=20(buffer))=0A=20= =20=20=20=20{=0A=20=20=20=20=20=20=20beg=20=3D=20"";=0A=20=20=20=20=20=20= =20len=20=3D=200;=0A=20=20=20=20=20}=0A+=20=20/*=20Normal=20case,=20read=20= a=20character.=20=20*/=0A=20=20=20else=0A=20=20=20=20=20{=0A=20=20=20=20=20= =20=20beg=20=3D=20(char=20*)=20BUF_BYTE_ADDRESS=20(buffer,=20byte_pos);=0A= -=20=20=20=20=20=20len=20=3D=20BYTES_BY_CHAR_HEAD=20((int)=20beg);=0A+=20= =20=20=20=20=20len=20=3D=20BYTES_BY_CHAR_HEAD=20((int)=20*beg);=0A=20=20=20= =20=20}=0A=20=20=20*bytes_read=20=3D=20(uint32_t)=20len;=0A-=0A=20=20=20= return=20beg;=0A=20}=0A=20=0A@@=20-158,13=20+235,16=20@@=20= make_ts_parser=20(struct=20buffer=20*buffer,=20TSParser=20*parser,=0A=20= {=0A=20=20=20struct=20Lisp_TS_Parser=20*lisp_parser=0A=20=20=20=20=20=3D=20= ALLOCATE_PSEUDOVECTOR=20(struct=20Lisp_TS_Parser,=20name,=20= PVEC_TS_PARSER);=0A+=0A=20=20=20lisp_parser->name=20=3D=20name;=0A=20=20=20= lisp_parser->buffer=20=3D=20buffer;=0A=20=20=20lisp_parser->parser=20=3D=20= parser;=0A=20=20=20lisp_parser->tree=20=3D=20tree;=0A-=20=20TSInput=20= input=20=3D=20{buffer,=20ts_read_buffer,=20TSInputEncodingUTF8};=0A+=20=20= TSInput=20input=20=3D=20{lisp_parser,=20ts_read_buffer,=20= TSInputEncodingUTF8};=0A=20=20=20lisp_parser->input=20=3D=20input;=0A=20=20= =20lisp_parser->need_reparse=20=3D=20true;=0A+=20=20= lisp_parser->visible_beg=20=3D=20BUF_BEGV=20(buffer);=0A+=20=20= lisp_parser->visible_end=20=3D=20BUF_ZV=20(buffer);=0A=20=20=20return=20= make_lisp_ptr=20(lisp_parser,=20Lisp_Vectorlike);=0A=20}=0A=20=0A@@=20= -287,7=20+367,7=20@@=20DEFUN=20("tree-sitter-parse-string",=0A=20=20=20= /*=20See=20comment=20in=20ts_ensure_parsed=20for=20possible=20reasons=20= for=20a=0A=20=20=20=20=20=20failure.=20=20*/=0A=20=20=20if=20(tree=20=3D=3D= =20NULL)=0A-=20=20=20=20signal_error=20("Failed=20to=20parse=20STRING",=20= string);=0A+=20=20=20=20xsignal1=20(Qtree_sitter_parse_error,=20string);=0A= =20=0A=20=20=20TSNode=20root_node=20=3D=20ts_tree_root_node=20(tree);=0A=20= =0A@@=20-535,7=20+615,9=20@@=20DEFUN=20= ("tree-sitter-node-first-child-for-byte",=0A=20{=0A=20=20=20= CHECK_INTEGER=20(pos);=0A=20=0A-=20=20struct=20buffer=20*buf=20=3D=20= (XTS_PARSER=20(XTS_NODE=20(node)->parser)->buffer);=0A+=20=20struct=20= buffer=20*buf=20=3D=20XTS_PARSER=20(XTS_NODE=20(node)->parser)->buffer;=0A= +=20=20ptrdiff_t=20visible_beg=20=3D=0A+=20=20=20=20XTS_PARSER=20= (XTS_NODE=20(node)->parser)->visible_beg;=0A=20=20=20ptrdiff_t=20= byte_pos=20=3D=20XFIXNUM=20(pos);=0A=20=0A=20=20=20if=20(byte_pos=20<=20= BUF_BEGV_BYTE=20(buf)=20||=20byte_pos=20>=20BUF_ZV_BYTE=20(buf))=0A@@=20= -544,9=20+626,10=20@@=20DEFUN=20= ("tree-sitter-node-first-child-for-byte",=0A=20=20=20TSNode=20ts_node=20= =3D=20XTS_NODE=20(node)->node;=0A=20=20=20TSNode=20child;=0A=20=20=20if=20= (NILP=20(named))=0A-=20=20=20=20child=20=3D=20= ts_node_first_child_for_byte=20(ts_node,=20byte_pos=20-=201);=0A+=20=20=20= =20child=20=3D=20ts_node_first_child_for_byte=20(ts_node,=20byte_pos=20-=20= visible_beg);=0A=20=20=20else=0A-=20=20=20=20child=20=3D=20= ts_node_first_named_child_for_byte=20(ts_node,=20byte_pos=20-=201);=0A+=20= =20=20=20child=20=3D=20ts_node_first_named_child_for_byte=0A+=20=20=20=20= =20=20(ts_node,=20byte_pos=20-=20visible_beg);=0A=20=0A=20=20=20if=20= (ts_node_is_null(child))=0A=20=20=20=20=20return=20Qnil;=0A@@=20-566,7=20= +649,9=20@@=20DEFUN=20("tree-sitter-node-descendant-for-byte-range",=0A=20= =20=20CHECK_INTEGER=20(beg);=0A=20=20=20CHECK_INTEGER=20(end);=0A=20=0A-=20= =20struct=20buffer=20*buf=20=3D=20(XTS_PARSER=20(XTS_NODE=20= (node)->parser)->buffer);=0A+=20=20struct=20buffer=20*buf=20=3D=20= XTS_PARSER=20(XTS_NODE=20(node)->parser)->buffer;=0A+=20=20ptrdiff_t=20= visible_beg=20=3D=0A+=20=20=20=20XTS_PARSER=20(XTS_NODE=20= (node)->parser)->visible_beg;=0A=20=20=20ptrdiff_t=20byte_beg=20=3D=20= XFIXNUM=20(beg);=0A=20=20=20ptrdiff_t=20byte_end=20=3D=20XFIXNUM=20= (end);=0A=20=0A@@=20-580,10=20+665,10=20@@=20DEFUN=20= ("tree-sitter-node-descendant-for-byte-range",=0A=20=20=20TSNode=20= child;=0A=20=20=20if=20(NILP=20(named))=0A=20=20=20=20=20child=20=3D=20= ts_node_descendant_for_byte_range=0A-=20=20=20=20=20=20(ts_node,=20= byte_beg=20-=201=20,=20byte_end=20-=201);=0A+=20=20=20=20=20=20(ts_node,=20= byte_beg=20-=20visible_beg=20,=20byte_end=20-=20visible_beg);=0A=20=20=20= else=0A=20=20=20=20=20child=20=3D=20= ts_node_named_descendant_for_byte_range=0A-=20=20=20=20=20=20(ts_node,=20= byte_beg=20-=201,=20byte_end=20-=201);=0A+=20=20=20=20=20=20(ts_node,=20= byte_beg=20-=20visible_beg,=20byte_end=20-=20visible_beg);=0A=20=0A=20=20= =20if=20(ts_node_is_null(child))=0A=20=20=20=20=20return=20Qnil;=0A@@=20= -593,31=20+678,24=20@@=20DEFUN=20= ("tree-sitter-node-descendant-for-byte-range",=0A=20=0A=20/*=20Query=20= functions=20*/=0A=20=0A-Lisp_Object=20ts_query_error_to_string=20= (TSQueryError=20error)=0A+char*=0A+ts_query_error_to_string=20= (TSQueryError=20error)=0A=20{=0A-=20=20char=20*error_name;=0A=20=20=20= switch=20(error)=0A=20=20=20=20=20{=0A=20=20=20=20=20case=20= TSQueryErrorNone:=0A-=20=20=20=20=20=20error_name=20=3D=20"none";=0A-=20=20= =20=20=20=20break;=0A+=20=20=20=20=20=20return=20"none";=0A=20=20=20=20=20= case=20TSQueryErrorSyntax:=0A-=20=20=20=20=20=20error_name=20=3D=20= "syntax";=0A-=20=20=20=20=20=20break;=0A+=20=20=20=20=20=20return=20= "syntax";=0A=20=20=20=20=20case=20TSQueryErrorNodeType:=0A-=20=20=20=20=20= =20error_name=20=3D=20"node=20type";=0A-=20=20=20=20=20=20break;=0A+=20=20= =20=20=20=20return=20"node=20type";=0A=20=20=20=20=20case=20= TSQueryErrorField:=0A-=20=20=20=20=20=20error_name=20=3D=20"field";=0A-=20= =20=20=20=20=20break;=0A+=20=20=20=20=20=20return=20"field";=0A=20=20=20=20= =20case=20TSQueryErrorCapture:=0A-=20=20=20=20=20=20error_name=20=3D=20= "capture";=0A-=20=20=20=20=20=20break;=0A+=20=20=20=20=20=20return=20= "capture";=0A=20=20=20=20=20case=20TSQueryErrorStructure:=0A-=20=20=20=20= =20=20error_name=20=3D=20"structure";=0A-=20=20=20=20=20=20break;=0A+=20=20= =20=20=20=20return=20"structure";=0A=20=20=20=20=20}=0A-=20=20return=20=20= make_pure_c_string=20(error_name,=20strlen(error_name));=0A=20}=0A=20=0A=20= DEFUN=20("tree-sitter-query-capture",=0A@@=20-634,7=20+712,7=20@@=20= DEFUN=20("tree-sitter-query-capture",=0A=20BEG=20and=20END,=20if=20= _both_=20non-nil,=20specifies=20the=20range=20in=20which=20the=20query=0A= =20is=20executed.=0A=20=0A-Return=20nil=20if=20the=20query=20failed.=20=20= */)=0A+Raise=20an=20tree-sitter-query-error=20if=20PATTERN=20is=20= malformed.=20=20*/)=0A=20=20=20(Lisp_Object=20node,=20Lisp_Object=20= pattern,=0A=20=20=20=20Lisp_Object=20beg,=20Lisp_Object=20end)=0A=20{=0A= @@=20-643,47=20+721,56=20@@=20DEFUN=20("tree-sitter-query-capture",=0A=20= =0A=20=20=20TSNode=20ts_node=20=3D=20XTS_NODE=20(node)->node;=0A=20=20=20= Lisp_Object=20lisp_parser=20=3D=20XTS_NODE=20(node)->parser;=0A+=20=20= ptrdiff_t=20visible_beg=20=3D=0A+=20=20=20=20XTS_PARSER=20(XTS_NODE=20= (node)->parser)->visible_beg;=0A=20=20=20const=20TSLanguage=20*lang=20=3D=20= ts_parser_language=0A=20=20=20=20=20(XTS_PARSER=20= (lisp_parser)->parser);=0A=20=20=20char=20*source=20=3D=20SSDATA=20= (pattern);=0A=20=0A+=0A=20=20=20uint32_t=20error_offset;=0A-=20=20= uint32_t=20error_type;=0A+=20=20TSQueryError=20error_type;=0A=20=20=20= TSQuery=20*query=20=3D=20ts_query_new=20(lang,=20source,=20strlen=20= (source),=0A=20=09=09=09=09=20&error_offset,=20&error_type);=0A=20=20=20= TSQueryCursor=20*cursor=20=3D=20ts_query_cursor_new=20();=0A=20=0A=20=20=20= if=20(query=20=3D=3D=20NULL)=0A=20=20=20=20=20{=0A-=20=20=20=20=20=20//=20= FIXME:=20Signal=20an=20error?=0A-=20=20=20=20=20=20return=20Qnil;=0A+=20=20= =20=20=20=20//=20FIXME:=20Still=20crashes,=20debug=20when=20I=20can=20= get=20a=20gdb.=0A+=20=20=20=20=20=20xsignal2=20= (Qtree_sitter_query_error,=0A+=09=09make_fixnum=20(error_offset),=0A+=09=09= build_string=20(ts_query_error_to_string=20(error_type)));=0A=20=20=20=20= =20}=0A=20=20=20if=20(!NILP=20(beg)=20&&=20!NILP=20(end))=0A=20=20=20=20=20= {=0A=20=20=20=20=20=20=20EMACS_INT=20beg_byte=20=3D=20XFIXNUM=20(beg);=0A= =20=20=20=20=20=20=20EMACS_INT=20end_byte=20=3D=20XFIXNUM=20(end);=0A=20=20= =20=20=20=20=20ts_query_cursor_set_byte_range=0A-=09(cursor,=20= (uint32_t)=20beg_byte=20-=201,=20(uint32_t)=20end_byte=20-=201);=0A+=09= (cursor,=20(uint32_t)=20beg_byte=20-=20visible_beg,=0A+=09=20(uint32_t)=20= end_byte=20-=20visible_beg);=0A=20=20=20=20=20}=0A=20=0A=20=20=20= ts_query_cursor_exec=20(cursor,=20query,=20ts_node);=0A=20=20=20= TSQueryMatch=20match;=0A-=20=20TSQueryCapture=20capture;=0A+=0A=20=20=20= Lisp_Object=20result=20=3D=20Qnil;=0A-=20=20Lisp_Object=20entry;=0A-=20=20= Lisp_Object=20captured_node;=0A-=20=20const=20char=20*capture_name;=0A-=20= =20uint32_t=20capture_name_len;=0A=20=20=20while=20= (ts_query_cursor_next_match=20(cursor,=20&match))=0A=20=20=20=20=20{=0A=20= =20=20=20=20=20=20const=20TSQueryCapture=20*captures=20=3D=20= match.captures;=0A=20=20=20=20=20=20=20for=20(int=20idx=3D0;=20idx=20<=20= match.capture_count;=20idx++)=0A=20=09{=0A+=09=20=20TSQueryCapture=20= capture;=0A+=09=20=20Lisp_Object=20captured_node;=0A+=09=20=20const=20= char=20*capture_name;=0A+=09=20=20Lisp_Object=20entry;=0A+=09=20=20= uint32_t=20capture_name_len;=0A+=0A=20=09=20=20capture=20=3D=20= captures[idx];=0A=20=09=20=20captured_node=20=3D=20= make_ts_node(lisp_parser,=20capture.node);=0A=20=09=20=20capture_name=20= =3D=20ts_query_capture_name_for_id=0A=20=09=20=20=20=20(query,=20= capture.index,=20&capture_name_len);=0A-=09=20=20entry=20=3D=20Fcons=20= (intern_c_string=20(capture_name),=0A+=09=20=20entry=20=3D=20Fcons=20= (intern_c_string_1=0A+=09=09=09=20(capture_name,=20capture_name_len),=0A=20= =09=09=09=20captured_node);=0A=20=09=20=20result=20=3D=20Fcons=20(entry,=20= result);=0A=20=09}=0A@@=20-705,11=20+792,15=20@@=20syms_of_tree_sitter=20= (void)=0A=20=20=20DEFSYM=20(Qhas_changes,=20"has-changes");=0A=20=20=20= DEFSYM=20(Qhas_error,=20"has-error");=0A=20=0A+=20=20= DEFSYM(Qtree_sitter_error,=20"tree-sitter-error");=0A=20=20=20DEFSYM=20= (Qtree_sitter_query_error,=20"tree-sitter-query-error");=0A-=20=20Fput=20= (Qtree_sitter_query_error,=20Qerror_conditions,=0A-=09pure_list=20= (Qtree_sitter_query_error,=20Qerror));=0A-=20=20Fput=20= (Qtree_sitter_query_error,=20Qerror_message,=0A-=09build_pure_c_string=20= ("Error=20with=20query=20pattern"))=0A+=20=20DEFSYM=20= (Qtree_sitter_parse_error,=20"tree-sitter-parse-error")=0A+=20=20= define_error=20(Qtree_sitter_error,=20"Generic=20tree-sitter=20error",=20= Qerror);=0A+=20=20define_error=20(Qtree_sitter_query_error,=20"Query=20= pattern=20is=20malformed",=0A+=09=09Qtree_sitter_error);=0A+=20=20= define_error=20(Qtree_sitter_parse_error,=20"Parse=20failed",=0A+=09=09= Qtree_sitter_error);=0A+=0A=20=0A=20=20=20DEFSYM=20= (Qtree_sitter_parser_list,=20"tree-sitter-parser-list");=0A=20=20=20= DEFVAR_LISP=20("tree-sitter-parser-list",=20Vtree_sitter_parser_list,=0A= diff=20--git=20a/src/tree_sitter.h=20b/src/tree_sitter.h=0Aindex=20= e9b4a71326..7e0fec0ee9=20100644=0A---=20a/src/tree_sitter.h=0A+++=20= b/src/tree_sitter.h=0A@@=20-20,8=20+20,6=20@@=20Copyright=20(C)=202021=20= Free=20Software=20Foundation,=20Inc.=0A=20#ifndef=20EMACS_TREE_SITTER_H=0A= =20#define=20EMACS_TREE_SITTER_H=0A=20=0A-#include=20=0A-=0A= =20#include=20"lisp.h"=0A=20=0A=20#include=20=0A@@=20= -33,12=20+31,25=20@@=20#define=20EMACS_TREE_SITTER_H=0A=20struct=20= Lisp_TS_Parser=0A=20{=0A=20=20=20union=20vectorlike_header=20header;=0A+=20= =20/*=20A=20parser's=20name=20is=20just=20a=20convenient=20tag,=20see=20= docstring=20for=0A+=20=20=20=20=20'tree-sitter-make-parser',=20and=20= 'tree-sitter-get-parser'.=20*/=0A=20=20=20Lisp_Object=20name;=0A=20=20=20= struct=20buffer=20*buffer;=0A=20=20=20TSParser=20*parser;=0A=20=20=20= TSTree=20*tree;=0A=20=20=20TSInput=20input;=0A+=20=20/*=20Re-parsing=20= an=20unchanged=20buffer=20is=20not=20free=20for=20tree-sitter,=20so=20we=0A= +=20=20=20=20=20only=20make=20it=20re-parse=20when=20need_reparse=20=3D=3D= =20true.=20=20That=20usually=0A+=20=20=20=20=20means=20some=20change=20= is=20made=20in=20the=20buffer.=20=20But=20others=20could=20set=0A+=20=20=20= =20=20this=20field=20to=20true=20to=20force=20tree-sitter=20to=20= re-parse.=20=20*/=0A=20=20=20bool=20need_reparse;=0A+=20=20/*=20This=20= two=20positions=20record=20the=20byte=20position=20of=20the=20"visible=0A= +=20=20=20=20=20region"=20that=20tree-sitter=20sees.=20=20Unlike=20= markers,=20These=20two=0A+=20=20=20=20=20positions=20do=20not=20change=20= as=20the=20user=20inserts=20and=20deletes=20text=0A+=20=20=20=20=20= around=20them.=20Before=20re-parse,=20we=20move=20these=20positions=20to=20= match=0A+=20=20=20=20=20BUF_BEGV_BYTE=20and=20BUF_ZV_BYTE.=20=20*/=0A+=20= =20ptrdiff_t=20visible_beg;=0A+=20=20ptrdiff_t=20visible_end;=0A=20};=0A=20= =0A=20/*=20A=20wrapper=20around=20a=20tree-sitter=20node.=20=20*/=0Adiff=20= --git=20a/test/src/tree-sitter-tests.el=20= b/test/src/tree-sitter-tests.el=0Aindex=20c61ad678d2..69104568de=20= 100644=0A---=20a/test/src/tree-sitter-tests.el=0A+++=20= b/test/src/tree-sitter-tests.el=0A@@=20-148,5=20+148,58=20@@=20= tree-sitter-query-api=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(cdr=20entry))))=0A=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20(tree-sitter-query-capture=20root-node=20= pattern)))))))=0A=20=0A+(ert-deftest=20tree-sitter-narrow=20()=0A+=20=20= "Tests=20if=20narrowing=20works."=0A+=20=20(with-temp-buffer=0A+=20=20=20= =20(let=20(parser=20root-node=20pattern=20doc-node=20object-node=20= pair-node)=0A+=20=20=20=20=20=20(progn=0A+=20=20=20=20=20=20=20=20= (insert=20"xxx[1,{\"name\":=20\"Bob\"},2,3]xxx")=0A+=20=20=20=20=20=20=20= =20(narrow-to-region=20(+=20(point-min)=203)=20(-=20(point-max)=203))=0A= +=20=20=20=20=20=20=20=20(setq=20parser=20(tree-sitter-create-parser=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (current-buffer)=20(tree-sitter-json)))=0A+=20=20=20=20=20=20=20=20(setq=20= root-node=20(tree-sitter-parser-root-node=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20parser)))=0A+=20=20=20=20=20= =20;;=20This=20test=20is=20from=20the=20basic=20test.=0A+=20=20=20=20=20=20= (should=0A+=20=20=20=20=20=20=20(equal=0A+=20=20=20=20=20=20=20=20= (tree-sitter-node-string=0A+=20=20=20=20=20=20=20=20=20= (tree-sitter-parser-root-node=20parser))=0A+=20=20=20=20=20=20=20=20= "(document=20(array=20(number)=20(object=20(pair=20key:=20(string=20= (string_content))=20value:=20(string=20(string_content))))=20(number)=20= (number)))"))=0A+=0A+=20=20=20=20=20=20(widen)=0A+=20=20=20=20=20=20= (goto-char=20(point-min))=0A+=20=20=20=20=20=20(insert=20"ooo")=0A+=20=20= =20=20=20=20(should=20(equal=20"oooxxx[1,{\"name\":=20\"Bob\"},2,3]xxx"=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (buffer-string)))=0A+=20=20=20=20=20=20(delete-region=2010=2026)=0A+=20=20= =20=20=20=20(should=20(equal=20"oooxxx[1,2,3]xxx"=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(buffer-string)))=0A+=20=20=20=20= =20=20(narrow-to-region=20(+=20(point-min)=206)=20(-=20(point-max)=203))=0A= +=20=20=20=20=20=20;;=20This=20test=20is=20also=20from=20the=20basic=20= test.=0A+=20=20=20=20=20=20(should=0A+=20=20=20=20=20=20=20(equal=20= (tree-sitter-node-string=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (tree-sitter-parser-root-node=20parser))=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20"(document=20(array=20(number)=20(number)=20(number)))"))=0A= +=20=20=20=20=20=20(widen)=0A+=20=20=20=20=20=20(goto-char=20= (point-max))=0A+=20=20=20=20=20=20(insert=20"[1,2]")=0A+=20=20=20=20=20=20= (should=20(equal=20"oooxxx[1,2,3]xxx[1,2]"=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(buffer-string)))=0A+=20=20=20=20=20=20= (narrow-to-region=20(-=20(point-max)=205)=20(point-max))=0A+=20=20=20=20=20= =20(should=0A+=20=20=20=20=20=20=20(equal=20(tree-sitter-node-string=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(tree-sitter-parser-root-node=20= parser))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20"(document=20= (array=20(number)=20(number)))"))=0A+=20=20=20=20=20=20(widen)=0A+=20=20=20= =20=20=20(goto-char=20(point-min))=0A+=20=20=20=20=20=20(insert=20"[1]")=0A= +=20=20=20=20=20=20(should=20(equal=20"[1]oooxxx[1,2,3]xxx[1,2]"=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (buffer-string)))=0A+=20=20=20=20=20=20(narrow-to-region=20(point-min)=20= (+=20(point-min)=203))=0A+=20=20=20=20=20=20(should=0A+=20=20=20=20=20=20= =20(equal=20(tree-sitter-node-string=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(tree-sitter-parser-root-node=20parser))=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20"(document=20(array=20(number)))")))))=0A+=0A=20= (provide=20'tree-sitter-tests)=0A=20;;;=20tree-sitter-tests.el=20ends=20= here=0A--=20=0A2.24.3=20(Apple=20Git-128)=0A=0A= --Apple-Mail=_F1BE1A5A-CFA3-48AC-B229-73A2EF7F336F--