unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: haj@posteo.de (Harald Jörg)
To: "Clément Pit-Claudel" <cpitclaudel@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Handling extensions of programming languages
Date: Sun, 21 Mar 2021 12:41:26 +0100	[thread overview]
Message-ID: <87h7l43fa1.fsf@hajtower> (raw)
In-Reply-To: <20a4ef1c-beaf-1d63-b984-12be9a856c86@gmail.com> ("Clément Pit-Claudel"'s message of "Sat, 20 Mar 2021 22:18:00 -0400")

Clément Pit-Claudel <cpitclaudel@gmail.com> writes:

> On 3/20/21 7:40 PM, Harald Jörg wrote:
>> 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?

I admit that I don't know much about SMIE, so maybe I'm wrong here.
Most of Perl is pretty similar to C or Java, but there are cases where
Perl's syntax just can't be parsed statically.

About the relation to font-lock-add-keywords - let me show an example.
"Traditional" Perl has no keywords for object oriented programming, but
there are dozens of extensions which add them.  For example, with
Object::Pad you can write (I apologize for the nonsensical example):

  class Coffee::Machine extends Lawn::Mower
  {
     has $grinder :reader :writer(replace_grinder)
     method grind { ...; }
  } 

If I want to support that with CPerl mode, I need to:

 - highlight class, extends, method and some more I haven't included in
   that example as keywords.  That's where font-lock-add-keywords comes
   into play.  Also, "Dishwasher" and "clean_up" should be highlighted
   like package and sub names.

 - add "Dishwasher" and "clean_up" to the imenu index.
 
 - 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.

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.

If, however, that same class would be defined using the Dios extension,
it would look like this:

  class Coffee::Machine is Lawn::Mower
  {
     has $.grinder is rw
     method grind { ... }
  } 

...and also offer the keywords "func" and "submethod" for stuff that
should go into imenu, and "lex" for declaring variables.  There's a
dozen or more other extensions providing OO frameworks for Perl.

So, if the Emacs support for an extension could be done by a separate
.el file, these could be developed within GNU Emacs, in GNU ELPA, but
also contributed via NonGNU elpa, MELPA or GitHub.

I am aware that probably as soon as such an extension mechanism is
available, _someone_ will publish a Perl extension which can't be
covered :)
-- 
Cheers,
haj



  reply	other threads:[~2021-03-21 11:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-19 18:53 Handling extensions of programming languages Harald Jörg
2021-03-20 17:02 ` Matt Armstrong
2021-03-20 23:40   ` Harald Jörg
2021-03-21  2:18     ` Clément Pit-Claudel
2021-03-21 11:41       ` Harald Jörg [this message]
2021-03-21 12:39         ` Stefan Monnier
2021-03-21 15:48           ` Harald Jörg
2021-03-21 17:59             ` Stefan Monnier
2021-03-22 14:08               ` Handling extensions of programming languages (Perl) Harald Jörg
2021-03-22 14:48                 ` Stefan Monnier
2021-03-22 17:32                   ` Harald Jörg
2021-03-22 18:27                     ` Stefan Monnier
2021-03-22 19:31                       ` Harald Jörg
2021-03-22 19:58                         ` [OFFTOPIC] " Stefan Monnier
2021-03-22 22:05                           ` Harald Jörg
2021-03-22 22:24                             ` Stefan Monnier
2021-03-22 23:43                               ` Harald Jörg
2021-03-23  3:49                                 ` [OFFTOPIC] " Stefan Monnier
2021-03-30 18:41             ` Handling extensions of programming languages Stephen Leake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h7l43fa1.fsf@hajtower \
    --to=haj@posteo.de \
    --cc=cpitclaudel@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).