From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Handling extensions of programming languages Date: Sun, 21 Mar 2021 08:39:12 -0400 Message-ID: References: <87o8ff560t.fsf@hajtower> <87im5lhi6i.fsf@rfc20.org> <87r1k94cnx.fsf@hajtower> <20a4ef1c-beaf-1d63-b984-12be9a856c86@gmail.com> <87h7l43fa1.fsf@hajtower> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38755"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: =?windows-1252?Q?Cl=E9ment?= Pit-Claudel , emacs-devel@gnu.org To: haj@posteo.de (Harald =?windows-1252?Q?J=F6rg?=) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Mar 21 13:40:44 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lNxNs-0009zJ-6R for ged-emacs-devel@m.gmane-mx.org; Sun, 21 Mar 2021 13:40:44 +0100 Original-Received: from localhost ([::1]:55940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNxNr-0005jJ-7d for ged-emacs-devel@m.gmane-mx.org; Sun, 21 Mar 2021 08:40:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNxMb-0005GK-77 for emacs-devel@gnu.org; Sun, 21 Mar 2021 08:39:25 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:33516) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNxMX-0001BX-6D for emacs-devel@gnu.org; Sun, 21 Mar 2021 08:39:24 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 9D7E680A74; Sun, 21 Mar 2021 08:39:19 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id EB62A8024F; Sun, 21 Mar 2021 08:39:13 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1616330354; bh=pxahbMiHKcK+nU6QZEth5YcC1sajtgiGnGugpo5ymU4=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=nNMYykFbj50lmSy9soWIeqaF1njgrTFDxDAS29gPPDWq3Puu+0a4YXblkiguJM1wr sxDY131JHWGdWtHdMM5gLW87oG7Q/Ag9w8N2plmKiUUM4N5oq1C4gQafWwuweiWdFq HP25/HczevJkrBZCS+LqA9CodRf4Xamtam45p4pqFubODWcnbaurCiaRczzjJ6B6mo Ndqjj/zfqhvGuy1xtXDOgARl7OmEDJCy5ff31DBonhZS0mC5PN4YGYe8AWTbP82rI4 dmjkW7/vrah2P/LBjFl7MXSOqlPunqJalL2icur1n4Rp14zGQ2DhKvCCnUq+L+IzL+ wo5wkEOR1v84g== Original-Received: from alfajor (unknown [216.154.43.249]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 9E4451200B8; Sun, 21 Mar 2021 08:39:13 -0400 (EDT) In-Reply-To: <87h7l43fa1.fsf@hajtower> ("Harald =?windows-1252?Q?J=F6rg=22?= =?windows-1252?Q?'s?= message of "Sun, 21 Mar 2021 12:41:26 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:266701 Archived-At: >>> Well, I have my doubts that Perl is a good candidate for SMIE, and >>> trying to use SMIE in CPerl mode would be a major rewrite anyway. I >>> guess the Emacs Losp basics (font-lock-add-keyword, hooks) will have to >>> do the job. >> >> I'm pretty sure SMIE would work wonderfully for Perl, but I'm also not >> sure how it relates to font-lock-add-keywords and hooks, so maybe >> we're not thinking of the same thing? FWIW, I'm sure SMIE could be made to work, but I highly doubt it would "work wonderfully" in the sense that it would likely take a fair bit of effort to make SMIE indent Perl mode as well as the current indentation code in `cperl-mode` or in `perl-mode`. > class Coffee::Machine extends Lawn::Mower > { > has $grinder :reader :writer(replace_grinder) > method grind { ...; } > } [...] > - add "Dishwasher" and "clean_up" to the imenu index. That seems to require AI (unless you're talking about a slightly different example than the one quoted above ;-). > - make sure that indentation recognizes that the closing braces end a > statement after "class" and "method". Perl syntax has various cases > where it doesn't. I guess this is the part where SMIE would help. Actually, the closing brace which also closes a statement is one of the major pain points in `sm-c-mode`, so it would be one of the parts where you'd need extra work to make SMIE understand what's going on. > For the latter two tasks, I need to "hook" the logic somehow into > CPerl's implementations of `imenu-create-index-function' and the various > indentation functions. The current indentation code in CPerl mode > is... a bit messy, and some old bugs call for attention anyway. AFAIK font-lock and imenu are easy. For font-lock there's `font-lock-add-keywords` and for imenu, you should be able to make it work fairly well with just `add-function` to `imenu-create-index-function`. For indentation, it's fundamentally harder (for the same reason that combining two LALR grammars doesn't necessarily give you an LALR grammar), so it will have to be done in a somewhat ad-hoc way. I suspect that if the base mode uses SMIE, it would make it significantly easier to add extensions (because the structure of SMIE imposes constraints that expose the "compositional" aspect of the grammar, in some sense), but that's not what you have to work with currently, so you're going to have to dig into the indentation code and try and figure out how to make it work with your extension(s) and then how to express the changes "from outside" (e.g. by using hooks, `add-function`, or `advice-add`; we can of course add hooks to `cperl-mode.el` or `perl-mode.el` to make that easier). Stefan