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: Sat, 18 Sep 2021 09:22:50 +0700 Message-ID: References: <83r1f7hydn.fsf@gnu.org> <8335qbirsr.fsf@gnu.org> <73E0B1F6-6F9F-40E0-927E-D08481BFF391@gmail.com> <834kaqhqlp.fsf@gnu.org> <8335qahqgk.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> <03386E3C-A975-4ECD-BF89-6AC62F751725@gmail.com> <83ilyz8xdl.fsf@gnu.org> <1BD3BF1C-C9F6-41CF-8558-4FA3E351346C@gmail.com> 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="403"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?UTF-8?Q?Cl=C3=A9ment_Pit=2DClaudel?= , Theodor Thornhill , Emacs developers , Stefan Monnier , Eli Zaretskii , Stephen Leake To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Sep 18 04:23:50 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 1mRQ17-000AWj-VA for ged-emacs-devel@m.gmane-mx.org; Sat, 18 Sep 2021 04:23:49 +0200 Original-Received: from localhost ([::1]:46248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRQ15-0002xe-IA for ged-emacs-devel@m.gmane-mx.org; Fri, 17 Sep 2021 22:23:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRQ0V-0002HB-9V for emacs-devel@gnu.org; Fri, 17 Sep 2021 22:23:11 -0400 Original-Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:56286) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRQ0T-000180-Km; Fri, 17 Sep 2021 22:23:11 -0400 Original-Received: by mail-pj1-x1031.google.com with SMTP id t20so8136980pju.5; Fri, 17 Sep 2021 19:23:08 -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=5mASd3thamqGbrxeEBgyYD5KwsewyTbYqvomHdGNUow=; b=UQAgUpsy7Sqc+z9yWQ7faN5ZGY+3PD+WMTKSSUQugXQ4Jkg8Oi/MflGyIzEerbFda7 CcFk1n/LRog9TsH/Wv0YdFyvu7P2xeoh+gbgnMEDkaxhH8UAPWmrGJ4yTWPodHCa1ppe SGhHMRBVypGNCLKuw3LhCLrTezp0l2IUEwkr9PudeMUIAPzFdUOLPIdN0J17xfPDw4pG 0TXZYcNsUvvx6GhcmoX6WbT9HQ9PhoHei87rHGJHePV0txntu3cUFBd/uZso51Xlzog1 2pJLtEGbzUvUNQHYZ3HzSjjaX25+iABp0wNDu6eP1ba8LokaPJp5ce6TIgNu/bjjshhV 9NiQ== 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=5mASd3thamqGbrxeEBgyYD5KwsewyTbYqvomHdGNUow=; b=5Hla8I/M3DR0leSGUllSun0uJEjPHSxZxpRP4NQvLZnp/Ut9VI85gmJAqCg4LZn888 BmnexQK3muhkywAyQYBlvZiPn0rfZSOcnDpRQURFWSO7mvo9YdCRw0PgX3HPWEbyFpp7 MBoc3Nq3Bcpjghswk5hiyoflP0vkQy8NYCTdOYeJvbs+S/AXxeSYAWj11BeLqMQxMZqp hbwpB+xVD2L/Kv2kwKPiE7mPZ4OLHne7oWdNuZatS2ZKGUI03pMoZzlq897Mhw2zzGEb FA1xspddr/XDp2zg/wecKYGZNiVLhGRacpQtV5O19M9epiHrGwF9z6TzkDTnUz3giN75 LdCw== X-Gm-Message-State: AOAM530rWLCUvRaMlJlYiInqtlsq/9X4K+ZXmY4YUgzDwPWYml2YylNI VRujvR3O5RWcnPqkZUVWpBFbd/4VqP8YHh/qiQ8= X-Google-Smtp-Source: ABdhPJwEKJgXo1jAae2EkUcFXKQSt2ix25Ps7F5xhXdXAvhYIOCq7R4hNzJArOu+MCIsVi8OAny7dTP2IXbWsUlav0s= X-Received: by 2002:a17:902:dcd5:b0:13d:97c6:c480 with SMTP id t21-20020a170902dcd500b0013d97c6c480mr2503585pll.70.1631931787487; Fri, 17 Sep 2021 19:23:07 -0700 (PDT) In-Reply-To: <1BD3BF1C-C9F6-41CF-8558-4FA3E351346C@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=ubolonton@gmail.com; helo=mail-pj1-x1031.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:274951 Archived-At: > > Tree-sitter has no indentation calculation feature. Major mode writers = genuinely need to read the source of the tree-sitter language definition. T= he source tells us what will be in the syntax tree parsed by tree-sitter, a= nd the node names differ from one language to another. For example, if I wa= nt to fontify type identifiers in C with font-lock-type-face, I need to kno= w how is type represented in the syntax tree. I look up the source[1], and = find > > > > _type_specifier: $ =3D> choice( > > $.struct_specifier, > > $.union_specifier, > > $.enum_specifier, > > $.macro_type_specifier, > > $.sized_type_specifier, > > $.primitive_type, > > $._type_identifier > > ), > > > > This roughly translates to > > > > _type_specifier :=3D > > | > > | > > | > > | > > | > > | <_type_identifier> > > > > in BNF > > > > From this (and some other hint) I know I need to grab all the _type_spe= cifier nodes in the syntax tree, find their corresponding text in the buffe= r, and apply font-lock-type-face. And type identifiers in another language = will be named differently, tree-sitter doesn=E2=80=99t provide an abstracti= on for semantic names in the syntax tree. > > > >> And I want to also point out that as Emacs core developers, we can=E2= =80=99t possibly provide a good translation from convention language names = to their tree-sitter name (C# -> c-sharp). Maybe we can do a half-decent jo= b, but 1) that won=E2=80=99t cover all available languages, and 2) if there= is a new language, we need to wait for the next release to update our tran= slation. It is better for the major mode writers to provide the information= on how to translate names. > > > > The database used by the conversion should definitely be extensible. > > But that doesn't mean it should be empty. > > > > Anyway, we've spent enough time on this issue. If you are still > > unconvinced, feel free to do it your way, and let the chips fall as > > they may. > > I=E2=80=99ll do it the way I see fit. You can always comment in the final= review (or something). Thanks. Your arguments were reasonable. Please continue the work. It's quite valuab= le. There will be a lot more important details to discuss. --=20 Tu=E1=BA=A5n-Anh Nguy=E1=BB=85n Software Engineer