Skip to content

Conversation

@wesQ3
Copy link
Contributor

@wesQ3 wesQ3 commented Jun 24, 2025

In Perl 5.26+, the regex quotelike operator accepts a second x modifier to allow whitespace inside of character classes. This can improve readability of complex character classes.

perl.tmLanguage.json (including upstream VScode/Textmate) does not parse extended regex with /xx correctly when broken across multiple lines.

# single line is ok
my $single = $foo =~ s/[ \N{NO-BREAK SPACE} \r \n {} " ]/ /grxx;
# multi-line highlights ok without second x
# this is syntactically invalid but useful for comparison
my $multi  = $foo =~ s/[
        \N{NO-BREAK SPACE}
        \r \n
        {}
        "
        ]/ /grx;
# multi line extended breaks when second x is added
my $multi_xx  = $foo =~ s/[
        \N{NO-BREAK SPACE}
        \r \n
        {}
        "
        ]/ /grxx;
# rest of file is now broken because of the second x

A simple adjustment to the extended regex 'end' condition to allow the second x fixes the parsing error.

I'll try to submit this to upstream Textmate as well but there doesn't seem to be much movement on their perl syntax project.

End patterns now allow the second 'x' to use extended regex with
whitespace in character classes.

See https://perldoc.perl.org/perlre#/x-and-/xx
@oalders
Copy link
Contributor

oalders commented Jun 25, 2025

I'll try to submit this to upstream Textmate as well but there doesn't seem to be much movement on their perl syntax project.

It's helpful that you did though, since (I believe) that's what GitHub uses for its syntax highlighting.

@wesQ3
Copy link
Contributor Author

wesQ3 commented Jun 25, 2025

Yes, isn't it convenient that we can demonstrate the functionality right here in a Github comment. 😃

Upstream issue submitted as textmate/perl.tmbundle#55

@bscan bscan merged commit 16deddb into bscan:main Jun 25, 2025
@bscan
Copy link
Owner

bscan commented Jun 25, 2025

Thanks @wesQ3! That's a great fix. Syntax highlighting is important, and ones that break the remainder of the document are very frustrating.

The Textmate repo is no longer maintainted. Vscode and Github are generally moving away from it and looking for other upstream repos. See microsoft/vscode#203212 for example. The upstreams for Github are listed here: https://github.com/github-linguist/linguist/blob/main/vendor/README.md

It would be great if this repo becomes the upstream for the Perl grammar for both vscode and github. Most of the open bugs on the textMate repo have already been addressed. See this example script demonstrating a wide variety of fixes with links to the Textmate issue: https://github.com/bscan/PerlNavigator/blob/main/testWorkspace/syntaxHighlighting.pl

The main open question I have is regarding the dynamic syntax in Perl (e.g. feature 'class', async/await, say, try/catch, etc). Support for these are added by checking import statements and dynamically adding textmate scopes: https://github.com/bscan/PerlNavigator/tree/main/syntaxes . I'm not sure if vscode would want to add all of these files. Perhaps they'd want all of these merged into a single file, or left only in this repo.

@rabbiveesh
Copy link
Contributor

rabbiveesh commented Jun 25, 2025 via email

@wesQ3
Copy link
Contributor Author

wesQ3 commented Jun 25, 2025

microsoft/vscode#203212 lists Perl as

Perl: We're not trying to find a new grammar here, but there aren't many complaints about it.

But I didn't even consider logging my issue with vscode, since other GH syntax issues are referred upstream (and the syntax file itself points upstream). 🤔

I see that github-linguist uses the official Perl6 project's syntax file for Raku. If you would like to pursue making your updated syntax file the upstream, I think a good first step would be to contact the Perl org and see if the syntax files can be adopted as a community repo at https://github.com/Perl.

@wesQ3
Copy link
Contributor Author

wesQ3 commented Jul 17, 2025

@bscan Do you know when the next release of the extension on the VS Marketplace will be?

@bscan
Copy link
Owner

bscan commented Jul 30, 2025

Hi @wesQ3, thanks for your patience on this one, I had fallen a bit behind on pushing new versions. However,I just added version 0.8.18 to the vscode marketplace, and it contains this fix. Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants