From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?VHXhuqVuLUFuaCBOZ3V54buFbg==?= Newsgroups: gmane.emacs.devel Subject: Re: Tree-sitter api Date: Fri, 17 Sep 2021 20:03:56 +0700 Message-ID: References: <83r1f7hydn.fsf@gnu.org> <3BC29D06-CA75-4706-9AD7-ABA2F65C4DEE@gmail.com> <83v936fj35.fsf@gnu.org> <83r1dselyo.fsf@gnu.org> <6A4CE984-6ACE-4E66-8EF2-F3D351C02248@gmail.com> <83r1dscpt2.fsf@gnu.org> <83o88wcof9.fsf@gnu.org> <83lf3zdh4z.fsf@gnu.org> <8965C4A0-79D3-4D77-A6BA-D07A6C93F7FE@gmail.com> <83ilz3cs4k.fsf@gnu.org> <04D19C1A-CD64-4156-B932-1C9FEEE4EC7B@gmail.com> <83zgsebc0r.fsf@gnu.org> <1F752923-F357-4A18-B6E2-0120F1B9BD37@gmail.com> <83fsu5bzem.fsf@gnu.org> <83zgsdad5j.fsf@gnu.org> <83sfy391ni.fsf@gnu.org> Mime-Version: 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="3737"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu , Theodor Thornhill , =?UTF-8?Q?Cl=C3=A9ment_Pit=2DClaudel?= , emacs-devel , Eli Zaretskii , Stephen Leake To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 17 15:06:14 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 1mRDZG-0000n9-Nx for ged-emacs-devel@m.gmane-mx.org; Fri, 17 Sep 2021 15:06:14 +0200 Original-Received: from localhost ([::1]:34988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRDZF-0001mB-5b for ged-emacs-devel@m.gmane-mx.org; Fri, 17 Sep 2021 09:06:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRDXN-0000KT-N4 for emacs-devel@gnu.org; Fri, 17 Sep 2021 09:04:17 -0400 Original-Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:42922) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRDXL-0006Rf-9v; Fri, 17 Sep 2021 09:04:17 -0400 Original-Received: by mail-pl1-x62f.google.com with SMTP id l6so1384847plh.9; Fri, 17 Sep 2021 06:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=CQJh5vRVtP/VGjW8Ar5l4WIlTlgJJVL2/SRnQIaSsxg=; b=Nj7roN2wEYm13tfUu/5DhyFMOF+Dz0XrYyE+9NBq9tlry/JxHO5FYRSn9a61pa3hgK Jjx1Sj0D/MN7X8fPni1XCjYo++tXRoB0GPJsfdVN3IcfB8YmaA1cTm4QEU5MEBPk3iys 9TaZljLhztS3C/hC1N+wOZ5WLNOsKSTbouJtguRyGxc1lby32Sh5zyumeiuA8M0nlG1Q bGs8KFClyzDoOa1AExZNhTTlFvJgHwgAzhSBYpN6Ie9G30j8BnXtab39zQ6GXpaubdYq uTkPWr4uVtVY8k1ruUyP4SLhgW+XNXX6CMNvN92fRP5taxYFyYbNtUlwYLKkBZXv60qn rcBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=CQJh5vRVtP/VGjW8Ar5l4WIlTlgJJVL2/SRnQIaSsxg=; b=QTGDGe0xn+zhS3VFfol8WihmQ6KMJa8BH2fl3MjSvZbP81tdsQpEEGP1Bt7yGUcrIR TQbg4vImuVpED2+72I9TfsCpd9JsWspSyez6WTwAfZblbBd9FtUCW4uUvtOsZs/tbN+8 hOU/od+dwBQBi6vdsqBRUmBGiqpDjmoLXaTMt23uhSgHo1ZMyUBlAQSO8NIO8eUtaXEo Sk/Ct1penXgmR8Ay/m6FAoJKdfuW2uBRMIWTAxU3VlE01oIwNQB3Ivo124baJrOdPrux ZgN9gwMbveRn9S7741XJpNYrmnxF4AFe9CpQk6A4PiyyMbes5ehIF46VOt2ctpYdp2zH VxfQ== X-Gm-Message-State: AOAM530Cifgu5wc2F4keihCyiTbcYeEv9hN4U7MNkzX6vUMf2LW1AVjy RxZKwTqin8xo2nSAsSE2KXf/G6l+D/9STyCNzII= X-Google-Smtp-Source: ABdhPJyU9dYtyd8TDIrHcb2vqEQE+0nNCLRtbeibujEkQ5lmLVYSYiYy81kciTn5jWiMVRB6kCFB4S8YNsRkxfjbiBw= X-Received: by 2002:a17:90a:af8f:: with SMTP id w15mr20982228pjq.90.1631883853140; Fri, 17 Sep 2021 06:04:13 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=ubolonton@gmail.com; helo=mail-pl1-x62f.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:274869 Archived-At: On Fri, Sep 17, 2021 at 7:23 PM Stefan Monnier w= rote: > For a major mode to use TS, the major mode's code needs to know; > - The name of the language's grammar file. > This can usually/often be guessed from the language's name and is > a trivial piece of information. > - The names of the various nodes that will appear in the AST. > Those are specific to the particular grammar being used, and the best > place to find them is in the source code of the grammar, tho you can > also just find them by experimentation. There are also field names, which make it easier to refer to specific child nodes within a parent node. For example, within a `function_definition` nod= e, the `identifier` node that is the function name has the field name `name`. Node names (types in tree-sitter's terms) and field names can both be extra= cted from the shared library. We should provide functions for that, e.g. `tree-sitter-node-types`, `tree-sitter-field-names`. The interesting non-trivial parts of a definition would be the relationship= s between the node types. For example, a `function_definition` can be inside = a `class_definition`, or a `module`, but not a `boolean_expression`. In princ= iple, these can be included in the shared library as well. AFAICT, the `tree-sitt= er` authors would be open to adding that feature. --=20 Tu=E1=BA=A5n-Anh Nguy=E1=BB=85n Software Engineer