From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 12 10:14:09 2023 Received: (at submit) by debbugs.gnu.org; 12 Jun 2023 14:14:09 +0000 Received: from localhost ([127.0.0.1]:40028 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q8iJ6-0004a0-QR for submit@debbugs.gnu.org; Mon, 12 Jun 2023 10:14:09 -0400 Received: from lists.gnu.org ([209.51.188.17]:56018) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q8iJ4-0004Zs-H2 for submit@debbugs.gnu.org; Mon, 12 Jun 2023 10:14:07 -0400 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 1q8iJ4-0002if-71 for bug-gnu-emacs@gnu.org; Mon, 12 Jun 2023 10:14:06 -0400 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q8iJ2-0002sU-I0 for bug-gnu-emacs@gnu.org; Mon, 12 Jun 2023 10:14:05 -0400 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2b1a86cdec6so50559171fa.3 for ; Mon, 12 Jun 2023 07:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686579242; x=1689171242; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=NHnqk8E+0dCfY1PXTEjr7hYL2lXwhoV9ZoxE2bxwGyA=; b=VDGeU7d7EcX6NMDTeNwwt9B4xsD65uokBt21REqkxgBMOmQ6p97efFvDDhjlmTWMQr RTsy3CRw5aIOipfLodmdAznC0tWZ8QxPvxsQtAnYvixCY4/0wPZ7xnJW2V2cqNr2H9d7 Gscto3/fGoWuDlW2HDTI2TORHph4CRqbTFYKH+Jih3WI0rKVRiM9Jtp5L9W5WqAoC4rt Oty9OtKsLNVX7R/VFIsZEEw6JKOthBF+NyHKkeq6dAEiHic/sYln3yKrIxhVuhZDLs4B Emr36bhJvDaz0AA6auvSYk9+fokJ5jRTnxwNXQ5HT5XOFv7PagkGE18EVxuCE86qOHRQ MChA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686579242; x=1689171242; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NHnqk8E+0dCfY1PXTEjr7hYL2lXwhoV9ZoxE2bxwGyA=; b=koHdCr1LllkxhnnuKpwOZP2kZzyG7PxcRluQI5eIx4MJYqtCcbwRLBqppMHQX2JQ7B xjJTEv+Tx1VpU18PrmFakrcqe5n/ZZ27uGa8UoIS1wFcvNGc02UqaA4C4K6w9Pu88uiD uRLHnLw8lKLFkGUEkhz0Y0mfcXMiRSe/58jJLzTjOAoRKRwxf0Jf3C/wJX1T2NbQa/rx /YQ9872ATFlAnTOWwoRvgMnaLaUbFWQDbfxi3/0kH6fCSNsEMSiCuUvqYWHJV+edxABR vAVNNvqAiSNQvAmc8EsUKCs7jkGUjIyTnHWCZ46pl/Psh1C1TNvUce0DfB0nwHEfDcUX J7cA== X-Gm-Message-State: AC+VfDxcQpruVTmV4tdXmwqY4LojKZW05lHpdKSxVnAV5JfsHmz1VY1R oC/fpiRhE6vCKOhCksYW7i2BXvcDp0Q= X-Google-Smtp-Source: ACHHUZ70EySgx65YJYSOwmJV8Nk5YdgWJTLs6cbwWS9679TJsekiMcOcPOTn7ZorPVkITblO7QRHYA== X-Received: by 2002:a2e:894b:0:b0:2b1:bcf2:68a5 with SMTP id b11-20020a2e894b000000b002b1bcf268a5mr2680477ljk.8.1686579242070; Mon, 12 Jun 2023 07:14:02 -0700 (PDT) Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id c8-20020a2ea1c8000000b002b1a737fd3fsm1774622ljm.99.2023.06.12.07.14.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2023 07:14:01 -0700 (PDT) From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Subject: Wrong conversion from Emacs to Tree-sitter S-expression syntax Message-Id: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> Date: Mon, 12 Jun 2023 16:14:01 +0200 To: Emacs Bug Report X-Mailer: Apple Mail (2.3654.120.0.1.15) Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=mattias.engdegard@gmail.com; helo=mail-lj1-x22e.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-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: Basil Contovounesios , Yuan Fu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) `treesit-pattern-expand` converts a query pattern into tree-sitter = S-expression syntax, as a string. The conversion mainly converts certain = keywords but the main problem is that it prints strings in Emacs syntax = which differs from that of tree-sitter. As a consequence, :match regexps cannot contain newlines: (treesit-query-capture 'java '(((identifier) @font-lock-constant-face (:match "hello\n" @font-lock-constant-face)))) signals a syntax error. As far as I can tell the tree-sitter string syntax allows for the escape = sequences: \n =3D LF \r =3D CR \t =3D TAB \0 =3D NUL (only a single 0 -- no octal escapes!) \X =3D the character X itself Unescape newlines result in a syntax error as seen in the example above. = NULs don't seem to go well either. At the very least, the conversion should avoid literal newlines and NULs = in the result (and probably CR and TAB). This cannot be done with a = straight prin1-to-string. (By the way, why is the conversion written in C? Was Lisp too slow?) Ideally we should not need to expose the tree-sitter s-exp query syntax = at all. Surely Emacs s-exps should be preferable in every case? From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 15 06:45:33 2023 Received: (at 64017) by debbugs.gnu.org; 15 Jun 2023 10:45:33 +0000 Received: from localhost ([127.0.0.1]:46260 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q9kTt-0006L5-7W for submit@debbugs.gnu.org; Thu, 15 Jun 2023 06:45:33 -0400 Received: from mail-lf1-f42.google.com ([209.85.167.42]:55753) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q9kTr-0006Kt-IL for 64017@debbugs.gnu.org; Thu, 15 Jun 2023 06:45:32 -0400 Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-4f61d79b0f2so10511999e87.3 for <64017@debbugs.gnu.org>; Thu, 15 Jun 2023 03:45:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686825925; x=1689417925; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=nT+Fpul3Ai/VQDeSDKXVFdPDNV7Zl0vC+mj85d309wU=; b=PX/w5EXbsPNkJHl59t9fEdLpCnC1fZBmFqcci1yzNpL/1fnIMIYGGJY43Y5i5ztkQM nl3Ets/KXixEzwS2KbH7dBKx7l2GsZLlRXxmw8x0ckooJDhf0sfvRiGMEbA5por0z3GD N0xWcQ5uXDInaQkkcJfzw1W7qoNAy7RMZTCNDyqCxDv4vdiU0zLuZ2dFeE4gfXMxAiTz 4K+ZB9pTbCH6heOUYwbAKKiop4oRmuvqwQh0wA4d6SfrVb7nDtDRareyiYyAdXYWPo0p 3e9CLctqbtIfcTrAhh+EsYKEwMic5NXPYTQWamsqYFGDiVEAzbVHCtSfO8xB9MD93FFm +VFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686825925; x=1689417925; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nT+Fpul3Ai/VQDeSDKXVFdPDNV7Zl0vC+mj85d309wU=; b=PVpW9PEHVOuSB4uZFsSPqy+Tnd0ApxPUQEc3mPEPjg0GfTHctZm1kEbHUkWVKyfddJ XdRaPjkVWxHaeHbZTElW6J391uVrY2WIzVYktsjSYfCHPmbAWQMdSFc+2oyahBN2vyen TpQEHSe+Dsh6LafGjoRaBQY/KwC4/WF5CubCK9e6xHYHCOcvapM2dxQyJ9BOiSHmRW0k QlhqtMk03Yg+oWYAzbgjhbohp7ejdO7+FrzghFZrrvF68fUV9pqk5HcgQasI9kp8y17J f31J9sQg6CuT+RF9bT8DN4OBt+bij7hy59yKxWIQXgqXvSKaRXscpsV8Kpun7UhFAo8g M7OA== X-Gm-Message-State: AC+VfDzp2NHKK99yRDyu7s8NlWBbaDjDhtW50fnaQ05hULqXZJLJ9c2H 6XXrZn20fMMnQbxUHnpZk8Si5U8mOnk= X-Google-Smtp-Source: ACHHUZ514z6QNlAeHDxBPqTX0uJwbn3tYblPlYnSHx1U0V2Saia6IeV1GEOQrEnNFk0dCsn5G3jZqw== X-Received: by 2002:ac2:5b9a:0:b0:4f6:47a2:7bb4 with SMTP id o26-20020ac25b9a000000b004f647a27bb4mr9547179lfn.60.1686825925193; Thu, 15 Jun 2023 03:45:25 -0700 (PDT) Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id m11-20020ac24acb000000b004f13711caedsm2512998lfp.103.2023.06.15.03.45.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2023 03:45:24 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Subject: bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= In-Reply-To: Date: Thu, 15 Jun 2023 12:45:23 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <195848A8-37EA-4F1C-AFDB-C1BB4F30BEA1@gmail.com> References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> To: 64017@debbugs.gnu.org X-Mailer: Apple Mail (2.3654.120.0.1.15) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 64017 Cc: Basil Contovounesios , Yuan Fu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) I also propose that we change the documentation to describe the (Elisp) = sexp-based query syntax only, or at least first and foremost, since that = is what all existing code uses and is more convenient. Currently the = manual starts by describing the string syntax and only then the Elisp = sexp syntax. From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 15 18:08:47 2023 Received: (at submit) by debbugs.gnu.org; 15 Jun 2023 22:08:47 +0000 Received: from localhost ([127.0.0.1]:48143 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q9v94-0003WZ-Pi for submit@debbugs.gnu.org; Thu, 15 Jun 2023 18:08:47 -0400 Received: from lists.gnu.org ([209.51.188.17]:44916) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q9v93-0003WS-GK for submit@debbugs.gnu.org; Thu, 15 Jun 2023 18:08:45 -0400 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 1q9v93-0002Nn-Af for bug-gnu-emacs@gnu.org; Thu, 15 Jun 2023 18:08:45 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q9v91-0006E7-L4 for bug-gnu-emacs@gnu.org; Thu, 15 Jun 2023 18:08:45 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6664a9f0b10so177008b3a.0 for ; Thu, 15 Jun 2023 15:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686866919; x=1689458919; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=3rq8hN65Qxacob1gHRHw82KcefMtjnX2aMfEsCIwTWA=; b=JKcFducIMD7QC7Ij8z4nNpfnlh75FlyvywZKOaqlfhlZzYnjlCMTOHM/lPPqzrs1FL D5jKBm3iYT5n+OVn+gKTdljX9tVMMep3sSfts+DaFt3+TlIeSNlG+ilKtKNwXrnMe8/F Aij885g5BHeuh/c3OLYIuq1S2v2DQs9Mucfy8JekjY5g93pIiStxWlas/Ggoal0VMdBc OZLjWeozkJsb9u2Uj4ERmgsqs1kw2VVpFasyb69oTmwwNr9dizLFuGxOYq5hkETVyDwm Y/2/7qeXi8FG1UeeroRB1+IZU/ZeFTljIEnzR8N0I5iFEjsmYvm6KTyJ7pYS1gfJq/JC 5HUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686866919; x=1689458919; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3rq8hN65Qxacob1gHRHw82KcefMtjnX2aMfEsCIwTWA=; b=eVR/cdZrE4b4AcuWCBZTlPDK+7MxSSF4AXN46n9w5x6IAYYdscIWc1GOjPMXPM/xvp fWip9grwyWtbOqBVGDEenNbW2BkuArsWV325rIVhwDT5KSqUnGid4CcHTl4PntEozRlV +CuuSnzzhrmM7cDo5yp/qKzRTUom9MTX14YTAdxFIbyxwOw2eI5F7Ra1HdqneDh73+Ms AodbjuXT7YvKCjteL6es0QD+WBT4akRtHPZFQVwbQG3xFZnsxOm9aKsaW5HC4+bASfjO ffEMOF+SYUFvUUp7BtTklUlFADCY8vEmorDttJnVt78AtC2MRR9n4lLuZ1o7ugxm2SCP wH6A== X-Gm-Message-State: AC+VfDycmKIP5krHYqzgnMp/tlZsazDwloWoWux9HYgMd0adrS9C7q1k An8UiyvzvBzTlRgCvc7y3E0= X-Google-Smtp-Source: ACHHUZ7L8xxOoERiWPAjWA+SZFkKGvqHXu8hqZUU387kOC0gED/qxd2ioCmqu+lcoA16UUGB0IBQuA== X-Received: by 2002:a05:6a00:1829:b0:64b:20cd:6d52 with SMTP id y41-20020a056a00182900b0064b20cd6d52mr366925pfa.14.1686866919112; Thu, 15 Jun 2023 15:08:39 -0700 (PDT) Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id y23-20020aa78557000000b0063b8ddf77f7sm12360472pfn.211.2023.06.15.15.08.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2023 15:08:38 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Subject: Re: Wrong conversion from Emacs to Tree-sitter S-expression syntax From: Yuan Fu In-Reply-To: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> Date: Thu, 15 Jun 2023 15:08:26 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> To: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= X-Mailer: Apple Mail (2.3731.600.7) Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=casouri@gmail.com; helo=mail-pf1-x436.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-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: Basil Contovounesios , Bug Report Emacs X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Thanks for catching this. > On Jun 12, 2023, at 7:14 AM, Mattias Engdeg=C3=A5rd = wrote: >=20 > `treesit-pattern-expand` converts a query pattern into tree-sitter = S-expression syntax, as a string. The conversion mainly converts certain = keywords but the main problem is that it prints strings in Emacs syntax = which differs from that of tree-sitter. >=20 > As a consequence, :match regexps cannot contain newlines: >=20 > (treesit-query-capture > 'java > '(((identifier) @font-lock-constant-face > (:match "hello\n" @font-lock-constant-face)))) >=20 > signals a syntax error. >=20 > As far as I can tell the tree-sitter string syntax allows for the = escape sequences: >=20 > \n =3D LF > \r =3D CR > \t =3D TAB > \0 =3D NUL (only a single 0 -- no octal escapes!) > \X =3D the character X itself >=20 > Unescape newlines result in a syntax error as seen in the example = above. NULs don't seem to go well either. >=20 > At the very least, the conversion should avoid literal newlines and = NULs in the result (and probably CR and TAB). This cannot be done with a = straight prin1-to-string. >=20 > (By the way, why is the conversion written in C? Was Lisp too slow?) Because I wasn't sure if it=E2=80=99s ok for C functions to rely on Lisp = functions, plus the function is simple enough. Right now if one = doesn=E2=80=99t load treesit.el, all the C functions work fine. >=20 > Ideally we should not need to expose the tree-sitter s-exp query = syntax at all. Surely Emacs s-exps should be preferable in every case? >=20 It shouldn=E2=80=99t hurt to expose the tree-sitter sexp. Other editors = mainly use the string syntax. Yuan= From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 15 18:13:32 2023 Received: (at 64017) by debbugs.gnu.org; 15 Jun 2023 22:13:32 +0000 Received: from localhost ([127.0.0.1]:48158 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q9vDg-0003eh-8C for submit@debbugs.gnu.org; Thu, 15 Jun 2023 18:13:32 -0400 Received: from mail-pf1-f178.google.com ([209.85.210.178]:42090) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q9vDe-0003eR-5z for 64017@debbugs.gnu.org; Thu, 15 Jun 2023 18:13:30 -0400 Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-666b0fab552so149377b3a.0 for <64017@debbugs.gnu.org>; Thu, 15 Jun 2023 15:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686867204; x=1689459204; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RU5Lie9mTdmhjxzbIVoSTTn7ej1W1ZKG9j6BeVapQmo=; b=k7VMIC/pJHMdH4HLiNLkkDOe12XejR4QuXm4mm5OhU+bsb6zRlp+7ZDG2hqZkUZN1M uKZJcTZKM1z7UdldFtOL6MdRcc/ddQocRW+13yobHRteOXuHPGdn0h3EAMukUipWJtd+ x+C5j8V252OyThalWsLmqA27NKB8i1tXDt512sB/2b5YAMhfdoDxN4SHe95ma0PvQ/uJ b0ApzPvitDKYLWopIHTV3F5hpuJrRioy7Qubv0skw7h0IiFonw67pkN0NcaAHMpfnXWF nmCvadt5nuD2lL4fzpj+pFBlBJyAxNSLmuBCBKL4Qg85ywHDKNIb4XS5/YJb5f7aEkLz Y23Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686867204; x=1689459204; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RU5Lie9mTdmhjxzbIVoSTTn7ej1W1ZKG9j6BeVapQmo=; b=TrY/jdeZsadAoEs+//4RuwkF2028k+FhpBqPbGRQOcOaJeqGGd1lBA2oDVm6G2OLD9 EmPOwuqE0tXs7byNialMn2WiAhkK0kW9G9/ExZqFzScYmXmG3sFI9kxDCmp4cA4TmogA Qi/DwDTRRfrG35VT7wLfNKTxc+zG7bLSji+h03ySRa7Pgl7EzrbX/m64vEZnOQ2quxKx MmbK07TYSKwDoo6foRjevqCGS3FhdoAjGm9OXjpgjD26/pOfwh/7rgru0huifv3CHv5D cG8n00wyZwhqUHHJ/eeFcjVpRbAAxGU4V1TcWW0Utb+X8pgTYFuwkIIb1go+wTJlvxNw 9oeQ== X-Gm-Message-State: AC+VfDzHPgEdlRmEcTtM38/HEYeNrIsl9TofjWaNvqeohEDrljCdoAd1 DaGH/uRPrlq7HXh5/oZgT1E= X-Google-Smtp-Source: ACHHUZ4q52ErqWrH1x7/Ar6qM0U17bLBUQywtL9JOzdak41N5o+gkKP0wmnSGtBqx03rJFPU4rsDNg== X-Received: by 2002:a17:902:d4d2:b0:1ae:9105:10a5 with SMTP id o18-20020a170902d4d200b001ae910510a5mr6968579plg.2.1686867203862; Thu, 15 Jun 2023 15:13:23 -0700 (PDT) Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id kg14-20020a170903060e00b001b06361a38dsm1391913plb.116.2023.06.15.15.13.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2023 15:13:23 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Subject: Re: bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax From: Yuan Fu In-Reply-To: <195848A8-37EA-4F1C-AFDB-C1BB4F30BEA1@gmail.com> Date: Thu, 15 Jun 2023 15:13:12 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <0583F162-026C-4469-8DD6-69B78549F563@gmail.com> References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> <195848A8-37EA-4F1C-AFDB-C1BB4F30BEA1@gmail.com> To: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= X-Mailer: Apple Mail (2.3731.600.7) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 64017 Cc: Basil Contovounesios , 64017@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On Jun 15, 2023, at 3:45 AM, Mattias Engdeg=C3=A5rd = wrote: >=20 > I also propose that we change the documentation to describe the = (Elisp) sexp-based query syntax only, or at least first and foremost, = since that is what all existing code uses and is more convenient. = Currently the manual starts by describing the string syntax and only = then the Elisp sexp syntax. >=20 The difference between tree-sitter syntax and Elisp sexp syntax is petty = small (anchor, predicates), so the text describing the tree-sitter = syntax is basically describing Elisp sexp syntax. With that said if = someone makes it describe Elisp sexp syntax first, I wouldn=E2=80=99t = mind. Yuan= From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 16 07:25:58 2023 Received: (at submit) by debbugs.gnu.org; 16 Jun 2023 11:25:58 +0000 Received: from localhost ([127.0.0.1]:48712 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qA7aX-0003To-Rt for submit@debbugs.gnu.org; Fri, 16 Jun 2023 07:25:58 -0400 Received: from lists.gnu.org ([209.51.188.17]:58826) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qA7aV-0003Tf-34 for submit@debbugs.gnu.org; Fri, 16 Jun 2023 07:25:55 -0400 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 1qA7aU-0003Lf-O3 for bug-gnu-emacs@gnu.org; Fri, 16 Jun 2023 07:25:54 -0400 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qA7aT-0008Ot-20 for bug-gnu-emacs@gnu.org; Fri, 16 Jun 2023 07:25:54 -0400 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f762b3227dso842835e87.1 for ; Fri, 16 Jun 2023 04:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686914750; x=1689506750; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=I2xiNVZDWgDTxWlM/lLH22vLRbBhF0rKiOH7UYIju3o=; b=Q6u6e4jDMQvl5n6HRdnq8Tm+IIywoDQFsxtiK6WUc+jnLcue6Y6SHNBQ7gqUX3gSNd 72NfJcIH9KszDsS8XgKClkh1WRaqikeJ2/p7UjLyAWpR7HnFlYuUh3jWFYKsfekJYJgD ueQ8w+mWSxqZqTGhDjA4JGXKCTfkxGTe7MuzfDMY1/m5Sgi2RTuLRjEdfwutgBb7MHVS pST3VD8E8kb3AIVi0vhAUfiKxtHWPZOTO3gPUQ8NZLbsLpS2fzKmnraoOtzH3j3WhiaH RyCvQIVFktLX5pg+AefM85fkLwmuJIvEwBCDzd7zb+gmy86BYOTia3fy8nH/xR8U7PMQ 9WwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686914750; x=1689506750; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=I2xiNVZDWgDTxWlM/lLH22vLRbBhF0rKiOH7UYIju3o=; b=I4SwSAVK+ai/JFY1FZX9ttJM8HqUw68rTZMciXJxvY5AHMWcYqvHX2Udltd/riIbbF YnEauw8Lzx4AhMy1QRnOL10m4smTUUVS0ce0nGCzogBWp0sjz+E4Vsu/jaypbMbwQ0xN SiurWL4AhecGo+HGEo4YUFXXPAVFdsQtpSmBwJd1Se9lWeODGi/1nYsdvDXIvFuJ0iil wZsX1DapR1KyjVvQC9Gp5N8PgzFw2IGL+vfAiBXpR0cOq5Lg/SLRrgMbke3YSUXwwFyy iNkh9TFZk3Pm1bU8o4sUmTpOI1xr793Yvt9RQ/DN71XGZChvsXlz4mJLWEMjxfU5zN5H PTNQ== X-Gm-Message-State: AC+VfDyifGIc9hBYq4ARWkKCJl528KUajRDTnva50emJpkNYgNniND3J GQJgquvpd5AOh/h7qWw8jiI= X-Google-Smtp-Source: ACHHUZ7fk1mo24OBUqvrIPFCtl0b3mUfnZiehmfGf1WZpTDmJrMooQCi9gvQ7q0saLM2Mgc2EVBP0w== X-Received: by 2002:ac2:5b5b:0:b0:4f6:2b50:8a1a with SMTP id i27-20020ac25b5b000000b004f62b508a1amr603035lfp.8.1686914749672; Fri, 16 Jun 2023 04:25:49 -0700 (PDT) Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id s2-20020a19ad42000000b004f6284b3064sm2974541lfd.140.2023.06.16.04.25.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jun 2023 04:25:49 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Subject: Re: Wrong conversion from Emacs to Tree-sitter S-expression syntax From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= In-Reply-To: Date: Fri, 16 Jun 2023 13:25:48 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> To: Yuan Fu X-Mailer: Apple Mail (2.3654.120.0.1.15) Received-SPF: pass client-ip=2a00:1450:4864:20::12f; envelope-from=mattias.engdegard@gmail.com; helo=mail-lf1-x12f.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-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: Basil Contovounesios , Bug Report Emacs X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) 16 juni 2023 kl. 00.08 skrev Yuan Fu : >> (By the way, why is the conversion written in C? Was Lisp too slow?) >=20 > Because I wasn't sure if it=E2=80=99s ok for C functions to rely on = Lisp functions, plus the function is simple enough. Right now if one = doesn=E2=80=99t load treesit.el, all the C functions work fine. All right, let's keep it there for now. I fixed the string conversion bug in 8657afac77. >> Ideally we should not need to expose the tree-sitter s-exp query = syntax at all. Surely Emacs s-exps should be preferable in every case? > It shouldn=E2=80=99t hurt to expose the tree-sitter sexp. Other = editors mainly use the string syntax. Most of them probably aren't written in Lisp. But fine, let's keep it as = an alternative syntax. > The difference between tree-sitter syntax and Elisp sexp syntax is = petty small (anchor, predicates), so the text describing the tree-sitter = syntax is basically describing Elisp sexp syntax. Yes, so it seemed to me but reading the source code (lib/src/query.c) = seems to indicate that what I thought were symbols -- *, +, ?, @thing, = #thing -- appear to be special postfix and prefix operators. = (Ironically, there doesn't seem to be a grammar for this language = anywhere, or am I mistaken?) Thus a structurally correct Lispish translation of (teet "toot"* (#equal "fie" @fum)) should arguable be something like (teet (* "toot") ((# equal) "fie" (@ fum))) rather than the current (teet "toot" :* (:equal "fie @fum)) but I'm not demanding that it all be changed at this stage. > With that said if someone makes it describe Elisp sexp syntax first, I = wouldn=E2=80=99t mind. I'll have a look. Wouldn't it be reasonable to use the Elisp syntax, = briefly state how it corresponds to the 'native' syntax, and refer to = the official tree-sitter documentation for details about the latter? From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 16 13:03:07 2023 Received: (at submit) by debbugs.gnu.org; 16 Jun 2023 17:03:07 +0000 Received: from localhost ([127.0.0.1]:50274 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qACqo-0006sN-Rp for submit@debbugs.gnu.org; Fri, 16 Jun 2023 13:03:07 -0400 Received: from lists.gnu.org ([209.51.188.17]:60182) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qACqm-0006sG-S1 for submit@debbugs.gnu.org; Fri, 16 Jun 2023 13:03:05 -0400 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 1qACqm-00069k-EK for bug-gnu-emacs@gnu.org; Fri, 16 Jun 2023 13:03:04 -0400 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qACqk-0002ly-OJ for bug-gnu-emacs@gnu.org; Fri, 16 Jun 2023 13:03:04 -0400 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f84d70bf96so1226170e87.0 for ; Fri, 16 Jun 2023 10:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686934980; x=1689526980; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=8rv7Bkw+TqK0PC3iid2gLmXLiR1kHtL3LEBV2Wb1mCw=; b=n3RlRwsJ9xEDCoAk98QW6oZdjgTg+NfcbKP4O2DLZHGGnOQn6BGQ38QCi+CZ6BKdTx ciJXxFhue7Y8VMhCYtN7ZvouSg8QSO2xnRfvrk/TqOzZ1a/4nCspcZtHZw8shTsCC3+T DzQd2Nr+46wPlW2/7hsO2TtWUuRLNoyAFijyvJr3ohj5qokCaKgbcv3j2HRgsK3TiM7X 0ziokjV8AtzFLvWSqpPO616zn0XvBdtpiluLF2u/F3egr+LORgOcNurnGjSY+YyfhtCD ahvqNMNO3A1ePutH1eck/Xag9fw7YmRf8fssI1qSP7FwnM+uFYzIz6TJ4sblSOOgftp3 RrNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686934980; x=1689526980; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8rv7Bkw+TqK0PC3iid2gLmXLiR1kHtL3LEBV2Wb1mCw=; b=lPqvIG1rVNcLPlSFxmhimKnKD47HtNf2E1uB2y+9T5/bFcz8vSgKMm9pEHVKUqmKZw T8kRuy3dKL515aNsNG0oDWgF0kJ4GXP98YfPSYoYAiDXO/0UQ0UMe0tEE2Vj3Ox1z/lW owt08YHZJ1ZIF6Oblsh+OOZMETyf+7yo0kKoygmdLfGgL1aXMHxaCyjIHPOsdGaOaEu2 ptUH0yLOpYqTvsF8+rnjIt1RiWAMH/Vr4nXnWhmvTwgSKlzMKN+b/pLYwJ/K7F6BZ115 5OvbeWQXVrzsh1SE5pTmoYGjuq2ib8QX6uQ40oh+XFgIJwdp9ViO50YcnHdYo8+4IHY/ oe4Q== X-Gm-Message-State: AC+VfDxCBPdYszE36LP8VG+j/RMLKwob7ByQmanTPt9bVybtY24gstjU misJKfwQOZ0s6UEzD71Vh4w= X-Google-Smtp-Source: ACHHUZ54WApxyUwQen4LTsdOjb8d9sULHs7BF2eYSj0kqSjf6BjfF/iY/7K0Skb7WZ3hoUMcJY1WJg== X-Received: by 2002:a19:9154:0:b0:4f8:45aa:f844 with SMTP id y20-20020a199154000000b004f845aaf844mr778974lfj.31.1686934980367; Fri, 16 Jun 2023 10:03:00 -0700 (PDT) Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id d1-20020ac244c1000000b004f73eac0308sm1105497lfm.183.2023.06.16.10.02.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jun 2023 10:02:59 -0700 (PDT) From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Message-Id: <04C45D03-D49B-4DE4-AD26-2606C94AF260@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_DC59A527-37D8-4AC7-8BA2-A7B078AD7320" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Subject: Re: Wrong conversion from Emacs to Tree-sitter S-expression syntax Date: Fri, 16 Jun 2023 19:02:58 +0200 In-Reply-To: <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> To: Yuan Fu References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> X-Mailer: Apple Mail (2.3654.120.0.1.15) Received-SPF: pass client-ip=2a00:1450:4864:20::12f; envelope-from=mattias.engdegard@gmail.com; helo=mail-lf1-x12f.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-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: Basil Contovounesios , Bug Report Emacs X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --Apple-Mail=_DC59A527-37D8-4AC7-8BA2-A7B078AD7320 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Here is a modification of the treesit manual to teach s-expressions first. It's mostly a matter of straightforward substitution. --Apple-Mail=_DC59A527-37D8-4AC7-8BA2-A7B078AD7320 Content-Disposition: attachment; filename=treesit-doc-sexp-patterns.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="treesit-doc-sexp-patterns.diff" Content-Transfer-Encoding: 7bit diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index b0824faaaa2..bd81ee3c535 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi @@ -1132,9 +1132,9 @@ Pattern Matching @defun treesit-query-capture node query &optional beg end node-only This function matches patterns in @var{query} within @var{node}. -The argument @var{query} can be either a string, a s-expression, or a -compiled query object. For now, we focus on the string syntax; -s-expression syntax and compiled query are described at the end of the +The argument @var{query} can be either a s-expression, a string, or a +compiled query object. For now, we focus on the s-expression syntax; +string syntax and compiled query are described at the end of the section. The argument @var{node} can also be a parser or a language symbol. A @@ -1165,8 +1165,8 @@ Pattern Matching @example @group (setq query - "(binary_expression - (number_literal) @@number-in-exp) @@biexp") + '((binary_expression + (number_literal) @@number-in-exp) @@biexp) @end group @end example @@ -1187,8 +1187,8 @@ Pattern Matching @example @group (setq query - "(binary_expression) @@biexp - (number_literal) @@number @@biexp") + '((binary_expression) @@biexp + (number_literal) @@number @@biexp) @end group @end example @@ -1246,23 +1246,23 @@ Pattern Matching @subheading Quantify node @cindex quantify node, tree-sitter -Tree-sitter recognizes quantification operators @samp{*}, @samp{+} and -@samp{?}. Their meanings are the same as in regular expressions: -@samp{*} matches the preceding pattern zero or more times, @samp{+} -matches one or more times, and @samp{?} matches zero or one time. +Tree-sitter recognizes quantification operators @samp{:*}, @samp{:+} and +@samp{:?}. Their meanings are the same as in regular expressions: +@samp{:*} matches the preceding pattern zero or more times, @samp{:+} +matches one or more times, and @samp{:?} matches zero or one time. For example, the following pattern matches @code{type_declaration} nodes that has @emph{zero or more} @code{long} keyword. @example -(type_declaration "long"*) @@long-type +(type_declaration "long" :*) @@long-type @end example The following pattern matches a type declaration that has zero or one @code{long} keyword: @example -(type_declaration "long"?) @@long-type +(type_declaration "long" :?) @@long-type @end example @subheading Grouping @@ -1272,15 +1272,15 @@ Pattern Matching express a comma separated list of identifiers, one could write @example -(identifier) ("," (identifier))* +(identifier) ("," (identifier)) :* @end example @subheading Alternation -Again, similar to regular expressions, we can express ``match anyone -from this group of patterns'' in a pattern. The syntax is a list of -patterns enclosed in square brackets. For example, to capture some -keywords in C, the pattern would be +Again, similar to regular expressions, we can express ``match any one +from this group of patterns'' in a pattern. The syntax is a vector of +patterns. For example, to capture some keywords in C, the pattern +would be @example @group @@ -1295,7 +1295,7 @@ Pattern Matching @subheading Anchor -The anchor operator @samp{.} can be used to enforce juxtaposition, +The anchor operator @code{:anchor} can be used to enforce juxtaposition, i.e., to enforce two things to be directly next to each other. The two ``things'' can be two nodes, or a child and the end of its parent. For example, to capture the first child, the last child, or two @@ -1304,19 +1304,19 @@ Pattern Matching @example @group ;; Anchor the child with the end of its parent. -(compound_expression (_) @@last-child .) +(compound_expression (_) @@last-child :anchor) @end group @group ;; Anchor the child with the beginning of its parent. -(compound_expression . (_) @@first-child) +(compound_expression :anchor (_) @@first-child) @end group @group ;; Anchor two adjacent children. (compound_expression (_) @@prev-child - . + :anchor (_) @@next-child) @end group @end example @@ -1332,8 +1332,8 @@ Pattern Matching @example @group ( - (array . (_) @@first (_) @@last .) - (#equal @@first @@last) + (array :anchor (_) @@first (_) @@last :anchor) + (:equal @@first @@last) ) @end group @end example @@ -1341,22 +1341,23 @@ Pattern Matching @noindent tree-sitter only matches arrays where the first element equals to the last element. To attach a predicate to a pattern, we need to group -them together. A predicate always starts with a @samp{#}. Currently -there are three predicates, @code{#equal}, @code{#match}, and -@code{#pred}. +them together. Currently +there are three predicates, @code{:equal}, @code{:match}, and +@code{:pred}. -@deffn Predicate equal arg1 arg2 +@deffn Predicate :equal arg1 arg2 Matches if @var{arg1} equals to @var{arg2}. Arguments can be either strings or capture names. Capture names represent the text that the captured node spans in the buffer. @end deffn -@deffn Predicate match regexp capture-name +@deffn Predicate :match regexp capture-name Matches if the text that @var{capture-name}'s node spans in the buffer -matches regular expression @var{regexp}. Matching is case-sensitive. +matches regular expression @var{regexp}, given as a string literal. +Matching is case-sensitive. @end deffn -@deffn Predicate pred fn &rest nodes +@deffn Predicate :pred fn &rest nodes Matches if function @var{fn} returns non-@code{nil} when passed each node in @var{nodes} as arguments. The function runs with the current buffer set to the buffer of node being queried. @@ -1366,23 +1367,23 @@ Pattern Matching the same pattern. Indeed, it makes little sense to refer to capture names in other patterns. -@heading S-expression patterns +@heading String patterns -@cindex tree-sitter patterns as sexps -@cindex patterns, tree-sitter, in sexp form -Besides strings, Emacs provides a s-expression based syntax for -tree-sitter patterns. It largely resembles the string-based syntax. -For example, the following query +@cindex tree-sitter patterns as strings +@cindex patterns, tree-sitter, in string form +Besides s-expressions, Emacs allows the tree-sitter's native query +syntax to be used by writing them as strings. It largely resembles +the s-expression syntax. For example, the following query @example @group (treesit-query-capture - node "(addition_expression - left: (_) @@left - \"+\" @@plus-sign - right: (_) @@right) @@addition + node '((addition_expression + left: (_) @@left + "+" @@plus-sign + right: (_) @@right) @@addition - [\"return\" \"break\"] @@keyword") + ["return" "break"] @@keyword)) @end group @end example @@ -1392,52 +1393,52 @@ Pattern Matching @example @group (treesit-query-capture - node '((addition_expression - left: (_) @@left - "+" @@plus-sign - right: (_) @@right) @@addition + node "(addition_expression + left: (_) @@left + \"+\" @@plus-sign + right: (_) @@right) @@addition - ["return" "break"] @@keyword)) + [\"return\" \"break\"] @@keyword") @end group @end example -Most patterns can be written directly as strange but nevertheless -valid s-expressions. Only a few of them needs modification: +Most patterns can be written directly as s-expressions inside a string. +Only a few of them need modification: @itemize @item -Anchor @samp{.} is written as @code{:anchor}. +Anchor @code{:anchor}. is written as @samp{.} @item -@samp{?} is written as @samp{:?}. +@samp{:?} is written as @samp{?}. @item -@samp{*} is written as @samp{:*}. +@samp{:*} is written as @samp{*}. @item -@samp{+} is written as @samp{:+}. +@samp{:+} is written as @samp{+}. @item -@code{#equal} is written as @code{:equal}. In general, predicates -change their @samp{#} to @samp{:}. +@code{:equal} is written as @code{#equal}. In general, predicates +change their @samp{:} to @samp{#}. @end itemize For example, @example @group -"( - (compound_expression . (_) @@first (_)* @@rest) - (#match \"love\" @@first) - )" +'(( + (compound_expression :anchor (_) @@first (_) :* @@rest) + (:match "love" @@first) + )) @end group @end example @noindent -is written in s-expression as +is written in string form as @example @group -'(( - (compound_expression :anchor (_) @@first (_) :* @@rest) - (:match "love" @@first) - )) +"( + (compound_expression . (_) @@first (_)* @@rest) + (#match \"love\" @@first) + )" @end group @end example @@ -1461,7 +1462,7 @@ Pattern Matching @end defun @defun treesit-query-language query -This function return the language of @var{query}. +This function returns the language of @var{query}. @end defun @defun treesit-query-expand query @@ -1653,7 +1654,7 @@ Multiple Languages (setq css-range (treesit-query-range 'html - "(style_element (raw_text) @@capture)")) + '((style_element (raw_text) @@capture)))) (treesit-parser-set-included-ranges css css-range) @end group @@ -1662,7 +1663,7 @@ Multiple Languages (setq js-range (treesit-query-range 'html - "(script_element (raw_text) @@capture)")) + '((script_element (raw_text) @@capture)))) (treesit-parser-set-included-ranges js js-range) @end group @end example --Apple-Mail=_DC59A527-37D8-4AC7-8BA2-A7B078AD7320-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 16 13:33:39 2023 Received: (at 64017) by debbugs.gnu.org; 16 Jun 2023 17:33:39 +0000 Received: from localhost ([127.0.0.1]:50312 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qADKN-0007hj-2p for submit@debbugs.gnu.org; Fri, 16 Jun 2023 13:33:39 -0400 Received: from mail-wm1-f51.google.com ([209.85.128.51]:62536) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qADKJ-0007hS-Va for 64017@debbugs.gnu.org; Fri, 16 Jun 2023 13:33:37 -0400 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-3f8ff5fe50aso975595e9.0 for <64017@debbugs.gnu.org>; Fri, 16 Jun 2023 10:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd.ie; s=google21; t=1686936810; x=1689528810; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0T+4sWJ+ZOuzEYtkcgjhJvjnSeoJwTiEIsyCvFRCtJw=; b=T8yz/tlN1QEoKmG0ZspfW90dfK/Mf4W9w4Tkm2EGnGPethIt1xJrGZtjfFZ3iK5d84 +W64sBlS4oopCER6Oe4eTSKk/0lPOrd9ESJBlyb9ibNXrM5WMEuL54QZQRrFUsTWmyMF IN4/kRb5wphwmaI/XKm2E0uA+ALydmtXpD0LsqYn4BlXAxfLZQ6Op+86guOAgF8Ma6Y/ b6DXtXz2U1WykuZwwH9naAU1Wm9EQfjhExUKpgafAukdkq9uCAf2G5I/VEp9q2B+aR0M 9m5e69By1bSBIgKLPnMW6F/5RI/f/vBZpMohhINgJMYi5SuGKtNCN3nzI5UsnUOZtluy Ur7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686936810; x=1689528810; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0T+4sWJ+ZOuzEYtkcgjhJvjnSeoJwTiEIsyCvFRCtJw=; b=j/yKoEWEENZChZ/6ckazAN1dwa3kgDQT5hzQcaMOzqI4nxvZ9PfEBj0D7JSyD3o5pV JQei4iC12YiNeTrdx5pBS6vABEDoWudJ7ffHDT1evmxVVNvYog2IcAYLhetWI7a9pccN 9KAu7ED7/CYKSzIOA42oZejwmdV+VLx+ADE+Nu0hQbRakl2O+oHRAX/inATUJaU4S+ew IFh2TgV69g8lfZ5jskOa+uhBAVBFOlAXM5RT91wtdC/nphypaELW2SP3Xh8S5YPmc/7y eVbopvVz9rKBIwM0OIOwa+dzdg5qDIlSjCazIfLcRKRiE0zDgD3EtLSmHNPAqd97yrRu 2kkg== X-Gm-Message-State: AC+VfDxU4QCYNQOWJ3waIjhpAVt/eZqV5SjK+HkgTYd/jUNT0p3E+7MF SQwpX5y2olYo+v9w38MMkK4Lrw== X-Google-Smtp-Source: ACHHUZ6YhgII2EcaThuq5ueJiUl0wGfBmerQHaYAR8lH/XK2NO3ya4RlVHSgUECIWM/VkgClX0KpDw== X-Received: by 2002:a05:600c:4f96:b0:3f7:f302:161 with SMTP id n22-20020a05600c4f9600b003f7f3020161mr7732454wmq.8.1686936809950; Fri, 16 Jun 2023 10:33:29 -0700 (PDT) Received: from localhost ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id l20-20020a1c7914000000b003f709a7e46bsm2697072wme.46.2023.06.16.10.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 10:33:29 -0700 (PDT) From: Basil Contovounesios To: Mattias =?utf-8?Q?Engdeg=C3=A5rd?= Subject: Re: bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax In-Reply-To: <04C45D03-D49B-4DE4-AD26-2606C94AF260@gmail.com> ("Mattias =?utf-8?Q?Engdeg=C3=A5rd=22's?= message of "Fri, 16 Jun 2023 19:02:58 +0200") References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> <04C45D03-D49B-4DE4-AD26-2606C94AF260@gmail.com> Date: Fri, 16 Jun 2023 18:33:28 +0100 Message-ID: <87r0qb1fdj.fsf@epfl.ch> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 64017 Cc: Yuan Fu , 64017@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Mattias Engdeg=C3=A5rd [2023-06-16 19:02 +0200] wrote: > Here is a modification of the treesit manual to teach s-expressions first. > It's mostly a matter of straightforward substitution. Generally LGTM, thanks. > diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi > index b0824faaaa2..bd81ee3c535 100644 > --- a/doc/lispref/parsing.texi > +++ b/doc/lispref/parsing.texi > @@ -1132,9 +1132,9 @@ Pattern Matching >=20=20 > @defun treesit-query-capture node query &optional beg end node-only > This function matches patterns in @var{query} within @var{node}. > -The argument @var{query} can be either a string, a s-expression, or a > -compiled query object. For now, we focus on the string syntax; > -s-expression syntax and compiled query are described at the end of the > +The argument @var{query} can be either a s-expression, a string, or a > +compiled query object. For now, we focus on the s-expression syntax; > +string syntax and compiled query are described at the end of the > section. I recently tweaked some of these docs in emacs-29, so you may want to merge into master before respinning your patch. > @@ -1341,22 +1341,23 @@ Pattern Matching > @noindent > tree-sitter only matches arrays where the first element equals to the > last element. To attach a predicate to a pattern, we need to group > -them together. A predicate always starts with a @samp{#}. Currently > -there are three predicates, @code{#equal}, @code{#match}, and > -@code{#pred}. > +them together. Currently > +there are three predicates, @code{:equal}, @code{:match}, and > +@code{:pred}. Do you intend to refill the paragraph before merging? > @itemize > @item > -Anchor @samp{.} is written as @code{:anchor}. > +Anchor @code{:anchor}. is written as @samp{.} ^ Unladen European full stop migrated from eol. --=20 Basil From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 06:48:03 2023 Received: (at 64017) by debbugs.gnu.org; 17 Jun 2023 10:48:03 +0000 Received: from localhost ([127.0.0.1]:50921 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qATTO-0004Q6-Pe for submit@debbugs.gnu.org; Sat, 17 Jun 2023 06:48:03 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:53524) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qATTL-0004Os-Dz for 64017@debbugs.gnu.org; Sat, 17 Jun 2023 06:48:01 -0400 Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-4f8467e39cfso2192465e87.3 for <64017@debbugs.gnu.org>; Sat, 17 Jun 2023 03:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686998873; x=1689590873; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=nrKDMEQdY0Q0dMl2scgM+8JPcVBMvJDNbxyDpZ88JfA=; b=jdEipR9dUCsXjyrNbZae+0s3t6cajjlM9iDYC8Q20/po1IlzQaPgyGCESPzAhOyUW6 YWvYbKNKmoMkYKPdarb2KMeFUv3C3iqjY3aM19rD1uuI7cDWtoId2jyNx7Ye9uLz3c/C PFqqUOi0QYD4ujzDy1z/vWUdWivtpcy5hIpSGfwOOHbjF8FUf6huy8ghm2U746wg18Wg F8SFXpEGRdinZ19PhZYCt+VXoNvTjKfb6JWIr7em1dIQEeM8ok/qxUl/i8gokefhMGoy 7pvGrgHblKZCpF1xEbm/lJYylvAC47SS6bnWte19jg3mimNBsynqI0dE/HsoHgSnKDtc 6Kfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686998873; x=1689590873; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nrKDMEQdY0Q0dMl2scgM+8JPcVBMvJDNbxyDpZ88JfA=; b=PiF514G1jw63GhBhqyhpQZ5a345Gf2MduRMK/OzO2JhvfMIk4/jQXnHVxyZH0OwG7H szFbVYtVU6qO9JqIIKuC9AGyuAmIOhHlfC+AJ6SulIDhI4HzqTc2nlQSdAPMfY6/KMCo 45E8nCb2wLC/4l89ZC0GuNaIYBiz2gYGNeVjbqV8VWVmJwNqaqw3kuH1sT52lood7/fq sKsPNi7AT7UzCDB5J41SacnFrNuIF2sJs1awBU2Kqf8QiLT05eTBWR0f99Gx8fkGJnu2 0Qo6wiyf7Z1ffLQ1HTm/EFtpjlywCqgZos1oCBqwe5J05uOzzxc+50//I6SS5Eg/BipZ vEHg== X-Gm-Message-State: AC+VfDxbN38sVa3zrPSr3rTzmECe3ranrg6SqxwfemgcntIM3NI61Out bDJlvPvSt1UcoJki18VA6Lo= X-Google-Smtp-Source: ACHHUZ4fpJklHDN5xTsfB9z+4QVlrIN1x+dqqBsHGQEQNQc68tla+F+IOFexMH99rD4/zmJbgSH60w== X-Received: by 2002:ac2:499e:0:b0:4f3:a485:919a with SMTP id f30-20020ac2499e000000b004f3a485919amr3005365lfl.57.1686998872887; Sat, 17 Jun 2023 03:47:52 -0700 (PDT) Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id y16-20020ac24210000000b004edc55d3900sm1372488lfh.0.2023.06.17.03.47.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Jun 2023 03:47:52 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Subject: Re: bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= In-Reply-To: <87r0qb1fdj.fsf@epfl.ch> Date: Sat, 17 Jun 2023 12:47:51 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <078740D5-8AA0-47B5-A34D-6E5C3E0C34B3@gmail.com> References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> <04C45D03-D49B-4DE4-AD26-2606C94AF260@gmail.com> <87r0qb1fdj.fsf@epfl.ch> To: Basil Contovounesios X-Mailer: Apple Mail (2.3654.120.0.1.15) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 64017 Cc: Yuan Fu , Eli Zaretskii , 64017@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 16 juni 2023 kl. 19.33 skrev Basil Contovounesios : > I recently tweaked some of these docs in emacs-29, so you may want to > merge into master before respinning your patch. Will do, thank you. Since this is only about documentation, perhaps it = could be done in emacs-29? Eli, would that be acceptable? > Do you intend to refill the paragraph before merging? I probably should (although it doesn't affect the output). >> -Anchor @samp{.} is written as @code{:anchor}. >> +Anchor @code{:anchor}. is written as @samp{.} > ^ > Unladen European full stop migrated from eol. So it tried to get away, that little rascal! Can't blame it for trying. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 08:57:21 2023 Received: (at 64017) by debbugs.gnu.org; 17 Jun 2023 12:57:21 +0000 Received: from localhost ([127.0.0.1]:51011 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAVUX-00028r-Gn for submit@debbugs.gnu.org; Sat, 17 Jun 2023 08:57:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33410) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAVUS-00028b-Px for 64017@debbugs.gnu.org; Sat, 17 Jun 2023 08:57:19 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAVUL-0006V4-U5; Sat, 17 Jun 2023 08:57:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=Gnr/uI3f/olFDzsTwr/wB6uCJP+G7/pWskjQa96TTNM=; b=XdUqs7a6VMrQKeC7M4wz gL1MRt+5gqPGl4ktaOv7kpFLmeG3zJNKCD2dNSwRpZ2LB2jIXq7140WeprNOKFVL5Pn5dGGhza5Sa sGKN1aly0qhGOP9RwLk5aY9QuflgmnaRScmZ0DJ9yvPpDzpaTAlJ1Fs0CenfC/D1HwnIPXHAQhnTp B/Zqus8n4q9k/WRz5dl8F3XOc+8nv/dTY7ArB4ZLBf5xCtLzqDJ4FjGDGYdyCjLnR/p6SaQ7pgxue WY+Fmchvk/aoNjYQTVNc0pcapEoz5yUArh1aMshgvXjzHz6R5++bh6iVZHLOZ/ueHeIREw2Ifx0JN ++V6OqwqrrrIcQ==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAVUL-0005eg-Ce; Sat, 17 Jun 2023 08:57:09 -0400 Date: Sat, 17 Jun 2023 15:57:06 +0300 Message-Id: <83bkheqmal.fsf@gnu.org> From: Eli Zaretskii To: Mattias =?utf-8?Q?Engdeg=C3=A5rd?= In-Reply-To: <078740D5-8AA0-47B5-A34D-6E5C3E0C34B3@gmail.com> (message from Mattias =?utf-8?Q?Engdeg=C3=A5rd?= on Sat, 17 Jun 2023 12:47:51 +0200) Subject: Re: bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> <04C45D03-D49B-4DE4-AD26-2606C94AF260@gmail.com> <87r0qb1fdj.fsf@epfl.ch> <078740D5-8AA0-47B5-A34D-6E5C3E0C34B3@gmail.com> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 64017 Cc: contovob@tcd.ie, casouri@gmail.com, 64017@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Mattias EngdegÄrd > Date: Sat, 17 Jun 2023 12:47:51 +0200 > Cc: Yuan Fu , > 64017@debbugs.gnu.org, > Eli Zaretskii > > 16 juni 2023 kl. 19.33 skrev Basil Contovounesios : > > > I recently tweaked some of these docs in emacs-29, so you may want to > > merge into master before respinning your patch. > > Will do, thank you. Since this is only about documentation, perhaps it could be done in emacs-29? > Eli, would that be acceptable? If Yuan doesn't mind, yes. But I'd like to hear from Yuan that he is okay with these changes. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 09:30:17 2023 Received: (at 64017) by debbugs.gnu.org; 17 Jun 2023 13:30:17 +0000 Received: from localhost ([127.0.0.1]:51062 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAW0P-00030B-EN for submit@debbugs.gnu.org; Sat, 17 Jun 2023 09:30:17 -0400 Received: from mail-lf1-f45.google.com ([209.85.167.45]:42429) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAW0J-0002yo-QW for 64017@debbugs.gnu.org; Sat, 17 Jun 2023 09:30:15 -0400 Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-4f762b3227dso2186770e87.1 for <64017@debbugs.gnu.org>; Sat, 17 Jun 2023 06:30:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687008606; x=1689600606; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=AsBJzrLmVLE8JtXyQ/Lgc8qMNsxScxX50mXl/3TQoaQ=; b=BSFA5W1l22j14445+4rM5WVPPjUq34LAZnEMEZWa9DIm6ygZdQYkH9XKRe9lfl3KmP gLXMg/5OYIkFSiMiU3MUIII7kMmVz9Wn5k7R20Hri/kse8AtOSK2rGFIUK4E6elAFo35 MKyyBPFPP2oaeaTWm6eB8l3ken6XkBZWx0c1HZDCBYvQNWy0U1sDEsCuMDNYWZyh+TVy 1VYIvrogJlANfVo0UAHXXhGDJg/JdPZcay9BFdj71isq5SoLIE/OjpSPLWH1aQoWJm/I 8T9s9CO+Mro7Nzq6N/9soe2HLis3s/kfe9FM0wOqpPrWQU0zIs7uHnHd2niqxySokNYZ MyzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687008606; x=1689600606; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AsBJzrLmVLE8JtXyQ/Lgc8qMNsxScxX50mXl/3TQoaQ=; b=bhs9cHl9Bsj/TJNFPCEFO+Vz/YROISZe3I3ZukN2ombQlaReRZI/+z1iXCJsz/Hrp6 +fCCHb3cd2ltWBBG1SfKe2OLmh+2ITApZHyKjXlfEPtg46Y7TS/2RZQNDvGZxmxfEVlk A/CdFuOy7C2IIfRuGQNeC//NfsCUeS7ZFPG/YZJZvKIDrgvihyYpfJHmf14oGMFagWZ5 m/WpcCTQeuLDPeUqC5hd0JSdWe1azTQJRGuFJXEhXnQuidUNDZkkzTK3SAQoqMoHc2aY WRVLpuwK175i25KUbw4k+a4rtHbBt8JWd2T/L0YdBdfCja3D1WEb/BuKo9/2Xsv/LiQi iV5A== X-Gm-Message-State: AC+VfDxSpmmAzNhKDtQ58gAjj1VWSZRcWr2v0Sjpw9PVzp3DfKQJmXwX AYtZmyP4yaM+joP0WrKpSkI= X-Google-Smtp-Source: ACHHUZ7qYkvFrifBR355GrURHsQ0gB6NoEWoZD8LP0ftt6Rq91C4kk2HQQkkCtyOdtfoIZd/LP2c8w== X-Received: by 2002:a19:e341:0:b0:4f1:2ebf:536f with SMTP id c1-20020a19e341000000b004f12ebf536fmr1715660lfk.16.1687008605538; Sat, 17 Jun 2023 06:30:05 -0700 (PDT) Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id o2-20020ac24942000000b004f740564139sm2625355lfi.167.2023.06.17.06.30.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Jun 2023 06:30:04 -0700 (PDT) From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Message-Id: <67D3CF20-8641-4BF6-A102-037591B6E821@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_2A1B46EA-512E-4800-91B8-8FDDF623A06A" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Subject: Re: bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax Date: Sat, 17 Jun 2023 15:30:04 +0200 In-Reply-To: <83bkheqmal.fsf@gnu.org> To: Eli Zaretskii References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> <04C45D03-D49B-4DE4-AD26-2606C94AF260@gmail.com> <87r0qb1fdj.fsf@epfl.ch> <078740D5-8AA0-47B5-A34D-6E5C3E0C34B3@gmail.com> <83bkheqmal.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.120.0.1.15) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 64017 Cc: contovob@tcd.ie, casouri@gmail.com, 64017@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --Apple-Mail=_2A1B46EA-512E-4800-91B8-8FDDF623A06A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 17 juni 2023 kl. 14.57 skrev Eli Zaretskii : >> Will do, thank you. Since this is only about documentation, perhaps = it could be done in emacs-29? >> Eli, would that be acceptable? >=20 > If Yuan doesn't mind, yes. But I'd like to hear from Yuan that he is > okay with these changes. Attached are the changes rebased to emacs-29 (fixing mistakes found by = Basil). --Apple-Mail=_2A1B46EA-512E-4800-91B8-8FDDF623A06A Content-Disposition: attachment; filename=treesit-doc-sexp-patterns-em29.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="treesit-doc-sexp-patterns-em29.diff" Content-Transfer-Encoding: 7bit diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index 3906ca0118a..9e1df07d25c 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi @@ -1084,9 +1084,9 @@ Pattern Matching @defun treesit-query-capture node query &optional beg end node-only This function matches patterns in @var{query} within @var{node}. The -argument @var{query} can be either a string, an s-expression, or a -compiled query object. For now, we focus on the string syntax; -s-expression syntax and compiled queries are described at the end of +argument @var{query} can be either an s-expression, a string, or a +compiled query object. For now, we focus on the s-expression syntax; +string syntax and compiled queries are described at the end of the section. The argument @var{node} can also be a parser or a language symbol. A @@ -1118,8 +1118,8 @@ Pattern Matching @example @group (setq query - "(binary_expression - (number_literal) @@number-in-exp) @@biexp") + '((binary_expression + (number_literal) @@number-in-exp) @@biexp) @end group @end example @@ -1140,8 +1140,8 @@ Pattern Matching @example @group (setq query - "(binary_expression) @@biexp - (number_literal) @@number @@biexp") + '((binary_expression) @@biexp + (number_literal) @@number @@biexp) @end group @end example @@ -1199,23 +1199,23 @@ Pattern Matching @subheading Quantify node @cindex quantify node, tree-sitter -Tree-sitter recognizes quantification operators @samp{*}, @samp{+}, -and @samp{?}. Their meanings are the same as in regular expressions: -@samp{*} matches the preceding pattern zero or more times, @samp{+} -matches one or more times, and @samp{?} matches zero or one times. +Tree-sitter recognizes quantification operators @samp{:*}, @samp{:+}, +and @samp{:?}. Their meanings are the same as in regular expressions: +@samp{:*} matches the preceding pattern zero or more times, @samp{:+} +matches one or more times, and @samp{:?} matches zero or one times. For example, the following pattern matches @code{type_declaration} nodes that have @emph{zero or more} @code{long} keywords. @example -(type_declaration "long"*) @@long-type +(type_declaration "long" :*) @@long-type @end example The following pattern matches a type declaration that may or may not have a @code{long} keyword: @example -(type_declaration "long"?) @@long-type +(type_declaration "long" :?) @@long-type @end example @subheading Grouping @@ -1225,15 +1225,14 @@ Pattern Matching express a comma-separated list of identifiers, one could write @example -(identifier) ("," (identifier))* +(identifier) ("," (identifier)) :* @end example @subheading Alternation Again, similar to regular expressions, we can express ``match any one -of these patterns'' in a pattern. The syntax is a list of patterns -enclosed in square brackets. For example, to capture some keywords in -C, the pattern would be +of these patterns'' in a pattern. The syntax is a vector of patterns. +For example, to capture some keywords in C, the pattern would be @example @group @@ -1248,7 +1247,7 @@ Pattern Matching @subheading Anchor -The anchor operator @samp{.} can be used to enforce juxtaposition, +The anchor operator @code{:anchor} can be used to enforce juxtaposition, i.e., to enforce two things to be directly next to each other. The two ``things'' can be two nodes, or a child and the end of its parent. For example, to capture the first child, the last child, or two @@ -1257,19 +1256,19 @@ Pattern Matching @example @group ;; Anchor the child with the end of its parent. -(compound_expression (_) @@last-child .) +(compound_expression (_) @@last-child :anchor) @end group @group ;; Anchor the child with the beginning of its parent. -(compound_expression . (_) @@first-child) +(compound_expression :anchor (_) @@first-child) @end group @group ;; Anchor two adjacent children. (compound_expression (_) @@prev-child - . + :anchor (_) @@next-child) @end group @end example @@ -1285,8 +1284,8 @@ Pattern Matching @example @group ( - (array . (_) @@first (_) @@last .) - (#equal @@first @@last) + (array :anchor (_) @@first (_) @@last :anchor) + (:equal @@first @@last) ) @end group @end example @@ -1294,22 +1293,22 @@ Pattern Matching @noindent tree-sitter only matches arrays where the first element is equal to the last element. To attach a predicate to a pattern, we need to -group them together. A predicate always starts with a @samp{#}. -Currently there are three predicates: @code{#equal}, @code{#match}, -and @code{#pred}. +group them together. Currently there are three predicates: +@code{:equal}, @code{:match}, and @code{:pred}. -@deffn Predicate equal arg1 arg2 +@deffn Predicate :equal arg1 arg2 Matches if @var{arg1} is equal to @var{arg2}. Arguments can be either strings or capture names. Capture names represent the text that the captured node spans in the buffer. @end deffn -@deffn Predicate match regexp capture-name +@deffn Predicate :match regexp capture-name Matches if the text that @var{capture-name}'s node spans in the buffer -matches regular expression @var{regexp}. Matching is case-sensitive. +matches regular expression @var{regexp}, given as a string literal. +Matching is case-sensitive. @end deffn -@deffn Predicate pred fn &rest nodes +@deffn Predicate :pred fn &rest nodes Matches if function @var{fn} returns non-@code{nil} when passed each node in @var{nodes} as arguments. @end deffn @@ -1318,23 +1317,23 @@ Pattern Matching the same pattern. Indeed, it makes little sense to refer to capture names in other patterns. -@heading S-expression patterns +@heading String patterns -@cindex tree-sitter patterns as sexps -@cindex patterns, tree-sitter, in sexp form -Besides strings, Emacs provides an s-expression based syntax for -tree-sitter patterns. It largely resembles the string-based syntax. -For example, the following query +@cindex tree-sitter patterns as strings +@cindex patterns, tree-sitter, in string form +Besides s-expressions, Emacs allows the tree-sitter's native query +syntax to be used by writing them as strings. It largely resembles +the s-expression syntax. For example, the following query @example @group (treesit-query-capture - node "(addition_expression - left: (_) @@left - \"+\" @@plus-sign - right: (_) @@right) @@addition + node '((addition_expression + left: (_) @@left + "+" @@plus-sign + right: (_) @@right) @@addition - [\"return\" \"break\"] @@keyword") + ["return" "break"] @@keyword)) @end group @end example @@ -1344,52 +1343,53 @@ Pattern Matching @example @group (treesit-query-capture - node '((addition_expression - left: (_) @@left - "+" @@plus-sign - right: (_) @@right) @@addition + node "(addition_expression + left: (_) @@left + \"+\" @@plus-sign + right: (_) @@right) @@addition - ["return" "break"] @@keyword)) + [\"return\" \"break\"] @@keyword") @end group @end example -Most patterns can be written directly as strange but nevertheless -valid s-expressions. Only a few of them need modification: +Most patterns can be written directly as s-expressions inside a string. +Only a few of them need modification: @itemize @item -Anchor @samp{.} is written as @code{:anchor}. +Anchor @code{:anchor} is written as @samp{.}. @item -@samp{?} is written as @samp{:?}. +@samp{:?} is written as @samp{?}. @item -@samp{*} is written as @samp{:*}. +@samp{:*} is written as @samp{*}. @item -@samp{+} is written as @samp{:+}. +@samp{:+} is written as @samp{+}. @item -@code{#equal} is written as @code{:equal}. In general, predicates -change their @samp{#} to @samp{:}. +@code{:equal}, @code{:match} and @code{:pred} are written as +@code{#equal}, @code{#match} and @code{#pred}, respectively. +In general, predicates change their @samp{:} to @samp{#}. @end itemize For example, @example @group -"( - (compound_expression . (_) @@first (_)* @@rest) - (#match \"love\" @@first) - )" +'(( + (compound_expression :anchor (_) @@first (_) :* @@rest) + (:match "love" @@first) + )) @end group @end example @noindent -is written in s-expression syntax as +is written in string form as @example @group -'(( - (compound_expression :anchor (_) @@first (_) :* @@rest) - (:match "love" @@first) - )) +"( + (compound_expression . (_) @@first (_)* @@rest) + (#match \"love\" @@first) + )" @end group @end example @@ -1413,7 +1413,7 @@ Pattern Matching @end defun @defun treesit-query-language query -This function return the language of @var{query}. +This function returns the language of @var{query}. @end defun @defun treesit-query-expand query @@ -1605,7 +1605,7 @@ Multiple Languages (setq css-range (treesit-query-range 'html - "(style_element (raw_text) @@capture)")) + '((style_element (raw_text) @@capture)))) (treesit-parser-set-included-ranges css css-range) @end group @@ -1614,7 +1614,7 @@ Multiple Languages (setq js-range (treesit-query-range 'html - "(script_element (raw_text) @@capture)")) + '((script_element (raw_text) @@capture)))) (treesit-parser-set-included-ranges js js-range) @end group @end example --Apple-Mail=_2A1B46EA-512E-4800-91B8-8FDDF623A06A-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 18:55:48 2023 Received: (at 64017) by debbugs.gnu.org; 17 Jun 2023 22:55:48 +0000 Received: from localhost ([127.0.0.1]:52786 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAepg-00068i-Fs for submit@debbugs.gnu.org; Sat, 17 Jun 2023 18:55:48 -0400 Received: from mail-ot1-f47.google.com ([209.85.210.47]:51435) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAepb-00068S-HY for 64017@debbugs.gnu.org; Sat, 17 Jun 2023 18:55:47 -0400 Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-6b291d55f52so1649026a34.2 for <64017@debbugs.gnu.org>; Sat, 17 Jun 2023 15:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687042538; x=1689634538; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=zsjyqF4MZcsV4OgwWviHiDtUlMA2s5X1nrzTCVLR87E=; b=LSp9ERr0ZK0l+tigOQVjePxUSN1d89FxaAi5tfOzWcyaj3EUGLx9QQQMRXuGTU4CsR aCKvz4NtBiMyuAXBFs+ECCzecbGpMudEzIMpIJS88KQ30H0dP4hNQCSlarlOWd6CZNQW kXiv6LVUQp8eTTUcAJRYMAqOHEkig1nmrC4oZ83ErQBuCSBy2JgV43vGEsmfjCI7+M/j 58+ll2nSab04Wc/MLwd631VrVB93YkFx4PzVMXleOmJml/ZuDsP5qhQH+EB8es2C6nUU sD88f3HtSFq4jlb069naJEodzFBRWSLQKwF1TbtJEJxRnOz2HQWj3b+C/n1NfetBN1qJ Kx8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687042538; x=1689634538; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zsjyqF4MZcsV4OgwWviHiDtUlMA2s5X1nrzTCVLR87E=; b=em7kx3XO//zi2NCGWbhQk1kDJpPqueIQ191Jtbc7Za+202ATBCDo+5a73tH8/GonfB bWNcxfGy/bqj7SUPWEMBZlP3xs2/XsivFVb9nwKqkTS/w+4lvZlXQTgE8ucDZWva6ys0 qhapFBhVDZ5BKYFdNGSqYea8QRFWL1fJFH3tBa6rz2dRb0JT3TuX8vuXTNyINGiXbHSC 8dr1h/T7s8VRLgmu6FbMa36eui/dwBGux7OK2bxrNhsOA/gWiaOlsjCzj65NNZx2I2pz mkQM4yJ1sA/rUyl+lQ8igVyTLX9GdAZly4o2jKaIRvqUSHCfEQZ/REKMeKGR+BWyK8l/ GISA== X-Gm-Message-State: AC+VfDzExym9kJT8VzBE2p0A2Bo6AJFVxttP0XROwz3E8XPiIo6f/AxX zeYcrkv2yN9VB1aGaYVwPa8= X-Google-Smtp-Source: ACHHUZ4L98WTA3gXusEkkzKF/bHS1Kq+olzep6Z7DJ4uXRkDFDAnUqtGF+gygbyIxK+XZPLUzjP1Yg== X-Received: by 2002:a05:6358:e930:b0:12f:2690:845d with SMTP id gk48-20020a056358e93000b0012f2690845dmr2478476rwb.6.1687042537616; Sat, 17 Jun 2023 15:55:37 -0700 (PDT) Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id l6-20020a170902d34600b001ab01598f40sm6223253plk.173.2023.06.17.15.55.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Jun 2023 15:55:37 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Subject: Re: bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax From: Yuan Fu In-Reply-To: <67D3CF20-8641-4BF6-A102-037591B6E821@gmail.com> Date: Sat, 17 Jun 2023 15:55:25 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> <04C45D03-D49B-4DE4-AD26-2606C94AF260@gmail.com> <87r0qb1fdj.fsf@epfl.ch> <078740D5-8AA0-47B5-A34D-6E5C3E0C34B3@gmail.com> <83bkheqmal.fsf@gnu.org> <67D3CF20-8641-4BF6-A102-037591B6E821@gmail.com> To: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= X-Mailer: Apple Mail (2.3731.600.7) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 64017 Cc: Basil Contovounesios , Eli Zaretskii , 64017@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On Jun 17, 2023, at 6:30 AM, Mattias Engdeg=C3=A5rd = wrote: >=20 > 17 juni 2023 kl. 14.57 skrev Eli Zaretskii : >=20 >>> Will do, thank you. Since this is only about documentation, perhaps = it could be done in emacs-29? >>> Eli, would that be acceptable? >>=20 >> If Yuan doesn't mind, yes. But I'd like to hear from Yuan that he is >> okay with these changes. >=20 > Attached are the changes rebased to emacs-29 (fixing mistakes found by = Basil). >=20 > LGTM! Yuan= From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 17 19:03:15 2023 Received: (at submit) by debbugs.gnu.org; 17 Jun 2023 23:03:15 +0000 Received: from localhost ([127.0.0.1]:52790 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAewt-0006Ks-G3 for submit@debbugs.gnu.org; Sat, 17 Jun 2023 19:03:15 -0400 Received: from lists.gnu.org ([209.51.188.17]:37136) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAewq-0006Kk-Q8 for submit@debbugs.gnu.org; Sat, 17 Jun 2023 19:03:14 -0400 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 1qAewq-00037e-Jj for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 19:03:12 -0400 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qAewo-00072q-VV for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2023 19:03:12 -0400 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6b46831fd13so278273a34.3 for ; Sat, 17 Jun 2023 16:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687042990; x=1689634990; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5RddoXXl6F28VWQozBCKEL4+0F4WlwIQBf4ncVt/LaU=; b=RmEJiPnNH1vcp/d25ekUo/IlJ98EIxLqI9vrKgxI7QFc/xOpFyptzUMPL3PxEbQp0j ZACVseq2xYNA2frnuhDcNeRhb9gs6j1OzS+GbNlIG/2X4y1Y4gABWetjL4w9N/Jh/PLI dM6ZrUiu7M4hXSu2xMGwQ1V4OkJVCYCwrZrTLRJbI1leV3u4hk1rvTpVniuUblDfTMw6 //XvuJsWZxmhy8kLIPSgRXw+atK4NzvdH7Hs6iYpbGuABTvETX5MyeMWRh1BTdrxD8IR qijt/CSrcB5azrBLc49eH8y6ZsKaLz8zKsj+JlWlJ3TZCrs9BJfONCTql+Lj600H/dUH jzAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687042990; x=1689634990; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5RddoXXl6F28VWQozBCKEL4+0F4WlwIQBf4ncVt/LaU=; b=j4v1ejvUMT+Y9CHl+1TJZK6Mx9Wh+zAbSo7yB9mT0PmPziKU7wrVYAl2FA+8KCheSA 5nipJQIMlU9cWqS9h59Uq17m9FcldiB8F4D+R6PlkdWr3YiOZ69XHojPPTgiIxt9UL/8 QxrKx4GUNTzDOjPr5plORJFQorpi+aGTExZJskwaL5SkB8N4M3Zfzj5+kSdvplXnr3Ub XaGatyw7r7dbmyfK1SLpG2KXnKWGrzzfsBrKLVQMp6x1Ndk4S3RVwjrwDUqZ+UKtoTYT B6ewjAQRFlN/jBGx0D6AwwxeqvrBY80lJU0Tvu/3gNX2fcsl+mO+UNNsU9CytKrDL5D8 ZWig== X-Gm-Message-State: AC+VfDx1Qq2v5miVmSZ3K8EuHjdmx76vywdrjGpfCOFaZ0JKoPG168oD ZGr23Jlr+QkMMNtry/ntvBI= X-Google-Smtp-Source: ACHHUZ4TNkSl+N03cLdfGg0EYd9nZWhszDCWrJBumYvK5YKhkhzGpr9liwEBZXiZijJm5a48tbjoCA== X-Received: by 2002:a05:6359:203:b0:123:3cc5:e6be with SMTP id ej3-20020a056359020300b001233cc5e6bemr3470022rwb.9.1687042989628; Sat, 17 Jun 2023 16:03:09 -0700 (PDT) Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id k5-20020a170902ba8500b001ae5fe602c3sm17944555pls.159.2023.06.17.16.03.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Jun 2023 16:03:09 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Subject: Re: Wrong conversion from Emacs to Tree-sitter S-expression syntax From: Yuan Fu In-Reply-To: <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> Date: Sat, 17 Jun 2023 16:02:58 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> To: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= X-Mailer: Apple Mail (2.3731.600.7) Received-SPF: pass client-ip=2607:f8b0:4864:20::32b; envelope-from=casouri@gmail.com; helo=mail-ot1-x32b.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-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: Basil Contovounesios , Bug Report Emacs X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) >=20 > Yes, so it seemed to me but reading the source code (lib/src/query.c) = seems to indicate that what I thought were symbols -- *, +, ?, @thing, = #thing -- appear to be special postfix and prefix operators. = (Ironically, there doesn't seem to be a grammar for this language = anywhere, or am I mistaken?) >=20 > Thus a structurally correct Lispish translation of >=20 > (teet "toot"* (#equal "fie" @fum)) >=20 > should arguable be something like >=20 > (teet (* "toot") ((# equal) "fie" (@ fum))) >=20 > rather than the current >=20 > (teet "toot" :* (:equal "fie @fum)) >=20 > but I'm not demanding that it all be changed at this stage. IMHO the query syntax is already pretty far away from a =E2=80=9Cproper = sexp=E2=80=9D that we expect, so changing these little things don=E2=80=99= t have much benefit. For example, the field names and trailing capture = names are not conventional, are we going to change them to be more sexpy = too?=20 In a proper sexp they would have been wrapped too, like (field-name: node) rather than field-name: node (@fn node) rather than node @fn Not to mention using colon and @ to distinguish field-names and capture = names from nodes=E2=80=94not very conventional either. Also a more conventional sexp syntax would be much more verbose than the = current one, and arguable harder to translate to the tree-sitter string = syntax, which is ultimately what we feed to tree-sitter functions. Yuan= From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 18 04:47:11 2023 Received: (at 64017-done) by debbugs.gnu.org; 18 Jun 2023 08:47:11 +0000 Received: from localhost ([127.0.0.1]:53151 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAo3z-000539-8C for submit@debbugs.gnu.org; Sun, 18 Jun 2023 04:47:11 -0400 Received: from mail-lj1-f178.google.com ([209.85.208.178]:51402) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAo3w-00052v-EK for 64017-done@debbugs.gnu.org; Sun, 18 Jun 2023 04:47:09 -0400 Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2b4725e9917so4701541fa.2 for <64017-done@debbugs.gnu.org>; Sun, 18 Jun 2023 01:47:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687078022; x=1689670022; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=lxRUmjJl1SmJrPSN7NfWTrBznX8miUk7NS8fXoSnRe8=; b=sfgMeq/O9/QxsezlPGKS3EhyC+KW/ZIRKHL1cWUSqOYH8Hr9SU+ZNnGhtB4vUp+wNg HsovpidJ6jrk72VltlofLTqhQH+hbfzr/q+NHHQw+ZUIgadSsT73vePX+oymYCpupyI0 JLYg/9+XFBWhwYUafnl8t1Z2OfmsAk5XiVLmDx8WorfTuZAdifNTzXRzf+zcZIylIltX Pede+YStYlAarhPL51CKQJRbr7kHvPBfdpNuMp297BDsMHcEmfUnx12k5UxnNSgs2hQh /4xJe7Beki1hOw2LY8PTyA7ricPRhxOpRYWjTcK40B4nemDD7AhGDf1xZKuivsqE+OKn Qjyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687078022; x=1689670022; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lxRUmjJl1SmJrPSN7NfWTrBznX8miUk7NS8fXoSnRe8=; b=B3mddvYqEPoCI4/7dVYPjIAVbWhcmTfH+X7LkldcmD0tQozfAOksyqVvFn05lwnLzQ hda0FdKx4OGRcwq1dxyrdQHuvwDvLYziW7+7Hhklxq4vB+nsLHyxVXaZVyzyEFSEI5/H TCSC8PSxkKarjaDZ+/Ar4pbnTHM13LfgkITdpmEmfouuBLmZkXyAZsuK5tNcRWoL3b5g 28FHRxA8L5VG0QmTn+mBHLgSRknlEKPpGAohI3Z/6BpX6NmsnCCnzwYK6lkOuCZYOHcx 1DDr2if77v+zRqCCu21abQr4wzyQOhY49c2bNCfjGC0FYveVl92629VLHin4cI0SVuAi jvFg== X-Gm-Message-State: AC+VfDzG306HPA+zJ1i+Ecfi9mz5eWIF05umylDhFSpqr5CA/sALgLlX cPrG6ZzKpau/BBsU6/Zh6WQ= X-Google-Smtp-Source: ACHHUZ6hoUt3TD+xWebp63fQG1gICW0UYz0qO4m8OrS9aETvm1qRriGRpdZB3ciJxI+LmiQ44jxmdA== X-Received: by 2002:a2e:80d0:0:b0:2b3:33b9:e998 with SMTP id r16-20020a2e80d0000000b002b333b9e998mr4094070ljg.7.1687078022157; Sun, 18 Jun 2023 01:47:02 -0700 (PDT) Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id t10-20020a2e2d0a000000b002adb566dc10sm4578478ljt.129.2023.06.18.01.47.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Jun 2023 01:47:01 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Subject: Re: bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= In-Reply-To: Date: Sun, 18 Jun 2023 10:47:01 +0200 Content-Transfer-Encoding: 7bit Message-Id: <731A0E4C-3775-4202-98FD-E1C1ACD4D3EF@gmail.com> References: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com> <0CBD145C-0A92-4258-A5F3-6FC616E89ED8@gmail.com> <04C45D03-D49B-4DE4-AD26-2606C94AF260@gmail.com> <87r0qb1fdj.fsf@epfl.ch> <078740D5-8AA0-47B5-A34D-6E5C3E0C34B3@gmail.com> <83bkheqmal.fsf@gnu.org> <67D3CF20-8641-4BF6-A102-037591B6E821@gmail.com> To: Yuan Fu X-Mailer: Apple Mail (2.3654.120.0.1.15) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 64017-done Cc: Basil Contovounesios , Eli Zaretskii , 64017-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 18 juni 2023 kl. 00.55 skrev Yuan Fu : > LGTM! Thank you, these changes are now in emacs-29. And we are done, closing the bug. From unknown Sun Aug 17 22:09:26 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 16 Jul 2023 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator