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: Simplify the tree-sitter parser creation API Date: Mon, 16 May 2022 13:50:52 -0700 Message-ID: References: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) 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="8720"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?utf-8?Q?Daniel_Mart=C3=ADn?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 16 23:03:31 2022 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 1nqhsJ-00022y-Me for ged-emacs-devel@m.gmane-mx.org; Mon, 16 May 2022 23:03:31 +0200 Original-Received: from localhost ([::1]:58354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqhsI-0000WY-Kn for ged-emacs-devel@m.gmane-mx.org; Mon, 16 May 2022 17:03:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqhg9-0004U6-Q2 for emacs-devel@gnu.org; Mon, 16 May 2022 16:51:01 -0400 Original-Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:55808) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nqhg8-0006GM-7y for emacs-devel@gnu.org; Mon, 16 May 2022 16:50:57 -0400 Original-Received: by mail-pj1-x102e.google.com with SMTP id n10so15567617pjh.5 for ; Mon, 16 May 2022 13:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=sg3iLLEfv1XomHtJuhjLRidatzyiuSv1JhTKnmgDaLs=; b=UU7drdDL92MuesqaLINDYtfGPqu3EJ8/Nj8WjgGTwcU7x2CLqtPUt53FGibH3iI+6F 0BdL9l6LkxyhMAaGrXZCQiGa5yVrrwbquvhDUjmId7PyxCDjMzOm8feVnFhspk6Em49+ PCuVpFkDMviVkXzvn5M5w17qxY9YWAjBcK2DiWk32sQcuyB0SISxMOsYz4OSFAAlZ9PC qwmSeZ7wQ/D3LDZDL3tQvWYWrrKfigxIgFpq5qHZ1T7bZ8rwjx4jPa2FM1U5BPnpXXSU 9JjjhTYtMVf/VOKBF+lwjuTYG0BoNyymIDb9Bh2eugzWuy/h7LdGngljagofFETAvQGz oyZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=sg3iLLEfv1XomHtJuhjLRidatzyiuSv1JhTKnmgDaLs=; b=moQNV2k3RCYGollqIhDHw5UKGR/NmhJd4NqJ5pt7dr4hwQY5+UGfBhuQF7fGHB/PGm /S30015a45v3VnWsgFQgatB7lRDWeFtGP+bEVdoNZCjJVKkdoz1sFAZF8c+5NvjvC/Am lbCOJkKB5oN092BtJh/e8Ynk+Pj1r1cfIUAjgbbiyiJeYmbu2NVrJHZYIIRmj0GM4vHI pa9wx/svilGuTF1txB2OlGIGRW3KwPh9A7jMii71d1ZcIL/M7LgmJiIVP20rShYcOanv HvUQlA9+7HpSXBSqowO3/Rl2Q7dyy//CK5cmpbwgCouB5HIwzZ93sHxDHWEcvaOa845w SmMA== X-Gm-Message-State: AOAM5312LVTwKgaLfU23NafWxz/5xeAXUCq9O+3Te2LOqJzpvz1kSr/g Pat4PSgoIeudYK4DJn7LOnQ= X-Google-Smtp-Source: ABdhPJzvCcxbpkEX1lOi0e1vFIWBRjhhqjQilx0h1B4ta3JZtUL3J33YeL/Jx++HYOZOzZU+jm9urw== X-Received: by 2002:a17:90a:690c:b0:1df:3b6f:d073 with SMTP id r12-20020a17090a690c00b001df3b6fd073mr9965368pjj.18.1652734254272; Mon, 16 May 2022 13:50:54 -0700 (PDT) Original-Received: from smtpclient.apple ([2600:1700:2ec7:8c90:359d:bac4:1a2e:ef27]) by smtp.gmail.com with ESMTPSA id m1-20020a17090a858100b001d792761e2esm109157pjn.47.2022.05.16.13.50.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 May 2022 13:50:53 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3696.80.82.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=casouri@gmail.com; helo=mail-pj1-x102e.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, T_SCC_BODY_TEXT_LINE=-0.01 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:289817 Archived-At: > On May 15, 2022, at 7:39 AM, Daniel Mart=C3=ADn = wrote: >=20 >=20 > Currently, there are three functions to create a tree-sitter parser: >=20 > - treesit-get-parser-create > - treesit-get-parser > - treesit-parser-create >=20 > I think this set of similarly named functions can be reduced, so that > developers don't need to remember a lot of APIs. How I understand the > problem of creating a tree-sitter parser is that we need three things > from the developer: >=20 > - A programming language (a symbol). > - A buffer (optional, default to the current buffer). > - Whether to create or reuse an existing parser for that language. >=20 > I think it would be simpler to have just one parser creation API like >=20 > (treesit-make-parser LANGUAGE &optional BUFFER ALWAYS-NEW) >=20 > There are similar API patterns like this one already in Emacs. With > this proposed API, the common case, which is to create a parser for = the > current buffer, and to try to reuse one if it already exists, is very > simple from the POV of an ELisp developer integrating with = tree-sitter: >=20 > (treesit-make-parser 'c) >=20 > Any thoughts? >=20 Thanks! I think it makes sense. Though I=E2=80=99d keep the = treesit-parser-create function because it directly corresponds to the = tree-sitter C API. I can extend the C definition of = treesit-parser-create to=20 (treesit-parser-create LANGUAGE &optional BUFFER NO-REUSE) Yuan