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: Sat, 24 Jul 2021 11:04:35 -0400 Message-ID: References: <83h7gw6pyj.fsf@gnu.org> <45EBF16A-C953-42C7-97D1-3A2BFEF7DD01@gmail.com> <83y2a764oy.fsf@gnu.org> <83v95b60fn.fsf@gnu.org> <00DD5BFE-D14E-449A-9319-E7B725DEBFB3@gmail.com> <83r1fz5xr9.fsf@gnu.org> <1AAB1BCC-362B-4249-B785-4E0530E15C60@gmail.com> <83czri67h0.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> <83eebq2mpy.fsf@gnu.org> <83lf5w26e3.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=_CB182ECC-FDB9-4900-A33D-A4E90410B14A" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22992"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?Q?Cl=C3=A9ment_Pit-Claudel?= , Stefan Monnier , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jul 24 17:05:53 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 1m7JDt-0005o7-04 for ged-emacs-devel@m.gmane-mx.org; Sat, 24 Jul 2021 17:05:53 +0200 Original-Received: from localhost ([::1]:38140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m7JDr-0005YR-V4 for ged-emacs-devel@m.gmane-mx.org; Sat, 24 Jul 2021 11:05:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m7JCl-0004IE-BN for emacs-devel@gnu.org; Sat, 24 Jul 2021 11:04:43 -0400 Original-Received: from mail-qv1-xf36.google.com ([2607:f8b0:4864:20::f36]:39805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m7JCj-00016m-Fr; Sat, 24 Jul 2021 11:04:43 -0400 Original-Received: by mail-qv1-xf36.google.com with SMTP id d3so2832989qvq.6; Sat, 24 Jul 2021 08:04:39 -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=drTtDte9FgRollIKRw/edCFvW8UqU0z4UHtLEdT890E=; b=dxlRS1zm3p7ZoaNLStS/8ygAS+U3aQiLFOYbfnITxjlwsbDiLYif9iKA58OYF4/AhR CXbfn+3EWmkuTLrPVGAQCyXhXnhkXZ7BEY1+RxLw8F1p2yA2Px4lXp0+Xuec02aWEDwF RPdlUKnD/+mZ063pcn8TAVc8Ylkcnnl5yxP1gHfEHSlbcbCJEvCfb07mOVUpblnNcRLb z2Shd/GUMnfFNB2ceUrD7jkBRKUnkMxHGT7m3MoP3vtOnHJO24nvMX8rPebOPxYqyvnV 2wesVfP6nub8oSYd8P+x+cm3uMIdS4FTTCIFM4mGbM2fLMpnAtDSZH5way75WmFWsim8 sUtA== 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=drTtDte9FgRollIKRw/edCFvW8UqU0z4UHtLEdT890E=; b=jodnq+KPj8KBHlw7tbHIOGAJ+EZJvt7jz9MCU7UY9yZyL+xpt5et8FB/hQPyCtFDCJ LvauyTJq6lWSeJjJyQi7deCOIeMisxpKTD1AoA55od5Gc/RHSOHYDqc3xa/p57HoScEE pFDwmG9HfmT6FqAqfP9WNHrMpMjZPUhQ4QRFSr4nxGS4WJzawHSws5qNk/Z83wDp6LGD tUaWxLnWOt1AA+vm/6uz4l2q2LZ37PBvsdcl6vzQOX+zbHSDYHPAW/NLAGgD+RoDFb6r yF/4IMT0VbQItxlmgolCAcv146h1tFBO7ocFRZTyBuywkbsmoBLYtG2sWp0Trsjorykm 0Q/Q== X-Gm-Message-State: AOAM533cK2amRzEk88pIbC46UT2O0ERnUP3muJJ2wnGm3OZhgW1WCN6x fr9zUfPVtCcECVj2/R+riC5dit1WAqc/vA== X-Google-Smtp-Source: ABdhPJza5CzFEVLRZysusE6hNirkFTJc6nOYY7s6vqOl7+KgW72WHE7ECrD+Zw50YM19QWOpqIBWYQ== X-Received: by 2002:a0c:fd48:: with SMTP id j8mr10046713qvs.60.1627139078273; Sat, 24 Jul 2021 08:04:38 -0700 (PDT) Original-Received: from 2603-7080-0302-635e-d969-6d23-8e5f-2ec1.res6.spectrum.com (2603-7080-0302-635e-d969-6d23-8e5f-2ec1.res6.spectrum.com. [2603:7080:302:635e:d969:6d23:8e5f:2ec1]) by smtp.gmail.com with ESMTPSA id 82sm13226624qkl.97.2021.07.24.08.04.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Jul 2021 08:04:37 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3654.60.0.2.21) Received-SPF: pass client-ip=2607:f8b0:4864:20::f36; envelope-from=casouri@gmail.com; helo=mail-qv1-xf36.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:271547 Archived-At: --Apple-Mail=_CB182ECC-FDB9-4900-A33D-A4E90410B14A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I wrote a simple interface between font-lock and tree-sitter, and it = works pretty well: using tree-sitter for fontification, xdisp.c opens a = lot faster, and scrolling through the buffer is also perceivably faster. = My simple interface works like this: tree-sitter allow you to =E2=80=9Cpat= tern match=E2=80=9D nodes in the parse tree with a DSL, and assign names = to the matched nodes, e.g., given a pattern, you get back a list of = (NAME . MATCHED-NODE). And if we use font-lock faces as names for those = nodes, we get back a list of (FACE . MATCHED-NODE) from tree-sitter, and = Emacs can simply look at the beginning and end of the node, and apply = FACE to that range. For flexibility, FACE can also be a function, in = which case the function is called with the node. This interface is = basically what emacs-tree-sitter does (I don=E2=80=99t know if they = allow a capture name to be a function, though.) I have an example major-mode for C that uses tree-sitter for = font-locking at the end of tree-sitter.el.=20 Main functions to look at: tree-sitter-query-capture in tree_sitter.c, = and tree-sitter-fontify-region-function in tree-sitter.el. On the font-lock front, tree-sitter-fontify-region-function replaces = font-lock-default-fontify-region, and tree-sitter-font-lock-settings = replaces font-lock-defaults and font-lock-keywords. I should support = font-lock-maximum-decoration but haven=E2=80=99t came up with a good way = to do that. Maybe I should somehow reuse font-lock-defaults, and make it = able to configure for tree-sitter font-locking? Apart from = font-lock-maximum-decoration, what else should tree-sitter share with = font-lock? BTW, what is the best way to signal a lisp error from C? I tried = xsignal2, signal_error, error and friends but they seem to crash Emacs. = Maybe I wasn=E2=80=99t using them correctly. IIUC if we want tree-sitter to use our malloc, we need to build it with = Emacs, where should I put the source of tree-sitter? What=E2=80=99s the different between make_string and make_pure_c_string? = I=E2=80=99ve seen this =E2=80=9Cpure=E2=80=9D thing else where, what = does =E2=80=9Cpure=E2=80=9D mean? Yuan --Apple-Mail=_CB182ECC-FDB9-4900-A33D-A4E90410B14A Content-Disposition: attachment; filename=ts.4.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="ts.4.patch" Content-Transfer-Encoding: quoted-printable =46rom=20d28e10e5905d244d92b71b74566c0bed80d5ed2b=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Yuan=20Fu=20=0ADate:=20Sat,=20= 24=20Jul=202021=2010:39:15=20-0400=0ASubject:=20[PATCH]=20checkpoint=204=0A= =0A-=20Add=20font-locking=0A-=20Remove=20change-recording=20from=20= replace_range_2,=20add=20to=20casify_region=0A---=0A=20= lisp/emacs-lisp/cl-preloaded.el=20|=20=20=202=20+=0A=20= lisp/tree-sitter.el=20=20=20=20=20=20=20=20=20=20=20=20=20|=20276=20= ++++++++++++++++++++++++++=0A=20src/casefiddle.c=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20|=20=2012=20++=0A=20src/insdel.c=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20|=20=2011=20+-=0A=20= src/tree_sitter.c=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20332=20= +++++++++++++++++++++++++++++---=0A=20src/tree_sitter.h=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20|=20=20=204=20+-=0A=20= test/src/tree-sitter-tests.el=20=20=20|=20=2058=20+++++-=0A=207=20files=20= changed,=20655=20insertions(+),=2040=20deletions(-)=0A=20create=20mode=20= 100644=20lisp/tree-sitter.el=0A=0Adiff=20--git=20= a/lisp/emacs-lisp/cl-preloaded.el=20b/lisp/emacs-lisp/cl-preloaded.el=0A= index=207365e23186..2dccdff91a=20100644=0A---=20= a/lisp/emacs-lisp/cl-preloaded.el=0A+++=20= b/lisp/emacs-lisp/cl-preloaded.el=0A@@=20-68,6=20+68,8=20@@=20= cl--typeof-types=0A=20=20=20=20=20(font-spec=20atom)=20(font-entity=20= atom)=20(font-object=20atom)=0A=20=20=20=20=20(vector=20array=20sequence=20= atom)=0A=20=20=20=20=20(user-ptr=20atom)=0A+=20=20=20=20= (tree-sitter-parser=20atom)=0A+=20=20=20=20(tree-sitter-node=20atom)=0A=20= =20=20=20=20;;=20Plus,=20really=20hand=20made:=0A=20=20=20=20=20(null=20= symbol=20list=20sequence=20atom))=0A=20=20=20"Alist=20of=20supertypes.=0A= diff=20--git=20a/lisp/tree-sitter.el=20b/lisp/tree-sitter.el=0Anew=20= file=20mode=20100644=0Aindex=200000000000..a6ecb09386=0A---=20/dev/null=0A= +++=20b/lisp/tree-sitter.el=0A@@=20-0,0=20+1,276=20@@=0A+;;;=20= tree-sitter.el=20---=20tree-sitter=20utilities=20-*-=20lexical-binding:=20= t=20-*-=0A+=0A+;;=20Copyright=20(C)=202021=20Free=20Software=20= Foundation,=20Inc.=0A+=0A+;;=20This=20file=20is=20part=20of=20GNU=20= Emacs.=0A+=0A+;;=20GNU=20Emacs=20is=20free=20software:=20you=20can=20= redistribute=20it=20and/or=20modify=0A+;;=20it=20under=20the=20terms=20= of=20the=20GNU=20General=20Public=20License=20as=20published=20by=0A+;;=20= the=20Free=20Software=20Foundation,=20either=20version=203=20of=20the=20= License,=20or=0A+;;=20(at=20your=20option)=20any=20later=20version.=0A+=0A= +;;=20GNU=20Emacs=20is=20distributed=20in=20the=20hope=20that=20it=20= will=20be=20useful,=0A+;;=20but=20WITHOUT=20ANY=20WARRANTY;=20without=20= even=20the=20implied=20warranty=20of=0A+;;=20MERCHANTABILITY=20or=20= FITNESS=20FOR=20A=20PARTICULAR=20PURPOSE.=20=20See=20the=0A+;;=20GNU=20= General=20Public=20License=20for=20more=20details.=0A+=0A+;;=20You=20= should=20have=20received=20a=20copy=20of=20the=20GNU=20General=20Public=20= License=0A+;;=20along=20with=20GNU=20Emacs.=20=20If=20not,=20see=20= .=0A+=0A+;;;=20Commentary:=0A+=0A+;;;=20= Code:=0A+=0A+;;;=20Node=20&=20parser=20accessors=0A+=0A+(defun=20= tree-sitter-node-buffer=20(node)=0A+=20=20"Return=20the=20buffer=20in=20= where=20NODE=20belongs."=0A+=20=20(tree-sitter-parser-buffer=0A+=20=20=20= (tree-sitter-node-parser=20node)))=0A+=0A+;;;=20Parser=20API=20= supplement=0A+=0A+(defun=20tree-sitter-get-parser=20(name)=0A+=20=20= "Find=20the=20first=20parser=20with=20name=20NAME=20in=20= `tree-sitter-parser-list'.=0A+Return=20nil=20if=20we=20can't=20find=20= any."=0A+=20=20(catch=20'found=0A+=20=20=20=20(dolist=20(parser=20= tree-sitter-parser-list)=0A+=20=20=20=20=20=20(when=20(equal=20name=20= (tree-sitter-parser-name=20parser))=0A+=20=20=20=20=20=20=20=20(throw=20= 'found=20parser)))))=0A+=0A+(defun=20tree-sitter-get-parser-create=20= (name=20language)=0A+=20=20"Find=20the=20first=20parser=20with=20name=20= NAME=20in=20`tree-sitter-parser-list'.=0A+If=20none=20exists,=20create=20= one=20and=20return=20it.=20=20LANGUAGE=20is=20passed=20to=0A= +`tree-sitter-create-parser'=20when=20creating=20the=20parser."=0A+=20=20= (or=20(tree-sitter-get-parser=20name)=0A+=20=20=20=20=20=20= (tree-sitter-create-parser=20(current-buffer)=20language=20name)))=0A+=0A= +;;;=20Node=20API=20supplement=0A+=0A+(defun=20= tree-sitter-node-beginning=20(node)=0A+=20=20"Return=20the=20start=20= position=20of=20NODE."=0A+=20=20(byte-to-position=20= (tree-sitter-node-start-byte=20node)))=0A+=0A+(defun=20= tree-sitter-node-end=20(node)=0A+=20=20"Return=20the=20end=20position=20= of=20NODE."=0A+=20=20(byte-to-position=20(tree-sitter-node-end-byte=20= node)))=0A+=0A+(defun=20tree-sitter-node-in-range=20(beg=20end=20= &optional=20parser-name=20named)=0A+=20=20"Return=20the=20smallest=20= node=20covering=20BEG=20to=20END.=0A+Find=20node=20in=20current=20= buffer.=20=20Return=20nil=20if=20none=20find.=20=20If=20NAMED=0A= +non-nil,=20only=20look=20for=20named=20node.=20=20NAMED=20defaults=20to=20= nil.=20=20By=0A+default,=20use=20the=20first=20parser=20in=20= `tree-sitter-parser-list';=20but=0A+if=20PARSER-NAME=20is=20non-nil,=20= it=20specifies=20the=20name=20of=20the=20parser=20that=0A+should=20be=20= used."=0A+=20=20(when-let=20((root=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(if=20= parser-name=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(tree-sitter-get-parser=20parser-name)=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(car=20= tree-sitter-parser-list)))))=0A+=20=20=20=20= (tree-sitter-node-descendant-for-byte-range=0A+=20=20=20=20=20root=20= (position-bytes=20beg)=20(position-bytes=20end)=20named)))=0A+=0A+(defun=20= tree-sitter-filter-child=20(node=20pred=20&optional=20named)=0A+=20=20= "Return=20children=20of=20NODE=20that=20satisfies=20PRED.=0A+PRED=20is=20= a=20function=20that=20takes=20one=20argument,=20the=20child=20node.=20=20= If=0A+NAMED=20non-nil,=20only=20search=20named=20node.=20=20NAMED=20= defaults=20to=20nil."=0A+=20=20(let=20((child=20(tree-sitter-node-child=20= node=200=20named))=0A+=20=20=20=20=20=20=20=20result)=0A+=20=20=20=20= (while=20child=0A+=20=20=20=20=20=20(when=20(funcall=20pred=20child)=0A+=20= =20=20=20=20=20=20=20(push=20child=20result))=0A+=20=20=20=20=20=20(setq=20= child=20(tree-sitter-node-next-sibling=20child=20named)))=0A+=20=20=20=20= result))=0A+=0A+(defun=20tree-sitter-node-content=20(node)=0A+=20=20= "Return=20the=20buffer=20content=20corresponding=20to=20NODE."=0A+=20=20= (with-current-buffer=20(tree-sitter-node-buffer=20node)=0A+=20=20=20=20= (buffer-substring-no-properties=0A+=20=20=20=20=20= (tree-sitter-node-beginning=20node)=0A+=20=20=20=20=20= (tree-sitter-node-end=20node))))=0A+=0A+;;;=20Font-lock=0A+=0A= +(defvar-local=20tree-sitter-font-lock-settings=20nil=0A+=20=20"A=20list=20= of=20settings=20for=20tree-sitter-based=20font-locking.=0A+=0A+Each=20= setting=20controls=20one=20parser=20(often=20of=20different=20language).=0A= +A=20settings=20is=20a=20list=20of=20form=20(NAME=20LANGUAGE=20PATTERN).=20= =20NAME=20is=0A+the=20name=20given=20to=20the=20parser,=20by=20= convention=20it=20is=0A+\"font-lock-\",=20where=20=20= is=20the=20language=20that=0A+the=20parser=20uses.=20=20LANGUAGE=20is=20= the=20language=20object=20returned=20by=0A+tree-sitter=20language=20= dynamic=20modules.=0A+=0A+PATTERN=20is=20a=20tree-sitter=20query=20= pattern.=20(See=20manual=20for=20how=20to=0A+write=20query=20patterns.)=20= =20This=20pattern=20should=20capture=20nodes=20with=0A+either=20face=20= names=20or=20function=20names.=20=20If=20captured=20with=20a=20face=0A= +name,=20the=20node's=20corresponding=20text=20in=20the=20buffer=20is=20= fontified=0A+with=20that=20face;=20if=20captured=20with=20a=20function=20= name,=20the=20function=20is=0A+called=20with=20three=20arguments,=20BEG=20= END=20NODE,=20where=20BEG=20and=20END=0A+marks=20the=20span=20of=20the=20= corresponding=20text,=20and=20NODE=20is=20the=20node=0A+itself.")=0A+=0A= +(defun=20tree-sitter-fontify-region-function=20(beg=20end=20&optional=20= verbose)=0A+=20=20"Fontify=20the=20region=20between=20BEG=20and=20END.=0A= +If=20VERBOSE=20is=20non-nil,=20print=20status=20messages.=0A+\(See=20= `font-lock-fontify-region-function'.)"=0A+=20=20(dolist=20(elm=20= tree-sitter-font-lock-settings)=0A+=20=20=20=20(let=20((parser-name=20= (car=20elm))=0A+=20=20=20=20=20=20=20=20=20=20(language=20(nth=201=20= elm))=0A+=20=20=20=20=20=20=20=20=20=20(match-pattern=20(nth=202=20= elm)))=0A+=20=20=20=20=20=20(tree-sitter-get-parser-create=20parser-name=20= language)=0A+=20=20=20=20=20=20(when-let=20((node=20= (tree-sitter-node-in-range=20beg=20end=20parser-name)))=0A+=20=20=20=20=20= =20=20=20(let=20((captures=20(tree-sitter-query-capture=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=20node=20= match-pattern=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;;=20specifying=20the=20range=20is=20important.=20More=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;;=20often=20than=20not,=20NODE=20will=20be=20the=20root=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= node,=20and=20if=20we=20don't=20specify=20the=20range,=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;;=20we=20= are=20basically=20querying=20the=20whole=20file.=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(position-bytes=20= beg)=20(position-bytes=20end))))=0A+=20=20=20=20=20=20=20=20=20=20= (with-silent-modifications=0A+=20=20=20=20=20=20=20=20=20=20=20=20(while=20= captures=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20(let*=20((face=20= (caar=20captures))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(node=20(cdar=20captures))=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20(beg=20(tree-sitter-node-beginning=20= node))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (end=20(tree-sitter-node-end=20node)))=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20(cond=20((facep=20face)=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(put-text-property=20beg=20end=20= 'face=20face))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20((functionp=20face)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(funcall=20face=20beg=20end=20node)))=0A+=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(if=20verbose=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(message=20"Fontifying=20= text=20from=20%d=20to=20%d=20with=20%s"=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=20=20=20beg=20end=20= face)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20(setq=20captures=20= (cdr=20captures))))=0A+=20=20=20=20=20=20=20=20=20=20`(jit-lock-bounds=20= ,(tree-sitter-node-beginning=20node)=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=20=20.=20= ,(tree-sitter-node-end=20node)))))))=0A+=0A+=0A+(define-derived-mode=20= json-mode=20js-mode=20"JSON"=0A+=20=20"Major=20mode=20for=20JSON=20= documents."=0A+=20=20(setq-local=20font-lock-fontify-region-function=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20= #'tree-sitter-fontify-region-function)=0A+=20=20(setq-local=20= tree-sitter-font-lock-settings=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20`(("font-lock-json"=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20,(tree-sitter-json)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20"(string)=20@font-lock-string-face=0A+(true)=20= @font-lock-constant-face=0A+(false)=20@font-lock-constant-face=0A+(null)=20= @font-lock-constant-face"))))=0A+=0A+(defun=20ts-c-fontify-system-lib=20= (beg=20end=20_)=0A+=20=20(put-text-property=20beg=20(1+=20beg)=20'face=20= 'font-lock-preprocessor-face)=0A+=20=20(put-text-property=20(1-=20end)=20= end=20'face=20'font-lock-preprocessor-face)=0A+=20=20(put-text-property=20= (1+=20beg)=20(1-=20end)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20'face=20'font-lock-string-face))=0A+=0A= +(define-derived-mode=20ts-c-mode=20prog-mode=20"TS=20C"=0A+=20=20"C=20= mode=20with=20tree-sitter=20support."=0A+=20=20(setq-local=20= font-lock-fontify-region-function=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20#'tree-sitter-fontify-region-function)=0A+=20=20(setq-local=20= tree-sitter-font-lock-settings=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20`(("font-lock-c"=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= ,(tree-sitter-c)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= "(null)=20@font-lock-constant-face=0A+(true)=20@font-lock-constant-face=0A= +(false)=20@font-lock-constant-face=0A+=0A+(comment)=20= @font-lock-comment-face=0A+=0A+(system_lib_string)=20= @ts-c-fontify-system-lib=0A+=0A+(unary_expression=0A+=20=20operator:=20_=20= @font-lock-negation-char-face)=0A+=0A+(string_literal)=20= @font-lock-string-face=0A+(char_literal)=20@font-lock-string-face=0A+=0A= +=0A+=0A+(function_definition=0A+=20=20declarator:=20(identifier)=20= @font-lock-function-name-face)=0A+=0A+(declaration=0A+=20=20declarator:=20= (identifier)=20@font-lock-function-name-face)=0A+=0A= +(function_declarator=0A+=20declarator:=20(identifier)=20= @font-lock-function-name-face)=0A+=0A+=0A+=0A+(init_declarator=0A+=20= declarator:=20(identifier)=20@font-lock-variable-name-face)=0A+=0A= +(parameter_declaration=0A+=20declarator:=20(identifier)=20= @font-lock-variable-name-face)=0A+=0A+(preproc_def=0A+=20name:=20= (identifier)=20@font-lock-variable-name-face)=0A+=0A+(enumerator=0A+=20= name:=20(identifier)=20@font-lock-variable-name-face)=0A+=0A= +(field_identifier)=20@font-lock-variable-name-face=0A+=0A= +(parameter_list=0A+=20(parameter_declaration=0A+=20=20(identifier)=20= @font-lock-variable-name-face))=0A+=0A+(pointer_declarator=0A+=20= declarator:=20(identifier)=20@font-lock-variable-name-face)=0A+=0A= +(array_declarator=0A+=20declarator:=20(identifier)=20= @font-lock-variable-name-face)=0A+=0A+(preproc_function_def=0A+=20name:=20= (identifier)=20@font-lock-variable-name-face=0A+=20parameters:=20= (preproc_params=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (identifier)=20@font-lock-variable-name-face))=0A+=0A+=0A+=0A= +(type_identifier)=20@font-lock-type-face=0A+(primitive_type)=20= @font-lock-type-face=0A+=0A+\"auto\"=20@font-lock-keyword-face=0A= +\"break\"=20@font-lock-keyword-face=0A+\"case\"=20= @font-lock-keyword-face=0A+\"const\"=20@font-lock-keyword-face=0A= +\"continue\"=20@font-lock-keyword-face=0A+\"default\"=20= @font-lock-keyword-face=0A+\"do\"=20@font-lock-keyword-face=0A+\"else\"=20= @font-lock-keyword-face=0A+\"enum\"=20@font-lock-keyword-face=0A= +\"extern\"=20@font-lock-keyword-face=0A+\"for\"=20= @font-lock-keyword-face=0A+\"goto\"=20@font-lock-keyword-face=0A+\"if\"=20= @font-lock-keyword-face=0A+\"register\"=20@font-lock-keyword-face=0A= +\"return\"=20@font-lock-keyword-face=0A+\"sizeof\"=20= @font-lock-keyword-face=0A+\"static\"=20@font-lock-keyword-face=0A= +\"struct\"=20@font-lock-keyword-face=0A+\"switch\"=20= @font-lock-keyword-face=0A+\"typedef\"=20@font-lock-keyword-face=0A= +\"union\"=20@font-lock-keyword-face=0A+\"volatile\"=20= @font-lock-keyword-face=0A+\"while\"=20@font-lock-keyword-face=0A+=0A= +\"long\"=20@font-lock-type-face=0A+\"short\"=20@font-lock-type-face=0A= +\"signed\"=20@font-lock-type-face=0A+\"unsigned\"=20= @font-lock-type-face=0A+=0A+\"#include\"=20@font-lock-preprocessor-face=0A= +\"#define\"=20@font-lock-preprocessor-face=0A+\"#ifdef\"=20= @font-lock-preprocessor-face=0A+\"#ifndef\"=20= @font-lock-preprocessor-face=0A+\"#endif\"=20= @font-lock-preprocessor-face=0A+\"#else\"=20@font-lock-preprocessor-face=0A= +\"#elif\"=20@font-lock-preprocessor-face"))))=0A+=0A+(add-to-list=20= 'auto-mode-alist=20'("\\.json\\'"=20.=20json-mode))=0A+(add-to-list=20= 'auto-mode-alist=20'("\\.tsc\\'"=20.=20ts-c-mode))=0A+=0A+(provide=20= 'tree-sitter)=0A+=0A+;;;=20tree-sitter.el=20ends=20here=0Adiff=20--git=20= a/src/casefiddle.c=20b/src/casefiddle.c=0Aindex=20a7a2541490..42cd2fdd28=20= 100644=0A---=20a/src/casefiddle.c=0A+++=20b/src/casefiddle.c=0A@@=20= -30,6=20+30,10=20@@=20Copyright=20(C)=201985,=201994,=201997-1999,=20= 2001-2021=20Free=20Software=20Foundation,=0A=20#include=20"composite.h"=0A= =20#include=20"keymap.h"=0A=20=0A+#ifdef=20HAVE_TREE_SITTER=0A+#include=20= "tree_sitter.h"=0A+#endif=0A+=0A=20enum=20case_action=20{CASE_UP,=20= CASE_DOWN,=20CASE_CAPITALIZE,=20CASE_CAPITALIZE_UP};=0A=20=0A=20/*=20= State=20for=20casing=20individual=20characters.=20=20*/=0A@@=20-495,6=20= +499,11=20@@=20casify_region=20(enum=20case_action=20flag,=20Lisp_Object=20= b,=20Lisp_Object=20e)=0A=20=20=20modify_text=20(start,=20end);=0A=20=20=20= prepare_casing_context=20(&ctx,=20flag,=20true);=0A=20=0A+#ifdef=20= HAVE_TREE_SITTER=0A+=20=20ptrdiff_t=20start_byte=20=3D=20CHAR_TO_BYTE=20= (start);=0A+=20=20ptrdiff_t=20old_end_byte=20=3D=20CHAR_TO_BYTE=20(end);=0A= +#endif=0A+=0A=20=20=20ptrdiff_t=20orig_end=20=3D=20end;=0A=20=20=20= record_delete=20(start,=20make_buffer_string=20(start,=20end,=20true),=20= false);=0A=20=20=20if=20(NILP=20(BVAR=20(current_buffer,=20= enable_multibyte_characters)))=0A@@=20-513,6=20+522,9=20@@=20= casify_region=20(enum=20case_action=20flag,=20Lisp_Object=20b,=20= Lisp_Object=20e)=0A=20=20=20=20=20{=0A=20=20=20=20=20=20=20= signal_after_change=20(start,=20end=20-=20start=20-=20added,=20end=20-=20= start);=0A=20=20=20=20=20=20=20update_compositions=20(start,=20end,=20= CHECK_ALL);=0A+#ifdef=20HAVE_TREE_SITTER=0A+=20=20=20=20=20=20= ts_record_change=20(start_byte,=20old_end_byte,=20CHAR_TO_BYTE=20(end));=0A= +#endif=0A=20=20=20=20=20}=0A=20=0A=20=20=20return=20orig_end=20+=20= added;=0Adiff=20--git=20a/src/insdel.c=20b/src/insdel.c=0Aindex=20= b313c50cda..3dfc281b49=20100644=0A---=20a/src/insdel.c=0A+++=20= b/src/insdel.c=0A@@=20-1592,7=20+1592,11=20@@=20replace_range=20= (ptrdiff_t=20from,=20ptrdiff_t=20to,=20Lisp_Object=20new,=0A=20=20=20=20= If=20MARKERS,=20relocate=20markers.=0A=20=0A=20=20=20=20Unlike=20most=20= functions=20at=20this=20level,=20never=20call=0A-=20=20=20= prepare_to_modify_buffer=20and=20never=20call=20signal_after_change.=20=20= */=0A+=20=20=20prepare_to_modify_buffer=20and=20never=20call=20= signal_after_change.=0A+=20=20=20Because=20this=20function=20is=20called=20= in=20a=20loop,=20one=20character=20at=20a=20time.=0A+=20=20=20The=20= caller=20of=20'replace_range_2'=20calls=20these=20hooks=20for=20the=20= entire=0A+=20=20=20region=20once.=20=20Apart=20from=20= signal_after_change,=20any=20caller=20of=20this=0A+=20=20=20function=20= should=20also=20call=20ts_record_change.=20=20*/=0A=20=0A=20void=0A=20= replace_range_2=20(ptrdiff_t=20from,=20ptrdiff_t=20from_byte,=0A@@=20= -1705,11=20+1709,6=20@@=20replace_range_2=20(ptrdiff_t=20from,=20= ptrdiff_t=20from_byte,=0A=20=0A=20=20=20modiff_incr=20(&MODIFF);=0A=20=20= =20CHARS_MODIFF=20=3D=20MODIFF;=0A-=0A-#ifdef=20HAVE_TREE_SITTER=0A-=20=20= ts_record_change=20(from_byte,=20to_byte,=20from_byte=20+=20insbytes);=0A= -#endif=0A-=0A=20}=0A=20=0C=0A=20/*=20Delete=20characters=20in=20current=20= buffer=0Adiff=20--git=20a/src/tree_sitter.c=20b/src/tree_sitter.c=0A= index=20a6a8912c84..e9f8ddc7e3=20100644=0A---=20a/src/tree_sitter.c=0A= +++=20b/src/tree_sitter.c=0A@@=20-35,6=20+35,8=20@@=20Copyright=20(C)=20= 2021=20Free=20Software=20Foundation,=20Inc.=0A=20/*=20parser.h=20defines=20= a=20macro=20ADVANCE=20that=20conflicts=20with=20alloc.c.=20=20*/=0A=20= #include=20=0A=20=0A+/***=20Functions=20related=20= to=20parser=20and=20node=20object.=20=20*/=0A+=0A=20DEFUN=20= ("tree-sitter-parser-p",=0A=20=20=20=20=20=20=20=20= Ftree_sitter_parser_p,=20Stree_sitter_parser_p,=201,=201,=200,=0A=20=20=20= =20=20=20=20=20doc:=20/*=20Return=20t=20if=20OBJECT=20is=20a=20= tree-sitter=20parser.=20=20*/)=0A@@=20-57,6=20+59,8=20@@=20DEFUN=20= ("tree-sitter-node-p",=0A=20=20=20=20=20return=20Qnil;=0A=20}=0A=20=0A= +/***=20Parsing=20functions=20*/=0A+=0A=20/*=20Update=20each=20parser's=20= tree=20after=20the=20user=20made=20an=20edit.=20=20This=0A=20function=20= does=20not=20parse=20the=20buffer=20and=20only=20updates=20the=20tree.=20= (So=20it=0A=20should=20be=20very=20fast.)=20=20*/=0A@@=20-77,7=20+81,6=20= @@=20ts_record_change=20(ptrdiff_t=20start_byte,=20ptrdiff_t=20= old_end_byte,=0A=20=20=20=20=20=20=20XTS_PARSER=20= (lisp_parser)->need_reparse=20=3D=20true;=0A=20=20=20=20=20=20=20= parser_list=20=3D=20Fcdr=20(parser_list);=0A=20=20=20=20=20}=0A-=0A=20}=0A= =20=0A=20/*=20Parse=20the=20buffer.=20=20We=20don't=20parse=20until=20we=20= have=20to.=20When=20we=20have=0A@@=20-91,9=20+94,19=20@@=20= ts_ensure_parsed=20(Lisp_Object=20parser)=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=20=20TSTree=20*new_tree=20=3D=20= ts_parser_parse(ts_parser,=20tree,=20input);=0A+=20=20/*=20This=20should=20= be=20very=20rare:=20it=20only=20happens=20when=201)=20language=20is=20= not=0A+=20=20=20=20=20set=20(impossible=20in=20Emacs=20because=20the=20= user=20has=20to=20supply=20a=0A+=20=20=20=20=20language=20to=20create=20= a=20parser),=202)=20parse=20canceled=20due=20to=20timeout=0A+=20=20=20=20= =20(impossible=20because=20we=20don't=20set=20a=20timeout),=203)=20parse=20= canceled=0A+=20=20=20=20=20due=20to=20cancellation=20flag=20(impossible=20= because=20we=20don't=20set=20the=0A+=20=20=20=20=20flag).=20=20(See=20= comments=20for=20ts_parser_parse=20in=0A+=20=20=20=20=20= tree_sitter/api.h.)=20=20*/=0A+=20=20if=20(new_tree=20=3D=3D=20NULL)=0A+=20= =20=20=20signal_error=20("Parse=20failed",=20parser);=0A=20=20=20= ts_tree_delete=20(tree);=0A=20=20=20XTS_PARSER=20(parser)->tree=20=3D=20= new_tree;=0A=20=20=20XTS_PARSER=20(parser)->need_reparse=20=3D=20false;=0A= +=20=20TSNode=20node=20=3D=20ts_tree_root_node=20(new_tree);=0A=20}=0A=20= =0A=20/*=20This=20is=20the=20read=20function=20provided=20to=20= tree-sitter=20to=20read=20from=20a=0A@@=20-103,9=20+116,6=20@@=20= ts_ensure_parsed=20(Lisp_Object=20parser)=0A=20ts_read_buffer=20(void=20= *buffer,=20uint32_t=20byte_index,=0A=20=09=09TSPoint=20position,=20= uint32_t=20*bytes_read)=0A=20{=0A-=20=20if=20(!BUFFER_LIVE_P=20((struct=20= buffer=20*)=20buffer))=0A-=20=20=20=20error=20("BUFFER=20is=20not=20= live");=0A-=0A=20=20=20ptrdiff_t=20byte_pos=20=3D=20byte_index=20+=201;=0A= =20=0A=20=20=20/*=20Read=20one=20character.=20=20Tree-sitter=20wants=20= us=20to=20set=20bytes_read=20to=200=0A@@=20-114,8=20+124,17=20@@=20= ts_read_buffer=20(void=20*buffer,=20uint32_t=20byte_index,=0A=20=20=20=20= =20=20string.=20=20*/=0A=20=20=20char=20*beg;=0A=20=20=20int=20len;=0A+=20= =20/*=20This=20function=20could=20run=20from=20a=20user=20command,=20so=20= it=20is=20better=20to=0A+=20=20=20=20=20do=20nothing=20instead=20of=20= raising=20an=20error.=20(It=20was=20a=20pain=20in=20the=20a**=0A+=20=20=20= =20=20to=20read=20mega-if-conditions=20in=20Emacs=20source,=20so=20I=20= write=20the=20two=0A+=20=20=20=20=20branches=20separately,=20hoping=20= the=20compiler=20can=20merge=20them.)=20=20*/=0A+=20=20if=20= (!BUFFER_LIVE_P=20((struct=20buffer=20*)=20buffer))=0A+=20=20=20=20{=0A+=20= =20=20=20=20=20beg=20=3D=20"";=0A+=20=20=20=20=20=20len=20=3D=200;=0A+=20= =20=20=20}=0A=20=20=20//=20TODO=20BUF_ZV_BYTE?=0A-=20=20if=20(byte_pos=20= >=3D=20BUF_Z_BYTE=20((struct=20buffer=20*)=20buffer))=0A+=20=20else=20if=20= (byte_pos=20>=3D=20BUF_Z_BYTE=20((struct=20buffer=20*)=20buffer))=0A=20=20= =20=20=20{=0A=20=20=20=20=20=20=20beg=20=3D=20"";=0A=20=20=20=20=20=20=20= len=20=3D=200;=0A@@=20-123,19=20+142,23=20@@=20ts_read_buffer=20(void=20= *buffer,=20uint32_t=20byte_index,=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,=20= byte_pos);=0A-=20=20=20=20=20=20len=20=3D=20next_char_len(byte_pos);=0A+=20= =20=20=20=20=20len=20=3D=20BYTES_BY_CHAR_HEAD=20((int)=20beg);=0A=20=20=20= =20=20}=0A=20=20=20*bytes_read=20=3D=20(uint32_t)=20len;=0A=20=0A=20=20=20= return=20beg;=0A=20}=0A=20=0A+/***=20Creators=20and=20accessors=20for=20= parser=20and=20node=20*/=0A+=0A=20/*=20Wrap=20the=20parser=20in=20a=20= Lisp_Object=20to=20be=20used=20in=20the=20Lisp=20machine.=20=20*/=0A=20= Lisp_Object=0A-make_ts_parser=20(struct=20buffer=20*buffer,=20TSParser=20= *parser,=20TSTree=20*tree)=0A+make_ts_parser=20(struct=20buffer=20= *buffer,=20TSParser=20*parser,=0A+=09=09TSTree=20*tree,=20Lisp_Object=20= name)=0A=20{=0A=20=20=20struct=20Lisp_TS_Parser=20*lisp_parser=0A-=20=20=20= =20=3D=20ALLOCATE_PLAIN_PSEUDOVECTOR=20(struct=20Lisp_TS_Parser,=20= PVEC_TS_PARSER);=0A+=20=20=20=20=3D=20ALLOCATE_PSEUDOVECTOR=20(struct=20= Lisp_TS_Parser,=20name,=20PVEC_TS_PARSER);=0A+=20=20lisp_parser->name=20= =3D=20name;=0A=20=20=20lisp_parser->buffer=20=3D=20buffer;=0A=20=20=20= lisp_parser->parser=20=3D=20parser;=0A=20=20=20lisp_parser->tree=20=3D=20= tree;=0A@@=20-156,17=20+179,35=20@@=20make_ts_node=20(Lisp_Object=20= parser,=20TSNode=20node)=0A=20=20=20return=20make_lisp_ptr=20(lisp_node,=20= Lisp_Vectorlike);=0A=20}=0A=20=0A+DEFUN=20("tree-sitter-node-parser",=0A= +=20=20=20=20=20=20=20Ftree_sitter_node_parser,=20= Stree_sitter_node_parser,=0A+=20=20=20=20=20=20=201,=201,=200,=0A+=20=20=20= =20=20=20=20doc:=20/*=20Return=20the=20parser=20to=20which=20NODE=20= belongs.=20=20*/)=0A+=20=20(Lisp_Object=20node)=0A+{=0A+=20=20= CHECK_TS_NODE=20(node);=0A+=20=20return=20XTS_NODE=20(node)->parser;=0A= +}=0A=20=0A=20DEFUN=20("tree-sitter-create-parser",=0A=20=20=20=20=20=20=20= =20Ftree_sitter_create_parser,=20Stree_sitter_create_parser,=0A-=20=20=20= =20=20=20=202,=202,=200,=0A+=20=20=20=20=20=20=202,=203,=200,=0A=20=20=20= =20=20=20=20=20doc:=20/*=20Create=20and=20return=20a=20parser=20in=20= BUFFER=20for=20LANGUAGE.=0A+=0A=20The=20parser=20is=20automatically=20= added=20to=20BUFFER's=0A=20`tree-sitter-parser-list'.=20=20LANGUAGE=20= should=20be=20the=20language=20provided=0A-by=20a=20tree-sitter=20= language=20dynamic=20module.=20=20*/)=0A-=20=20(Lisp_Object=20buffer,=20= Lisp_Object=20language)=0A+by=20a=20tree-sitter=20language=20dynamic=20= module.=0A+=0A+NAME=20(a=20string)=20is=20the=20name=20assigned=20to=20= the=20parser,=20like=20the=20name=20for=0A+a=20process.=20=20Unlike=20= process=20names,=20not=20care=20is=20taken=20to=20make=20each=0A= +parser's=20name=20unique.=20=20By=20default,=20no=20name=20is=20= assigned=20to=20the=20parser;=0A+the=20only=20consequence=20of=20that=20= is=20you=20can't=20use=0A+`tree-sitter-get-parser'=20to=20find=20the=20= parser=20by=20its=20name.=20=20*/)=0A+=20=20(Lisp_Object=20buffer,=20= Lisp_Object=20language,=20Lisp_Object=20name)=0A=20{=0A=20=20=20= CHECK_BUFFER(buffer);=0A+=20=20if=20(!NILP=20(name))=0A+=20=20=20=20= CHECK_STRING=20(name);=0A=20=0A=20=20=20/*=20LANGUAGE=20is=20a=20= USER_PTR=20that=20contains=20the=20pointer=20to=20a=20TSLanguage=0A=20=20= =20=20=20=20struct.=20=20*/=0A@@=20-175,9=20+216,8=20@@=20DEFUN=20= ("tree-sitter-create-parser",=0A=20=20=20ts_parser_set_language=20= (parser,=20lang);=0A=20=0A=20=20=20Lisp_Object=20lisp_parser=0A-=20=20=20= =20=3D=20make_ts_parser=20(XBUFFER(buffer),=20parser,=20NULL);=0A+=20=20=20= =20=3D=20make_ts_parser=20(XBUFFER(buffer),=20parser,=20NULL,=20name);=0A= =20=0A-=20=20//=20FIXME:=20Is=20this=20the=20correct=20way=20to=20set=20= a=20buffer-local=20variable?=0A=20=20=20struct=20buffer=20*old_buffer=20= =3D=20current_buffer;=0A=20=20=20set_buffer_internal=20(XBUFFER=20= (buffer));=0A=20=0A@@=20-188,6=20+228,30=20@@=20DEFUN=20= ("tree-sitter-create-parser",=0A=20=20=20return=20lisp_parser;=0A=20}=0A=20= =0A+DEFUN=20("tree-sitter-parser-buffer",=0A+=20=20=20=20=20=20=20= Ftree_sitter_parser_buffer,=20Stree_sitter_parser_buffer,=0A+=20=20=20=20= =20=20=201,=201,=200,=0A+=20=20=20=20=20=20=20doc:=20/*=20Return=20the=20= buffer=20of=20PARSER.=20=20*/)=0A+=20=20(Lisp_Object=20parser)=0A+{=0A+=20= =20CHECK_TS_PARSER=20(parser);=0A+=20=20Lisp_Object=20buf;=0A+=20=20= XSETBUFFER=20(buf,=20XTS_PARSER=20(parser)->buffer);=0A+=20=20return=20= buf;=0A+}=0A+=0A+DEFUN=20("tree-sitter-parser-name",=0A+=20=20=20=20=20=20= =20Ftree_sitter_parser_name,=20Stree_sitter_parser_name,=0A+=20=20=20=20=20= =20=201,=201,=200,=0A+=20=20=20=20=20=20=20doc:=20/*=20Return=20parser's=20= name.=20=20*/)=0A+=20=20(Lisp_Object=20parser)=0A+{=0A+=20=20= CHECK_TS_PARSER=20(parser);=0A+=20=20return=20XTS_PARSER=20= (parser)->name;=0A+}=0A+=0A+/***=20Parser=20API=20*/=0A+=0A=20DEFUN=20= ("tree-sitter-parser-root-node",=0A=20=20=20=20=20=20=20=20= Ftree_sitter_parser_root_node,=20Stree_sitter_parser_root_node,=0A=20=20=20= =20=20=20=20=201,=201,=200,=0A@@=20-200,7=20+264,8=20@@=20DEFUN=20= ("tree-sitter-parser-root-node",=0A=20=20=20return=20make_ts_node=20= (parser,=20root_node);=0A=20}=0A=20=0A-DEFUN=20("tree-sitter-parse",=20= Ftree_sitter_parse,=20Stree_sitter_parse,=0A+DEFUN=20= ("tree-sitter-parse-string",=0A+=20=20=20=20=20=20=20= Ftree_sitter_parse_string,=20Stree_sitter_parse_string,=0A=20=20=20=20=20= =20=20=202,=202,=200,=0A=20=20=20=20=20=20=20=20doc:=20/*=20Parse=20= STRING=20and=20return=20the=20root=20node.=0A=20LANGUAGE=20should=20be=20= the=20language=20provided=20by=20a=20tree-sitter=20language=0A@@=20= -219,23=20+284,20=20@@=20DEFUN=20("tree-sitter-parse",=20= Ftree_sitter_parse,=20Stree_sitter_parse,=0A=20=09=09=09=09=09=20SSDATA=20= (string),=0A=20=09=09=09=09=09=20strlen=20(SSDATA=20(string)));=0A=20=0A= -=20=20/*=20See=20comment=20for=20ts_parser_parse=20in=20= tree_sitter/api.h=0A-=20=20=20=20=20for=20possible=20reasons=20for=20a=20= failure.=20=20*/=0A+=20=20/*=20See=20comment=20in=20ts_ensure_parsed=20= for=20possible=20reasons=20for=20a=0A+=20=20=20=20=20failure.=20=20*/=0A=20= =20=20if=20(tree=20=3D=3D=20NULL)=0A=20=20=20=20=20signal_error=20= ("Failed=20to=20parse=20STRING",=20string);=0A=20=0A=20=20=20TSNode=20= root_node=20=3D=20ts_tree_root_node=20(tree);=0A=20=0A-=20=20Lisp_Object=20= lisp_parser=20=3D=20make_ts_parser=20(NULL,=20parser,=20tree);=0A+=20=20= Lisp_Object=20lisp_parser=20=3D=20make_ts_parser=20(NULL,=20parser,=20= tree,=20Qnil);=0A=20=20=20Lisp_Object=20lisp_node=20=3D=20make_ts_node=20= (lisp_parser,=20root_node);=0A=20=0A=20=20=20return=20lisp_node;=0A=20}=0A= =20=0A-/*=20Below=20this=20point=20are=20uninteresting=20mechanical=20= translations=20of=0A-=20=20=20tree-sitter=20API.=20=20*/=0A-=0A-/*=20= Node=20functions.=20=20*/=0A+/***=20Node=20API=20=20*/=0A=20=0A=20DEFUN=20= ("tree-sitter-node-type",=0A=20=20=20=20=20=20=20=20= Ftree_sitter_node_type,=20Stree_sitter_node_type,=201,=201,=200,=0A@@=20= -245,9=20+307,31=20@@=20DEFUN=20("tree-sitter-node-type",=0A=20=20=20= CHECK_TS_NODE=20(node);=0A=20=20=20TSNode=20ts_node=20=3D=20XTS_NODE=20= (node)->node;=0A=20=20=20const=20char=20*type=20=3D=20= ts_node_type(ts_node);=0A+=20=20//=20TODO:=20Maybe=20return=20a=20string=20= instead.=0A=20=20=20return=20intern_c_string=20(type);=0A=20}=0A=20=0A= +DEFUN=20("tree-sitter-node-start-byte",=0A+=20=20=20=20=20=20=20= Ftree_sitter_node_start_byte,=20Stree_sitter_node_start_byte,=201,=201,=20= 0,=0A+=20=20=20=20=20=20=20doc:=20/*=20Return=20the=20NODE's=20start=20= byte=20position.=20=20*/)=0A+=20=20(Lisp_Object=20node)=0A+{=0A+=20=20= CHECK_TS_NODE=20(node);=0A+=20=20TSNode=20ts_node=20=3D=20XTS_NODE=20= (node)->node;=0A+=20=20uint32_t=20start_byte=20=3D=20= ts_node_start_byte(ts_node);=0A+=20=20return=20make_fixnum(start_byte=20= +=201);=0A+}=0A+=0A+DEFUN=20("tree-sitter-node-end-byte",=0A+=20=20=20=20= =20=20=20Ftree_sitter_node_end_byte,=20Stree_sitter_node_end_byte,=201,=20= 1,=200,=0A+=20=20=20=20=20=20=20doc:=20/*=20Return=20the=20NODE's=20end=20= byte=20position.=20=20*/)=0A+=20=20(Lisp_Object=20node)=0A+{=0A+=20=20= CHECK_TS_NODE=20(node);=0A+=20=20TSNode=20ts_node=20=3D=20XTS_NODE=20= (node)->node;=0A+=20=20uint32_t=20end_byte=20=3D=20= ts_node_end_byte(ts_node);=0A+=20=20return=20make_fixnum(end_byte=20+=20= 1);=0A+}=0A=20=0A=20DEFUN=20("tree-sitter-node-string",=0A=20=20=20=20=20= =20=20=20Ftree_sitter_node_string,=20Stree_sitter_node_string,=201,=201,=20= 0,=0A@@=20-303,9=20+387,9=20@@=20DEFUN=20("tree-sitter-node-check",=0A=20= =20=20=20=20=20=20=20Ftree_sitter_node_check,=20Stree_sitter_node_check,=20= 2,=202,=200,=0A=20=20=20=20=20=20=20=20doc:=20/*=20Return=20non-nil=20if=20= NODE=20is=20in=20condition=20COND,=20nil=20otherwise.=0A=20=0A-COND=20= could=20be=20'named,=20'missing,=20'extra,=20'has-error.=20=20Named=20= nodes=0A-correspond=20to=20named=20rules=20in=20the=20grammar,=20whereas=20= "anonymous"=20nodes=0A-correspond=20to=20string=20literals=20in=20the=20= grammar.=0A+COND=20could=20be=20'named,=20'missing,=20'extra,=20= 'has-changes,=20'has-error.=0A+Named=20nodes=20correspond=20to=20named=20= rules=20in=20the=20grammar,=20whereas=0A+"anonymous"=20nodes=20= correspond=20to=20string=20literals=20in=20the=20grammar.=0A=20=0A=20= Missing=20nodes=20are=20inserted=20by=20the=20parser=20in=20order=20to=20= recover=20from=0A=20certain=20kinds=20of=20syntax=20errors,=20i.e.,=20= should=20be=20there=20but=20not=20there.=0A@@=20-313,6=20+397,9=20@@=20= DEFUN=20("tree-sitter-node-check",=0A=20Extra=20nodes=20represent=20= things=20like=20comments,=20which=20are=20not=20required=20the=0A=20= grammar,=20but=20can=20appear=20anywhere.=0A=20=0A+A=20node=20"has=20= changes"=20if=20the=20buffer=20changed=20since=20the=20node=20is=0A= +created.=20(Don't=20forget=20the=20"s"=20at=20the=20end=20of=20= 'has-changes.)=0A+=0A=20A=20node=20"has=20error"=20if=20itself=20is=20a=20= syntax=20error=20or=20contains=20any=20syntax=0A=20errors.=20=20*/)=0A=20= =20=20(Lisp_Object=20node,=20Lisp_Object=20cond)=0A@@=20-329,7=20+416,10=20= @@=20DEFUN=20("tree-sitter-node-check",=0A=20=20=20=20=20result=20=3D=20= ts_node_is_extra=20(ts_node);=0A=20=20=20else=20if=20(EQ=20(cond,=20= Qhas_error))=0A=20=20=20=20=20result=20=3D=20ts_node_has_error=20= (ts_node);=0A+=20=20else=20if=20(EQ=20(cond,=20Qhas_changes))=0A+=20=20=20= =20result=20=3D=20ts_node_has_changes=20(ts_node);=0A=20=20=20else=0A+=20= =20=20=20//=20TODO:=20Is=20this=20a=20good=20error=20message?=0A=20=20=20= =20=20signal_error=20("Expecting=20one=20of=20four=20symbols,=20see=20= docstring",=20cond);=0A=20=20=20return=20result=20?=20Qt=20:=20Qnil;=0A=20= }=0A@@=20-432,8=20+522,177=20@@=20DEFUN=20= ("tree-sitter-node-prev-sibling",=0A=20=20=20return=20= make_ts_node(XTS_NODE=20(node)->parser,=20sibling);=0A=20}=0A=20=0A= +DEFUN=20("tree-sitter-node-first-child-for-byte",=0A+=20=20=20=20=20=20=20= Ftree_sitter_node_first_child_for_byte,=0A+=20=20=20=20=20=20=20= Stree_sitter_node_first_child_for_byte,=202,=203,=200,=0A+=20=20=20=20=20= =20=20doc:=20/*=20Return=20the=20first=20child=20of=20NODE=20on=20POS.=0A= +Specifically,=20return=20the=20first=20child=20that=20extends=20beyond=20= POS.=20=20POS=20is=0A+a=20byte=20position=20in=20the=20buffer=20counting=20= from=201.=20=20Return=20nil=20if=20there=0A+isn't=20any.=20=20If=20NAMED=20= is=20non-nil,=20look=20for=20named=20child=20only.=20=20NAMED=0A= +defaults=20to=20nil.=20=20Note=20that=20this=20function=20returns=20an=20= immediate=20child,=0A+not=20the=20smallest=20(grand)child.=20=20*/)=0A+=20= =20(Lisp_Object=20node,=20Lisp_Object=20pos,=20Lisp_Object=20named)=0A+{=0A= +=20=20CHECK_INTEGER=20(pos);=0A+=0A+=20=20struct=20buffer=20*buf=20=3D=20= (XTS_PARSER=20(XTS_NODE=20(node)->parser)->buffer);=0A+=20=20ptrdiff_t=20= byte_pos=20=3D=20XFIXNUM=20(pos);=0A+=0A+=20=20if=20(byte_pos=20<=20= BUF_BEGV_BYTE=20(buf)=20||=20byte_pos=20>=20BUF_ZV_BYTE=20(buf))=0A+=20=20= =20=20xsignal1=20(Qargs_out_of_range,=20pos);=0A+=0A+=20=20TSNode=20= ts_node=20=3D=20XTS_NODE=20(node)->node;=0A+=20=20TSNode=20child;=0A+=20=20= if=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= else=0A+=20=20=20=20child=20=3D=20ts_node_first_named_child_for_byte=20= (ts_node,=20byte_pos=20-=201);=0A+=0A+=20=20if=20= (ts_node_is_null(child))=0A+=20=20=20=20return=20Qnil;=0A+=0A+=20=20= return=20make_ts_node(XTS_NODE=20(node)->parser,=20child);=0A+}=0A+=0A= +DEFUN=20("tree-sitter-node-descendant-for-byte-range",=0A+=20=20=20=20=20= =20=20Ftree_sitter_node_descendant_for_byte_range,=0A+=20=20=20=20=20=20=20= Stree_sitter_node_descendant_for_byte_range,=203,=204,=200,=0A+=20=20=20=20= =20=20=20doc:=20/*=20Return=20the=20smallest=20node=20that=20covers=20= BEG=20to=20END.=0A+The=20returned=20node=20is=20a=20descendant=20of=20= NODE.=20=20POS=20is=20a=20byte=20position=0A+counting=20from=201.=20=20= Return=20nil=20if=20there=20isn't=20any.=20=20If=20NAMED=20is=20non-nil,=0A= +look=20for=20named=20child=20only.=20=20NAMED=20defaults=20to=20nil.=20=20= */)=0A+=20=20(Lisp_Object=20node,=20Lisp_Object=20beg,=20Lisp_Object=20= end,=20Lisp_Object=20named)=0A+{=0A+=20=20CHECK_INTEGER=20(beg);=0A+=20=20= CHECK_INTEGER=20(end);=0A+=0A+=20=20struct=20buffer=20*buf=20=3D=20= (XTS_PARSER=20(XTS_NODE=20(node)->parser)->buffer);=0A+=20=20ptrdiff_t=20= byte_beg=20=3D=20XFIXNUM=20(beg);=0A+=20=20ptrdiff_t=20byte_end=20=3D=20= XFIXNUM=20(end);=0A+=0A+=20=20/*=20Checks=20for=20BUFFER_BEG=20<=3D=20= BEG=20<=3D=20END=20<=3D=20BUFFER_END.=20=20*/=0A+=20=20if=20= (!(BUF_BEGV_BYTE=20(buf)=20<=3D=20byte_beg=0A+=09&&=20byte_beg=20<=3D=20= byte_end=0A+=09&&=20byte_end=20<=3D=20BUF_ZV_BYTE=20(buf)))=0A+=20=20=20=20= xsignal2=20(Qargs_out_of_range,=20beg,=20end);=0A+=0A+=20=20TSNode=20= ts_node=20=3D=20XTS_NODE=20(node)->node;=0A+=20=20TSNode=20child;=0A+=20=20= if=20(NILP=20(named))=0A+=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=20else=0A+=20=20=20=20= child=20=3D=20ts_node_named_descendant_for_byte_range=0A+=20=20=20=20=20=20= (ts_node,=20byte_beg=20-=201,=20byte_end=20-=201);=0A+=0A+=20=20if=20= (ts_node_is_null(child))=0A+=20=20=20=20return=20Qnil;=0A+=0A+=20=20= return=20make_ts_node(XTS_NODE=20(node)->parser,=20child);=0A+}=0A+=0A=20= /*=20Query=20functions=20*/=0A=20=0A+Lisp_Object=20= ts_query_error_to_string=20(TSQueryError=20error)=0A+{=0A+=20=20char=20= *error_name;=0A+=20=20switch=20(error)=0A+=20=20=20=20{=0A+=20=20=20=20= case=20TSQueryErrorNone:=0A+=20=20=20=20=20=20error_name=20=3D=20"none";=0A= +=20=20=20=20=20=20break;=0A+=20=20=20=20case=20TSQueryErrorSyntax:=0A+=20= =20=20=20=20=20error_name=20=3D=20"syntax";=0A+=20=20=20=20=20=20break;=0A= +=20=20=20=20case=20TSQueryErrorNodeType:=0A+=20=20=20=20=20=20= error_name=20=3D=20"node=20type";=0A+=20=20=20=20=20=20break;=0A+=20=20=20= =20case=20TSQueryErrorField:=0A+=20=20=20=20=20=20error_name=20=3D=20= "field";=0A+=20=20=20=20=20=20break;=0A+=20=20=20=20case=20= TSQueryErrorCapture:=0A+=20=20=20=20=20=20error_name=20=3D=20"capture";=0A= +=20=20=20=20=20=20break;=0A+=20=20=20=20case=20TSQueryErrorStructure:=0A= +=20=20=20=20=20=20error_name=20=3D=20"structure";=0A+=20=20=20=20=20=20= break;=0A+=20=20=20=20}=0A+=20=20return=20=20make_pure_c_string=20= (error_name,=20strlen(error_name));=0A+}=0A+=0A+DEFUN=20= ("tree-sitter-query-capture",=0A+=20=20=20=20=20=20=20= Ftree_sitter_query_capture,=0A+=20=20=20=20=20=20=20= Stree_sitter_query_capture,=202,=204,=200,=0A+=20=20=20=20=20=20=20doc:=20= /*=20Query=20NODE=20with=20PATTERN.=0A+=0A+Returns=20a=20list=20of=20= (CAPTURE_NAME=20.=20NODE).=20=20CAPTURE_NAME=20is=20the=20name=0A= +assigned=20to=20the=20node=20in=20PATTERN.=20=20NODE=20is=20the=20= captured=20node.=0A+=0A+PATTERN=20is=20a=20string=20containing=20one=20= or=20more=20matching=20patterns.=20=20See=0A+manual=20for=20further=20= explanation=20for=20how=20to=20write=20a=20match=20pattern.=0A+=0A+BEG=20= and=20END,=20if=20_both_=20non-nil,=20specifies=20the=20range=20in=20= which=20the=20query=0A+is=20executed.=0A+=0A+Return=20nil=20if=20the=20= query=20failed.=20=20*/)=0A+=20=20(Lisp_Object=20node,=20Lisp_Object=20= pattern,=0A+=20=20=20Lisp_Object=20beg,=20Lisp_Object=20end)=0A+{=0A+=20=20= CHECK_TS_NODE=20(node);=0A+=20=20CHECK_STRING=20(pattern);=0A+=0A+=20=20= TSNode=20ts_node=20=3D=20XTS_NODE=20(node)->node;=0A+=20=20Lisp_Object=20= lisp_parser=20=3D=20XTS_NODE=20(node)->parser;=0A+=20=20const=20= TSLanguage=20*lang=20=3D=20ts_parser_language=0A+=20=20=20=20(XTS_PARSER=20= (lisp_parser)->parser);=0A+=20=20char=20*source=20=3D=20SSDATA=20= (pattern);=0A+=0A+=20=20uint32_t=20error_offset;=0A+=20=20uint32_t=20= error_type;=0A+=20=20TSQuery=20*query=20=3D=20ts_query_new=20(lang,=20= source,=20strlen=20(source),=0A+=09=09=09=09=20&error_offset,=20= &error_type);=0A+=20=20TSQueryCursor=20*cursor=20=3D=20= ts_query_cursor_new=20();=0A+=0A+=20=20if=20(query=20=3D=3D=20NULL)=0A+=20= =20=20=20{=0A+=20=20=20=20=20=20//=20FIXME:=20Signal=20an=20error?=0A+=20= =20=20=20=20=20return=20Qnil;=0A+=20=20=20=20}=0A+=20=20if=20(!NILP=20= (beg)=20&&=20!NILP=20(end))=0A+=20=20=20=20{=0A+=20=20=20=20=20=20= EMACS_INT=20beg_byte=20=3D=20XFIXNUM=20(beg);=0A+=20=20=20=20=20=20= EMACS_INT=20end_byte=20=3D=20XFIXNUM=20(end);=0A+=20=20=20=20=20=20= ts_query_cursor_set_byte_range=0A+=09(cursor,=20(uint32_t)=20beg_byte=20= -=201,=20(uint32_t)=20end_byte=20-=201);=0A+=20=20=20=20}=0A+=0A+=20=20= ts_query_cursor_exec=20(cursor,=20query,=20ts_node);=0A+=20=20= TSQueryMatch=20match;=0A+=20=20TSQueryCapture=20capture;=0A+=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=20while=20= (ts_query_cursor_next_match=20(cursor,=20&match))=0A+=20=20=20=20{=0A+=20= =20=20=20=20=20const=20TSQueryCapture=20*captures=20=3D=20= match.captures;=0A+=20=20=20=20=20=20for=20(int=20idx=3D0;=20idx=20<=20= match.capture_count;=20idx++)=0A+=09{=0A+=09=20=20capture=20=3D=20= captures[idx];=0A+=09=20=20captured_node=20=3D=20= make_ts_node(lisp_parser,=20capture.node);=0A+=09=20=20capture_name=20=3D=20= ts_query_capture_name_for_id=0A+=09=20=20=20=20(query,=20capture.index,=20= &capture_name_len);=0A+=09=20=20entry=20=3D=20Fcons=20(intern_c_string=20= (capture_name),=0A+=09=09=09=20captured_node);=0A+=09=20=20result=20=3D=20= Fcons=20(entry,=20result);=0A+=09}=0A+=20=20=20=20}=0A+=20=20= ts_query_delete=20(query);=0A+=20=20ts_query_cursor_delete=20(cursor);=0A= +=20=20return=20Freverse=20(result);=0A+}=0A+=0A=20/*=20Initialize=20the=20= tree-sitter=20routines.=20=20*/=0A=20void=0A=20syms_of_tree_sitter=20= (void)=0A@@=20-443,11=20+702,18=20@@=20syms_of_tree_sitter=20(void)=0A=20= =20=20DEFSYM=20(Qnamed,=20"named");=0A=20=20=20DEFSYM=20(Qmissing,=20= "missing");=0A=20=20=20DEFSYM=20(Qextra,=20"extra");=0A+=20=20DEFSYM=20= (Qhas_changes,=20"has-changes");=0A=20=20=20DEFSYM=20(Qhas_error,=20= "has-error");=0A=20=0A+=20=20DEFSYM=20(Qtree_sitter_query_error,=20= "tree-sitter-query-error");=0A+=20=20Fput=20(Qtree_sitter_query_error,=20= Qerror_conditions,=0A+=09pure_list=20(Qtree_sitter_query_error,=20= Qerror));=0A+=20=20Fput=20(Qtree_sitter_query_error,=20Qerror_message,=0A= +=09build_pure_c_string=20("Error=20with=20query=20pattern"))=0A+=0A=20=20= =20DEFSYM=20(Qtree_sitter_parser_list,=20"tree-sitter-parser-list");=0A-=20= =20DEFVAR_LISP=20("ts-parser-list",=20Vtree_sitter_parser_list,=0A-=09=09= =20=20=20=20=20doc:=20/*=20A=20list=20of=20tree-sitter=20parsers.=0A+=20=20= DEFVAR_LISP=20("tree-sitter-parser-list",=20Vtree_sitter_parser_list,=0A= +=09=20=20=20=20=20=20=20doc:=20/*=20A=20list=20of=20tree-sitter=20= parsers.=0A=20//=20TODO:=20more=20doc.=0A=20If=20you=20removed=20a=20= parser=20from=20this=20list,=20do=20not=20put=20it=20back=20in.=20=20= */);=0A=20=20=20Vtree_sitter_parser_list=20=3D=20Qnil;=0A@@=20-455,11=20= +721,19=20@@=20syms_of_tree_sitter=20(void)=0A=20=0A=20=20=20defsubr=20= (&Stree_sitter_parser_p);=0A=20=20=20defsubr=20(&Stree_sitter_node_p);=0A= +=0A+=20=20defsubr=20(&Stree_sitter_node_parser);=0A+=0A=20=20=20defsubr=20= (&Stree_sitter_create_parser);=0A+=20=20defsubr=20= (&Stree_sitter_parser_buffer);=0A+=20=20defsubr=20= (&Stree_sitter_parser_name);=0A+=0A=20=20=20defsubr=20= (&Stree_sitter_parser_root_node);=0A-=20=20defsubr=20= (&Stree_sitter_parse);=0A+=20=20defsubr=20(&Stree_sitter_parse_string);=0A= =20=0A=20=20=20defsubr=20(&Stree_sitter_node_type);=0A+=20=20defsubr=20= (&Stree_sitter_node_start_byte);=0A+=20=20defsubr=20= (&Stree_sitter_node_end_byte);=0A=20=20=20defsubr=20= (&Stree_sitter_node_string);=0A=20=20=20defsubr=20= (&Stree_sitter_node_parent);=0A=20=20=20defsubr=20= (&Stree_sitter_node_child);=0A@@=20-469,4=20+743,8=20@@=20= syms_of_tree_sitter=20(void)=0A=20=20=20defsubr=20= (&Stree_sitter_node_child_by_field_name);=0A=20=20=20defsubr=20= (&Stree_sitter_node_next_sibling);=0A=20=20=20defsubr=20= (&Stree_sitter_node_prev_sibling);=0A+=20=20defsubr=20= (&Stree_sitter_node_first_child_for_byte);=0A+=20=20defsubr=20= (&Stree_sitter_node_descendant_for_byte_range);=0A+=0A+=20=20defsubr=20= (&Stree_sitter_query_capture);=0A=20}=0Adiff=20--git=20= a/src/tree_sitter.h=20b/src/tree_sitter.h=0Aindex=20= a7e2a2d670..e9b4a71326=20100644=0A---=20a/src/tree_sitter.h=0A+++=20= b/src/tree_sitter.h=0A@@=20-33,6=20+33,7=20@@=20#define=20= EMACS_TREE_SITTER_H=0A=20struct=20Lisp_TS_Parser=0A=20{=0A=20=20=20union=20= vectorlike_header=20header;=0A+=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-95,7=20+96,8=20@@=20ts_record_change=20= (ptrdiff_t=20start_byte,=20ptrdiff_t=20old_end_byte,=0A=20=09=09=20=20= ptrdiff_t=20new_end_byte);=0A=20=0A=20Lisp_Object=0A-make_ts_parser=20= (struct=20buffer=20*buffer,=20TSParser=20*parser,=20TSTree=20*tree);=0A= +make_ts_parser=20(struct=20buffer=20*buffer,=20TSParser=20*parser,=0A+=09= =09TSTree=20*tree,=20Lisp_Object=20name);=0A=20=0A=20Lisp_Object=0A=20= make_ts_node=20(Lisp_Object=20parser,=20TSNode=20node);=0Adiff=20--git=20= a/test/src/tree-sitter-tests.el=20b/test/src/tree-sitter-tests.el=0A= index=20cb1c464d3a..c61ad678d2=20100644=0A---=20= a/test/src/tree-sitter-tests.el=0A+++=20b/test/src/tree-sitter-tests.el=0A= @@=20-21,6=20+21,7=20@@=0A=20=0A=20(require=20'ert)=0A=20(require=20= 'tree-sitter-json)=0A+(require=20'tree-sitter)=0A=20=0A=20(ert-deftest=20= tree-sitter-basic-parsing=20()=0A=20=20=20"Test=20basic=20parsing=20= routines."=0A@@=20-52,12=20+53,13=20@@=20tree-sitter-basic-parsing=0A=20= (ert-deftest=20tree-sitter-node-api=20()=0A=20=20=20"Tests=20for=20node=20= API."=0A=20=20=20(with-temp-buffer=0A-=20=20=20=20(insert=20= "[1,2,{\"name\":=20\"Bob\"},3]")=0A=20=20=20=20=20(let=20(parser=20= root-node=20doc-node=20object-node=20pair-node)=0A-=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(current-buffer)=20(tree-sitter-json)))=0A= -=20=20=20=20=20=20(setq=20root-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= parser))=0A+=20=20=20=20=20=20(progn=0A+=20=20=20=20=20=20=20=20(insert=20= "[1,2,{\"name\":=20\"Bob\"},3]")=0A+=20=20=20=20=20=20=20=20(setq=20= parser=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=20root-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=20;;=20= `tree-sitter-node-type'.=0A=20=20=20=20=20=20=20(should=20(eq=20= 'document=20(tree-sitter-node-type=20root-node)))=0A=20=20=20=20=20=20=20= ;;=20`tree-sitter-node-check'.=0A@@=20-100,7=20+102,51=20@@=20= tree-sitter-node-api=0A=20=20=20=20=20=20=20(should=20(equal=20"(\",\")"=0A= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (tree-sitter-node-string=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(tree-sitter-node-prev-sibling=20object-node))))=0A= -=20=20=20=20=20=20)))=0A+=20=20=20=20=20=20;;=20= `tree-sitter-node-first-child-for-byte'.=0A+=20=20=20=20=20=20(should=20= (equal=20"(number)"=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(tree-sitter-node-string=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(tree-sitter-node-first-child-for-byte=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= doc-node=203=20t))))=0A+=20=20=20=20=20=20(should=20(equal=20"(\",\")"=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (tree-sitter-node-string=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(tree-sitter-node-first-child-for-byte=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20doc-node=20= 3))))=0A+=20=20=20=20=20=20;;=20= `tree-sitter-node-descendant-for-byte-range'.=0A+=20=20=20=20=20=20= (should=20(equal=20"(\"{\")"=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(tree-sitter-node-string=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20= (tree-sitter-node-descendant-for-byte-range=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20root-node=206=207))))=0A+=20=20= =20=20=20=20(should=20(equal=20"(object=20(pair=20key:=20(string=20= (string_content))=20value:=20(string=20(string_content))))"=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (tree-sitter-node-string=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(tree-sitter-node-descendant-for-byte-range=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20root-node=20= 6=207=20t)))))))=0A+=0A+(ert-deftest=20tree-sitter-query-api=20()=0A+=20=20= "Tests=20for=20query=20API."=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"[1,2,{\"name\":=20\"Bob\"},3]")=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=20root-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=20=20= (setq=20pattern=20"(string)=20@string=0A+(pair=20key:=20(_)=20@keyword)=0A= +(number)=20@number"))=0A+=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'((number=20.=20"1")=20(number=20= .=20"2")=0A+=20=20=20=20=20=20=20=20=20=20(keyword=20.=20"\"name\"")=0A+=20= =20=20=20=20=20=20=20=20=20(string=20.=20"\"name\"")=0A+=20=20=20=20=20=20= =20=20=20=20(string=20.=20"\"Bob\"")=0A+=20=20=20=20=20=20=20=20=20=20= (number=20.=20"3"))=0A+=20=20=20=20=20=20=20=20(mapcar=20(lambda=20= (entry)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(cons=20= (car=20entry)=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(tree-sitter-node-content=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(cdr=20entry))))=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20(tree-sitter-query-capture=20= root-node=20pattern)))))))=0A=20=0A=20(provide=20'tree-sitter-tests)=0A=20= ;;;=20tree-sitter-tests.el=20ends=20here=0A--=20=0A2.24.3=20(Apple=20= Git-128)=0A=0A= --Apple-Mail=_CB182ECC-FDB9-4900-A33D-A4E90410B14A--