From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christian Johansson Newsgroups: gmane.emacs.devel Subject: Re: New package emacs-parser-generator Date: Wed, 1 Dec 2021 08:52:07 +0100 Message-ID: <12F88CF0-4706-4C10-A76D-52CC0EEF8D0C@cvj.se> References: <8ECC2C6B-9BB0-442F-98A5-39AB88E2AC12@gmail.com> Mime-Version: 1.0 (1.0) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31411"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , =?utf-8?Q?Daniel_Mart=C3=ADn?= , monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 01 08:53:25 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 1msKQf-0007x8-An for ged-emacs-devel@m.gmane-mx.org; Wed, 01 Dec 2021 08:53:25 +0100 Original-Received: from localhost ([::1]:46482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1msKQd-0003qO-CW for ged-emacs-devel@m.gmane-mx.org; Wed, 01 Dec 2021 02:53:23 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:39778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1msKPY-0002Gu-04 for emacs-devel@gnu.org; Wed, 01 Dec 2021 02:52:16 -0500 Original-Received: from mailrelay1-3.pub.mailoutpod1-cph3.one.com ([46.30.212.10]:40996) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1msKPV-0004oA-Dq for emacs-devel@gnu.org; Wed, 01 Dec 2021 02:52:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cvj.se; s=20191106; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version:from: content-transfer-encoding:content-type:from; bh=7vA2LFG0Oc1i3kuLVdkSa+6hFfTtd3If+kyLO55KEu0=; b=kyBgxhKx2dlJZvRyFrzEZ+sAacVR1EzsfrzFGtOnJYREEspG66NaLnPOruHNSLHnY38IyU6mOMyxj 6wy2+qAAqp/VCAtmoHMFmw7JOVTBw7kpDPFT90sgv9i5c0DtAbbubSj36j1qGLJYQQq2rpB/NJoRSd QD+M7mZGLi1TYg+CCAhvzumgnj996fAUrbEmIjjYZ3sz0zl6/5GORWG7U8SFRwCl+WngTG6BDb4oBe pfCUbTv2Ry/Cp5VjI22p1/AAMnn69Y16L0T0WddOvt0RZ8tfjK/tgVvtVjQZ+BGvidXo43rMkA1tQ8 7jMu6PRxOC+jhD53M8glkA7AK65cesg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cvj.se; s=rsa1; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version:from: content-transfer-encoding:content-type:from; bh=7vA2LFG0Oc1i3kuLVdkSa+6hFfTtd3If+kyLO55KEu0=; b=a/Bx1pk/Ww7U2LZLgvF1/b8aqPcaGbxrgqgdTyJyvQGobBCE2gLnmrTZwhUKRsViWMgpjAebr65Pn BeT/z/Rp201N5umsX65eB6dzeqU+grOQZ1pVTflt8MmMmsQjKg8RYrQ5guKaADPkaSH6sOGHsTa6vu I5TY3EJUhsEfG9InibzVhKperq64NXR3cRGNzwjxB4yIB1gi39QMM4sKLs/L9UtWOGDVeWfpUeaOdD jnHkP79V8gP2zcwZHVZcrmQMDS0U1tbU2n+/EtVsKxPh1ytoQuWC0HrSux9y1AzUA+5Sk1VqNmCneT VglLJUnVMSPmidXMvsvNyTyS7pPSWZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=cvj.se; s=ed1; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version:from: content-transfer-encoding:content-type:from; bh=7vA2LFG0Oc1i3kuLVdkSa+6hFfTtd3If+kyLO55KEu0=; b=pFnwUwrpabF4UTn8JGg79SFeb+42Mquo91C///kiTemFjO9+xITRDiqSAXDM7PYvyAXNjshbyfS+C INLbaKFBA== X-HalOne-Cookie: be7336b6a8a3589b1609a41c5d2afbc816f03364 X-HalOne-ID: 94ef53b6-527b-11ec-b7dd-d0431ea8a283 Original-Received: from smtpclient.apple (c188-150-212-230.bredband.tele2.se [188.150.212.230]) by mailrelay1.pub.mailoutpod1-cph3.one.com (Halon) with ESMTPSA id 94ef53b6-527b-11ec-b7dd-d0431ea8a283; Wed, 01 Dec 2021 07:52:07 +0000 (UTC) In-Reply-To: <8ECC2C6B-9BB0-442F-98A5-39AB88E2AC12@gmail.com> X-Mailer: iPhone Mail (19A404) Received-SPF: none client-ip=46.30.212.10; envelope-from=christian@cvj.se; helo=mailrelay1-3.pub.mailoutpod1-cph3.one.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, MIME_QP_LONG_LINE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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:280593 Archived-At: Alright, could you give some more details about when a buffer parse is trigg= ered, is it via threads, is it sometimes incremental, does it work on a stri= ng copy of the buffer or on the buffer contents directly? Does treesitter expose a (faster) regexp matcher that perhaps can be used by= my library? Regards Christian > 29 nov. 2021 kl. 20:22 skrev Yuan Fu : >=20 > =EF=BB=BFThe tree-sitter integration doesn=E2=80=99t provide anything to d= efine a grammar nor generating a parser. It merely uses pre-defined grammar (= written by tree-sitter community) to parse buffers and produce an AST. >=20 > To write an tree-sitter grammar definition you need to write the grammar i= n JavaScript and pass it to tree-sitter=E2=80=99s parser generator. The gene= rator spits out a grammar definition encoded in a C source file (in the form= of a C struct). To use this grammar definition, we compile it to a library,= load it at runtime, pass the struct to tree-sitter library, and tree-sitter= can now parse according to this grammar definition. >=20 > The tree-sitter integration provides 1) Lisp wrappers for tree-sitter=E2=80= =99s C API; 2) some convenient functions built on the C API; 3) integration w= ith font-lock and indentation. I didn=E2=80=99t add any =E2=80=9Ccommon API=E2= =80=9D, I simply used existing frameworks in Emacs: for font-lock I used fon= t-lock-fontify-region-function, for indent I used indent-line-function. If i= n the future a common API for parses is desirable, tree-sitter can easily co= mply. >=20 > IOW, this is what tree-sitter integration currently does: >=20 > font-lock indent > | | > font-lock-fontify-region-function indent-line-function > | | > | | > tree-sitter-font-lock-fontify-region tree-sitter-indent-function >=20 > This is what could happen if we want a common API: >=20 > font-lock indent > | | > font-lock-fontify-region-function indent-line-function > | | > | | > common API --------------------------+ > / \ > / \ > / \ > tree-sitter other parser >=20 > Yuan