Skip to content

Conversation

@b4n
Copy link
Contributor

@b4n b4n commented Dec 27, 2025

Fixes #342.


DISCLAIMER: I don't know Perl, but this seems to be consistent with the lexer, and seems to work. The docs seem to support the report this fix is for.

@b4n
Copy link
Contributor Author

b4n commented Dec 27, 2025

Wait, I made a blunder it seems, fixing a mistake, hold on

@b4n
Copy link
Contributor Author

b4n commented Dec 27, 2025

OK, no, the code is fine but only works if method is styled as a keyword (so is in the properties list). That's the same for sub, so it should be fine, but… adding it to the properties actually breaks/changes styling of the following:

-{11}lvalue{0} {11}method{0} {5}prototype{10}(..){0} {11}locked{0} {11}const{0}
+{11}lvalue{0} {5}method{0} {11}prototype{10}(..){0} {11}locked{0} {11}const{0}

so maybe there's more to it than this, and I'm in over my head given I have no idea what this line above means (I mean, the Perl version lvalue method prototype(..) locked const).

@b4n b4n marked this pull request as draft December 27, 2025 12:37
@zufuliu
Copy link
Contributor

zufuliu commented Dec 27, 2025

It seems class, method and field are context/soft like keywords (not listed on https://learn.perl.org/docs/keywords.html):

https://perldoc.perl.org/perlclass

=head1 NAME

perlclass - Perl class syntax reference

=head1 SYNOPSIS

use v5.38;
use feature 'class';

class My::Example 1.234 {
    field $x;

    ADJUST {
        $x = "Hello, world";
    }

    method print_message {
        say $x;
    }
}

My::Example->new->print_message;

=head1 DESCRIPTION

@b4n b4n marked this pull request as ready for review December 27, 2025 13:54
@b4n
Copy link
Contributor Author

b4n commented Dec 27, 2025

OK I adjusted the special handling to allow for SCE_PL_IDENTIFIER as well as SCE_PL_WORD and it seems to work fine without breaking the tests. So I pushed an updated version including a test for this.
Testing is welcome, but that seems OK now.

@b4n
Copy link
Contributor Author

b4n commented Dec 27, 2025

Seeing https://sourceforge.net/p/scintilla/feature-requests/1574/ adds method as a keyword, maybe somebody with more Perl knowledge should really look at this, because as-is it will prevent prototype from being styled as a keyword after method, like in lvalue method prototype(..) locked const (see above). So it might really need special softness handling.

@nyamatongwe nyamatongwe added the perl Caused by the Perl lexer label Dec 27, 2025
@nyamatongwe
Copy link
Member

The line lvalue method prototype(..) locked const appears to just be checking if function attributes have been specified as keywords, not an example of real use. Attributes may appear inside function declarations after a : as discussed at perlsub.
https://perldoc.perl.org/perlsub
https://perldoc.perl.org/attributes
https://users.softlab.ntua.gr/~sivann/books/OReilly%20Bookshelf/perl/prog/ch06_05.htm

Examples:

sub foo : method ;
sub Y::x : lvalue { 1 }
sub foo($$) : prototype(@) {}
*INLINED = sub : const { $x };

# Only one thread is allowed into this function on a given object.
sub afunc : locked method { ... }

For the class.pl example to lex well (style 5=word instead of 11=identifier), method and class should be included in the keywords inside SciTE.properties. Perhaps just copy the keywords from SciTE as that appears to have been done initially.

@b4n
Copy link
Contributor Author

b4n commented Dec 28, 2025

Okay so if adding method as a keyword changes other tests' result it might not be an issue? Here my concern was mostly that it changed which keyword was actually highlighted as such (see above). If that's all fine then it's easier and only the tests need adjusting.

@b4n
Copy link
Contributor Author

b4n commented Dec 29, 2025

OK so I just added a commit before that updated the keywords, and the tests that got different results for this (e.g. some identifiers becoming keywords).

Second commit now has better styles, but again the prototype is not a keyword anymore in lvalue method prototype(..) locked const. If that's fine, then this is ready I guess.

nyamatongwe pushed a commit that referenced this pull request Dec 29, 2025
This will be useful for an upcoming test.
@nyamatongwe nyamatongwe added the committed Issue fixed in repository but not in release label Dec 29, 2025
@nyamatongwe
Copy link
Member

Contextual keywords are difficult. While it would be great to recognize contextual keywords exactly like the Perl interpreter, that would require much more work. It is still worth improving the set of cases that are recognized correctly, prioritizing cases that are likely more common like method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

committed Issue fixed in repository but not in release perl Caused by the Perl lexer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LexPerl needs to treat method same as sub

3 participants