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: Tree-sitter api Date: Sun, 12 Sep 2021 21:15:31 -0700 Message-ID: References: <83r1f7hydn.fsf@gnu.org> <95F37923-5BF9-4D81-B361-267CF119FBCA@gmail.com> <735AF34C-FD18-4A6A-A99D-E5D8EB4DE4F3@gmail.com> <40611F1F-7B5C-4885-A2CA-CE709ED8D22B@gmail.com> <4E876354-10D1-46B3-8124-CAE916261F08@gmail.com> <0A3F5464-B90D-4D47-BBDD-CCA26D877F43@gmail.com> <83tuiys1y4.fsf@gnu.org> <835yvcpdip.fsf@gnu.org> <7B1F90DE-A992-4F51-B391-0A4E5A598780@gmail.com> <3E8CA8E4-E623-4051-A76D-508C6CF94B6A@gmail.com> <837dfpj5yf.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> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) 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="5336"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?B?VHXhuqVuLUFuaCBOZ3V54buFbg==?= , Theodor Thornhill , =?utf-8?Q?Cl=C3=A9ment_Pit-Claudel?= , Emacs developers , Stefan Monnier , stephen_leake@stephe-leake.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 13 06:16:48 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 1mPdOi-00018d-3b for ged-emacs-devel@m.gmane-mx.org; Mon, 13 Sep 2021 06:16:48 +0200 Original-Received: from localhost ([::1]:33888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPdOg-0003vG-MC for ged-emacs-devel@m.gmane-mx.org; Mon, 13 Sep 2021 00:16:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPdNd-0003FI-0P for emacs-devel@gnu.org; Mon, 13 Sep 2021 00:15:41 -0400 Original-Received: from mail-ot1-x32e.google.com ([2607:f8b0:4864:20::32e]:46703) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mPdNY-00083S-7W; Mon, 13 Sep 2021 00:15:40 -0400 Original-Received: by mail-ot1-x32e.google.com with SMTP id c8-20020a9d6c88000000b00517cd06302dso11527246otr.13; Sun, 12 Sep 2021 21:15:34 -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=CTQfE7uT0K89eE55xyP7HU4tAz002ZIVP63smCYyNE0=; b=CM2Ada85ZGTHg6qIGxJ0jbht29LxPHLGt7KLRJ6OjJo431F6/pR9pUkziSrTAN2ksc 7rxo8m62ymhTQe3Z7i/KM1d5O7MV+ai3o4EHb/Hmjcb42zDoFL4wOqUGgjVKgXZyu3Vk lEokJm9sXoYrIhyUbdPURvzEy/0wKqNVm5po6z7yQz8zHSGX1O1mIelKWgIy+hlNtR8l pAaAA7cmrolApBg1JS4h1v/9340nEN49NhzxPucS58jfj1IyXH4+gbnkxMoBsKDbML72 aJJyzxLTQP2QNM4IYwBDqfsGGYnDpHVEspoS7C6mv+S1szoBoNRA9fsQw9t8NyW/tzME 24Cg== 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=CTQfE7uT0K89eE55xyP7HU4tAz002ZIVP63smCYyNE0=; b=BAY3uUUY5NDdCKJZe+NX2JQfTg24h4rMVHMDpQDxBDkEZAPfRrOlENeiqi5+sdXOUu HHo+K3QzebDEDoTSodb/GzHlzOLVIwK8sFAO4oKUkJQx8RpjqFjerATcaRA4xc+yxBcm lXm3+SkqNA5giQbn5scRT7ByG0m4q6Ib7oGbg/Qw2xYNvRJmJrhk10UpDEF3tISjsbPV L1swJCmiBV0f+/1cNhGEoQ9pnXkrayOIPG6NQuHXtoMNRKunQFmvXwut+J5AhKu1HVNk hXtGw3VWYHmLk1JI1KMsK3WBMxJIpYxBkTacOpna0VxB7Uhhk6cVIvkYY8YSPkudR61I qg8Q== X-Gm-Message-State: AOAM532EF+VOrFEa2vKk6TnuVOpjUmWbtyyQ+W1RjwGoMhIEacKNMHLC UOoRVeKC6+CysOMqc0VC5iB9sY7IGZ7wPoxm X-Google-Smtp-Source: ABdhPJzDHK0JjAGc9xlo4GZ1LycPIz1KP/vx1v/MfdBpDxm76YjE5GtHPleI23txIGC5JGk+cWfL5A== X-Received: by 2002:a05:6830:4097:: with SMTP id x23mr8735249ott.289.1631506532982; Sun, 12 Sep 2021 21:15:32 -0700 (PDT) Original-Received: from smtpclient.apple ([2600:1700:2ec7:8c9f:a1fa:bf8f:af60:ddef]) by smtp.gmail.com with ESMTPSA id a4sm1610436otv.49.2021.09.12.21.15.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Sep 2021 21:15:32 -0700 (PDT) In-Reply-To: <83v936fj35.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.120.0.1.13) Received-SPF: pass client-ip=2607:f8b0:4864:20::32e; envelope-from=casouri@gmail.com; helo=mail-ot1-x32e.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:274615 Archived-At: > On Sep 11, 2021, at 10:39 PM, Eli Zaretskii wrote: >=20 >> From: Yuan Fu >> Date: Sat, 11 Sep 2021 13:29:09 -0700 >> Cc: Tu=E1=BA=A5n-Anh Nguy=E1=BB=85n , >> Theodor Thornhill , >> Cl=C3=A9ment Pit-Claudel , >> Emacs developers , >> Stefan Monnier , >> stephen_leake@stephe-leake.org >>=20 >>> But the part is still needed to be concocted somehow. E.g., >>> the conversion from "C#" to "c-sharp" isn't trivial. >>=20 >> The project name of tree-sitter=E2=80=99s C# definition is = =E2=80=9Ctree-sitter-c-sharp=E2=80=9D[1]. So if someone wants to use the = C# language, they probably know what symbol represents it (we will = explain the translation rule in doc-string and the manual). I also want = to point out that we don=E2=80=99t come up with the symbols representing = each language, the _user_ passes 'tree-sitter-parser-create' a symbol = representing a language, and we translate that symbol to dynamic library = name and C symbol name. >=20 > Surely, you don't mean "user" as in "the person who edits a source > file"? I presume you mean the Lisp program, not the human user. That > Lisp program is the major mode which wants to use TS services, and the > only thing that it has in hand is its own symbol, like 'c-mode' or > 'python-mode' or 'f90-mode'. It needs a way to pass the corresponding > TS module name to TS, and my question is: how would the major mode > compute the correct module name? We need either a mode-specific > variable with that name, or some global function that could be used by > any major mode to obtain the language module name. Not the end-user, no. But not really =E2=80=9CLisp Program=E2=80=9D, = either. I mean the human being writing the major-mode and adapting the = major-mode to utilize tree-sitter features. The major mode writer should = be able to figure out the correct symbol to use, if she go checks out = the project name for the language definition, or the package name of the = language definition in her package manager, or by some other means. For = example, one should be able to figure out that tree-sitter-c is the = symbol for C language definition, and tree-sitter-c-sharp that C#. Then = Emacs automatically translate tree-sitter-c to libtree-sitter-c.so, and = tree-sitter-c-sharp to libtree-sitter-c-sharp.so; basically adding = =E2=80=9Clib=E2=80=9D and =E2=80=9C.so=E2=80=9D (or =E2=80=9Cdylib=E2=80=9D= etc). If that doesn=E2=80=99t give the correct library name for a = quirky language, the major-mode writer can add an entry to = tree-sitter-library-name-override-list=E2=80=94(tree-sitter-quirky-lang = =E2=80=9Clibtree-sitter-qlang=E2=80=9D =E2=80=9Ctree_sitter_qlang=E2=80=9D= )=E2=80=94and Emacs will use that. (Or she can just use = tree-sitter-qlang as the symbol, and Emacs=E2=80=99 auto translation = would just fine.) >=20 >>>>> BTW, since dynamic libraries has different extensions on different = systems, what I want to do it to try loading the library with .so, then = try .dylib, then try .dll, is that a good idea? >>>>=20 >>>> We can do better, see load-suffixes. >>>=20 >>> And in C, you can use MODULES_SUFFIX directly. Though we will >>> probably need some minor changes there, to have the suffix defined >>> even in a build --without-modules. >>=20 >> I=E2=80=99m using tree-sitter-load-suffixes with default value = =E2=80=98(=E2=80=9C.so=E2=80=9D, =E2=80=9C.dylib=E2=80=9D, =E2=80=9C.dll=E2= =80=9D). Should I populate this variable with MODULES_SUFFIX and = MODULES_SECONDARY_SUFFIX, or should I just use the two SUFFIX in C? = I.e., do you see a need for users to customize suffixes? >=20 > I'd prefer a general variable shared-library-suffix(es), either a > single value specific to the target system or an alist with keys being > system names (from system-type). Then we could use that in > load-suffixes (instead of MODULES_SUFFIX) and everywhere else. To summarize, we have=20 "load-suffixes=E2=80=9D (".elc" ".el=E2=80=9D, with M_SUFFIX & = M_SEC_SUFFIX if modules enabled),=20 "module-file-suffix=E2=80=9D (M_SUFFIX if modules enabled),=20 "load-file-rep-suffixes=E2=80=9D ("" ".gz").=20 All contribute to the possible file names Emacs tries when loading a = file (be it a Elisp file or an Emacs module). I will add a = "shared-library-suffix=E2=80=9D specifically for loading dynamic = libraries, its value will be MODULES_SUFFIX regardless if module is = enabled. Yuan