From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id YC5qOcN/6GMipAAAbAwnHQ (envelope-from ) for ; Sun, 12 Feb 2023 06:57:24 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 8LJQOcN/6GPxlAAAauVa8A (envelope-from ) for ; Sun, 12 Feb 2023 06:57:23 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id BBACBF20D for ; Sun, 12 Feb 2023 06:57:23 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pR5MG-0006Il-FY; Sun, 12 Feb 2023 00:57:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pR5ME-0006Ib-MU for guix-patches@gnu.org; Sun, 12 Feb 2023 00:57:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pR5ME-00017f-AG for guix-patches@gnu.org; Sun, 12 Feb 2023 00:57:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pR5MD-0003HR-VI for guix-patches@gnu.org; Sun, 12 Feb 2023 00:57:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#49946] [PATCH v7 01/32] gnu: tree-sitter: Move to its own module. Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 12 Feb 2023 05:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49946 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Pierre Langlois Cc: "\(" , Pierre Langlois , 49946@debbugs.gnu.org, Luis Henrique Gomes Higino , zimoun Received: via spool by 49946-submit@debbugs.gnu.org id=B49946.167618137712552 (code B ref 49946); Sun, 12 Feb 2023 05:57:01 +0000 Received: (at 49946) by debbugs.gnu.org; 12 Feb 2023 05:56:17 +0000 Received: from localhost ([127.0.0.1]:43851 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pR5LU-0003GN-QA for submit@debbugs.gnu.org; Sun, 12 Feb 2023 00:56:17 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:39791) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pR5LQ-0003Fz-2y for 49946@debbugs.gnu.org; Sun, 12 Feb 2023 00:56:15 -0500 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id 08C18C0003; Sun, 12 Feb 2023 05:56:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1676181364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=i9dmPnWeEXB+LGcV9Wf7uQtXdlkwJdxd9UJzLC7Hp5k=; b=erLixOVU3NzyMp/4I8pKPNsFC1b3E5NetCBG980jW+asswrx8VIT95LM+G3SrBsvVHnR+f f570mFHZJ1PHGrDw79rO87LdnRwUAEdSOXYxyWrvt49VSWfgFDkmO8UMQ7WDoWzFZkM+dv a5jCuITM8Sov6ugUk1u0xk5p4IknNoVuHQ9NbJ8EFDUujNBIo3m2zBNvX8BaLyIvnFWr5k 48GV7oddOqSe9G8wCZ1iycF9+DcO16pMHsmmSPkLDKd5Y8SOKS+Zh744C3s3OFYpOQjOY2 8qnVV/U2ESlUMGQyitJWCMBe+Edlr14XIEXe0dXxtjcmtiQdad0ZF9OUZRegfw== From: Andrew Tropin In-Reply-To: <87o7q1qzol.fsf@gmx.com> References: <87mtfi63ut.fsf@gmx.com> <20221125012142.22579-1-pierre.langlois@gmx.com> <20221125012142.22579-2-pierre.langlois@gmx.com> <87bkovcp1d.fsf@gmx.com> <87h6vvgnd6.fsf@trop.in> <86pmaj3td2.fsf@gmail.com> <87cz6jgcku.fsf@trop.in> <87a61lr8cp.fsf@trop.in> <87o7q1qzol.fsf@gmx.com> Date: Sun, 12 Feb 2023 09:55:58 +0400 Message-ID: <87mt5jfmvl.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-TUID: v3sWjfWVPOhQ --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On 2023-02-10 15:48, Pierre Langlois wrote: > Hi Andrew, thanks for pushing this along! It's great to see things > getting merged. > > Andrew Tropin writes: > >> [[PGP Signed Part:Undecided]] >> On 2023-02-09 18:04, Andrew Tropin wrote: >> >>> On 2023-02-09 13:39, zimoun wrote: >>> >>>> Hi, >>>> >>>> On Thu, 09 Feb 2023 at 14:11, Andrew Tropin wrote: >>>> >>>>> I applied tree-sitter and tree-sitter-cli patches, >>>> >>>> Just to be sure to understand, you have only applied 02/32 and 05/32, >>>> right? >>>> >>>> >>>> [bug#49946] [PATCH v7 02/32] gnu: tree-sitter: Update to 0.20.7. >>>> id:20221125012142.22579-3-pierre.langlois@gmx.com >>>> http://issues.guix.gnu.org/msgid/20221125012142.22579-3-pierre.langloi= s@gmx.com >>>> >>>> [bug#49946] [PATCH v7 05/32] gnu: Add tree-sitter-cli. >>>> id:20221125012142.22579-6-pierre.langlois@gmx.com >>>> http://issues.guix.gnu.org/msgid/20221125012142.22579-6-pierre.langloi= s@gmx.com >>>> >>>> Leaving out all the others, right? >>> >>> Merged first 5 patches from 01 to 05, also added one more commit, which >>> addresses some things from reviews and one commit, which adds html >>> grammar. >>> >>> The html grammar is added for the testing purposes. It relies on >>> generated parser.c and scanner.c and we will need to repackage it using >>> grammar.js instead. I'm not sure if a separate build system is needed >>> for this, I guess we can just rewrite tree-sitter-grammar function, >>> which generates packages as in example with tree-sitter-grammar-html: >>> https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/tree-sitte= r.scm?h=3D53b00b91b73bd60412d5bd057e22e6d63194a7f7#n158 >>> >>> Anyway, I only skimmed tree-sitter-build-system source code, and plan to >>> read it carefully, evaluate and either introduce new build system or >>> just move all needed parts to tree-sitter-grammar function. WDYT? >>> After we done with it we can package all other grammars. >> >> Ok, I realized that the proper build process for tree-sitter grammars is >> a little harder than I expected, tree-sitter-build system make sense. I >> reviewed it, made a small change: > > Ah great, I was going to comment to try and push for us to keep the > build system. I originally went with a template package and inheritance, > but Maxime suggested moving to a build-system which ended up making the > package definitions a *lot* nicer IMO (see previous discussion here > https://issues.guix.gnu.org/49946#144). It also allows us to deal with > grammars that depend on each other more nicely I think. > >> >> @@ -29,7 +29,7 @@ (define-module (guix build tree-sitter-build-system) >> ;; Commentary: >> ;; >> ;; Build procedures for tree-sitter grammar packages. This is the >> -;; builder-side code, which builds on top fo the node build-system. >> +;; builder-side code, which builds on top of the node build-system. >> ;; >> ;; Tree-sitter grammars are written in JavaScript and compiled to a nat= ive >> ;; shared object. The `tree-sitter generate' command invokes `node' in= order >> @@ -114,7 +114,7 @@ (define (compile-language dir) >> "-fno-exceptions" >> "-O2" >> "-g" >> - "-o" ,(string-append lib "/" lang ".so") >> + "-o" ,(string-append lib "/libtree-sitter-" lang ".s= o") >> ;; An additional `scanner.{c,cc}' file is sometimes >> ;; provided. >> ,@(cond >> >> >> rewrote html grammar to use this build system and made it work with >> built-in treesit package. Also, tried examples of c and cpp grammars >> from patches in this thread. >> >> If you ok with it, I'll push the build system to master and update the >> html grammar accordingly. >> >> The final result will look like this: >> >> (define tree-sitter-delete-generated-files >> #~(begin >> (delete-file "binding.gyp") >> (delete-file-recursively "bindings") >> (delete-file "src/grammar.json") >> (delete-file "src/node-types.json") >> (delete-file "src/parser.c") >> (delete-file-recursively "src/tree_sitter"))) >> >> (define* (tree-sitter-grammar >> language language-for-synopsis version commit hash >> #:key >> (repository-url >> (format #f "https://github.com/tree-sitter/tree-sitter-~a" la= nguage)) >> (inputs '())) >> (let ((synopsis (string-append language-for-synopsis >> " grammar for tree-sitter")) >> (name (string-append "tree-sitter-grammar-" language))) >> (package >> (name name) >> (version version) >> (home-page repository-url) >> (source (origin >> (method git-fetch) >> (uri (git-reference >> (url repository-url) >> (commit commit))) >> (file-name (git-file-name name version)) >> (sha256 (base32 hash)) >> (modules '((guix build utils))) >> (snippet tree-sitter-delete-generated-files))) >> (build-system tree-sitter-build-system) >> (inputs inputs) >> (synopsis synopsis) >> (description (string-append synopsis ".")) >> (license license:expat)))) >> >> (define-public tree-sitter-grammar-html >> (tree-sitter-grammar >> "html" "HTML" >> "0.19.0" "v0.19.0" >> "1hg7vbcy7bir6b8x11v0a4x0glvqnsqc3i2ixiarbxmycbgl3axy")) >> >> After that we can bring the rest of the grammars. > > I would suggest to rmeove the `tree-sitter-grammar' function, and keep > grammars as "regular" package records, even though it's a little bit > more verbose: > > --8<---------------cut here---------------start------------->8--- > (define-public tree-sitter-html > (package > (name "tree-sitter-html") It seems tree-sitter-html mimics upstream package name and probably make more sense than tree-sitter-grammar-html used by me. > (version "0.19.0") > (source (origin > (method git-fetch) > (uri (git-reference > (url "https://github.com/tree-sitter/tree-sitter-html= ") > (commit (string-append "v" version)))) > (file-name (git-file-name name version)) > (sha256 > (base32 > "1hg7vbcy7bir6b8x11v0a4x0glvqnsqc3i2ixiarbxmycbgl3axy")) > (modules '((guix build utils))) > (snippet tree-sitter-delete-generated-files))) > (build-system tree-sitter-build-system) > (home-page "https://github.com/tree-sitter/tree-sitter-html") > (synopsis "Tree-sitter HTML grammar") > (description > "This package provides a HTML grammar for the Tree-sitter library.") > (license license:expat))) > --8<---------------cut here---------------end--------------->8--- > > This way, they look like any other package in Guix, which makes it > easier for us to apply automatic changes in the future if needed (for > example like how the input format could be automically updated for all > "simple" package definitions, but had to be manual whenever custom code > refactoring was done). Does this make sense? Make sense, but on the other hand we already have hunspell, aspell dictionaries and probably a few more others, which are very similiar in spirit and we already have to keep in mind their existence on such automatic code updates. It looks that the packages differ only in url for the source code, lang name and sometimes in inputs. Having template package function can make management of shared parts more centralized, reduce possibility of copy-paste mistakes, when the description wasn't updated and so on and can reduce the amount of the code overall (which also reduces the change of introducing an error). I don't have a strong opinion on this topic, but leaning towards the template function slightly more, however I'm completely ok with the standalone package definitions as well. WDYT? > >> >>> >>> According to emacs integration: I already have a working prototype on >>> my local setup, which uses builtin treesit package, it's similiar to >>> what Luis mentioned with search-paths. We just need to figure out a >>> few minor details and I'll add it. >> >> I've sent a patch for emacs+tree-sitter integration in a different reply >> in this thread. >> >> Thank you very much for all the work, it's really valuable! > > :-) > > Thanks, > Pierre > =2D-=20 Best regards, Andrew Tropin --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmPof24ACgkQIgjSCVjB 3rDSmw/+Need86jXW8YJuPd3UOS/Hb6S7YGCi9Dibxf8EOGfSxd5+YRo5JYNKGlh +xCPSfU6wEEbxH1zVY0AejsJkJxhizK0jDkTn4ACQImi/FpmWKrpf/UpiMIsMdhw o7OUY20sZNs0Xb3WSLLb5azjCfj0teEzMEBT/vmL0pGnzFdEwDQb24aE4euQB3LJ 0Kyyh+V6RbV6AtQHbeAYVMdDlPSkzgBw7uAhvafmgLD+tObP+1G4oP/QTt+VaJCN Sqtmwz8nzTzMkn4KaWux1w0/kxefM8VbIWe16XPZiGG2A2Tjtyovl+F8Y1NmfdBQ 6+Ljxr0OgBBMOh62UHR5CAMc0celSQEl2gGbon9Sk08YDi1xq4j1v3a3h/f8ZIR5 Pou0VI8wHJaU/2UFo8yDQkCotnHFQT0UcY8hdy1gPDYVf9U0hOwoKonjDBmPCmCK srwwlEI6RyAfza14lCHd/i/HumD8BxmBZ6ZTRqkeqXFMFKl2XllyQfsqpoO1sfn5 0cDxnjKgfaJ9dVcXAKRnDbH0oTWmxIfbyF96MqRT+t/cZNWr1tQ5Tp1+ByHCY5S8 5ETp91rnSt9xR+IvKvZbbP33PwRTpTMay1QsJSYK1YJCjDMEZMguEAlO8hMNJrB/ ygQUnYs87q4R1GfyJF0a0eHb2HQyTI5acpSRx4b+Jg4+TlOc34A= =WmHB -----END PGP SIGNATURE----- --=-=-=--