[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Handling extensions of programming languages
From: |
Harald Jörg |
Subject: |
Re: Handling extensions of programming languages |
Date: |
Sun, 21 Mar 2021 12:41:26 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
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
- Handling extensions of programming languages, Harald Jörg, 2021/03/19
- Re: Handling extensions of programming languages, Matt Armstrong, 2021/03/20
- Re: Handling extensions of programming languages, Harald Jörg, 2021/03/20
- Re: Handling extensions of programming languages, Clément Pit-Claudel, 2021/03/20
- Re: Handling extensions of programming languages,
Harald Jörg <=
- Re: Handling extensions of programming languages, Stefan Monnier, 2021/03/21
- Re: Handling extensions of programming languages, Harald Jörg, 2021/03/21
- Re: Handling extensions of programming languages, Stefan Monnier, 2021/03/21
- Re: Handling extensions of programming languages (Perl), Harald Jörg, 2021/03/22
- Re: Handling extensions of programming languages (Perl), Stefan Monnier, 2021/03/22
- Re: Handling extensions of programming languages (Perl), Harald Jörg, 2021/03/22
- Re: Handling extensions of programming languages (Perl), Stefan Monnier, 2021/03/22
- Re: Handling extensions of programming languages (Perl), Harald Jörg, 2021/03/22
- [OFFTOPIC] Re: Handling extensions of programming languages (Perl), Stefan Monnier, 2021/03/22
- Re: [OFFTOPIC] Re: Handling extensions of programming languages (Perl), Harald Jörg, 2021/03/22