Sublime Forum

Perl Syntax: Single quote package delimiter not supported

#1

I know it’s not the preferred way of doing it anymore, and it’s probably a hassle to parse, but Perl supports a single quote as a package delimiter which is being incorrectly identified as the start of a string in ST’s syntax highlighting. This feature is mentioned specifically in the perl docs in the second paragraph here: perldoc.perl.org/perlmod.html#Packages

I figure this will end up being a “won’t fix” issue, but I figured I’d mention it. My company has code with this delimiter in it all over the place, and it’s a hassle looking at huge chunks of code that lack syntax highlighting because ST thinks it’s all a string.

0 Likes

#2

There are also highlight problem with:

   $nocache =  $nocache ? "?nocache=$nocache" : "" ;
0 Likes

#3

oof, this will be very difficult to parse out.

Not having syntax highlighting is miserable, so I’ll give it a shot for ya.

Edit: Not as hard as I expected, as it turns out. See my github repo (link below).

0 Likes

#4

nick you are the man! That’s so much better. There are still a few quirks though. It looks like it’s only operating on scalars, whereas we have instances of arrays and hashes that are referenced in packages as well. So for instance:

$myPackage'myScalar = 12;
@myPackage'myArray = ();
%myPackage'myHash = ();

The first instance will be detected properly, whereas the following two are not. So I extended your plain array handling regex to this:

@[A-Za-z0-9_]+(('|::)[A-Za-z0-9_]+)*

Which seems to do the trick. I’m not comfortable submitting a pull request, or extending this to other cases (in braces, from scalar), because honestly I’m not a perl expert and I’m not familiar at all with ST’s custom parsing functionality, but that should give you a decent idea of what’s currently lacking if you want to improve it somewhat.

0 Likes

#5

@eogas, I made a small change which adds support for using arrays and hashes as packages. Let me know if you come across any other bugs.

0 Likes

#6

Looks good. I do have a regular expression that’s “leaking”, but I pulled an old version (before the single quote changes), and confirmed that it’s an existing issue. I’ll see if I can identify what exactly is causing that expression to not be identified correctly, but as far as the single quote stuff, it all seems to be good.

On the regex issue, is it best to keep responding here, or should I just submit an issue on your repo?

0 Likes

#7

I check these forum pretty frequently, but to keep things organized go ahead and open an issue in the repo. If you can provide the regex, that’d be best. I understand that may be private information, so no worries if you can’t.

0 Likes

#8

Cool, I went ahead and submitted an issue.

0 Likes