Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(perl) add support for the new class system #3856

Merged
merged 6 commits into from
Oct 27, 2023

Conversation

bmeneg
Copy link
Contributor

@bmeneg bmeneg commented Sep 4, 2023

This PR brings the highlight support for the new Perl class system (Cor) by adding the keywords class, method and field and their supported additional features, like attributes and version number.

For getting it done, the regex for matching numbers were reworked because floating points were not fully supported alongside the use of _ in between number digits.

Resolves #3855

src/languages/perl.js Outdated Show resolved Hide resolved
src/languages/perl.js Outdated Show resolved Hide resolved
src/languages/perl.js Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Sep 9, 2023

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

2 files changed

Total change +205 B

View Changes
file base pr diff
es/languages/perl.min.js 1.87 KB 1.98 KB +102 B
languages/perl.min.js 1.87 KB 1.98 KB +103 B

@bmeneg bmeneg force-pushed the perl-class branch 2 times, most recently from f537618 to ad0ea73 Compare September 11, 2023 20:05
<span class="hljs-keyword">field</span> $_name<span class="hljs-attribute"> : param</span> = <span class="hljs-string">&#x27;Test&#x27;</span>;

<span class="hljs-function"><span class="hljs-keyword">method</span> <span class="hljs-title">test</span>() </span>{
$_name == <span class="hljs-string">&#x27;Test&#x27;</span> ? <span class="hljs-string">&#x27;y&#x27;</span> : <span class="hljs-string">&#x27;n&#x27;</span>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want to tag the identifier portion of these as variables? Ie, $_name ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I completely missed it. Yes! It should be tagged. I'll get it done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it turns out that all tests were ignoring the presence of variables due to the missing variable scope and changing it also required to change Mojolicious (src/languages/mojolicious.js) test case, which also had a conflict with the %= tag. I pushed 2 new commits to get variables to work.

@github-actions
Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +229 B

View Changes
file base pr diff
es/core.min.js 8.14 KB 8.14 KB +2 B
es/highlight.min.js 8.14 KB 8.14 KB +2 B
es/languages/perl.min.js 1.87 KB 1.98 KB +111 B
highlight.min.js 8.17 KB 8.17 KB +1 B
languages/perl.min.js 1.87 KB 1.98 KB +113 B

@bmeneg
Copy link
Contributor Author

bmeneg commented Oct 11, 2023

I was not able to reproduce the "Node.js CI/build" failure locally, but looking at the logs I'm not sure it's something related to the changes. At the same time, the Lint error also occurs in the main branch, meaning it's out-of-scope of this PR.

What am I missing?

@joshgoebel
Copy link
Member

Yeah, something isn't happy... I'll try to find some time to look at it soon.

Floating points numbers (eg. `2.34`, `0.54` and `.54`) were not being
matched correctly. This patch splits the number class regex in different
variants to make things clearer and also adds variants to better match
floating points, including the `_` character, and also the special case of
version numbers (eg. v5.38). Markup test for the new number class was also
added.
Perl got a new builtin class support which brought new keywords like
`class`, `method` and `field`, being that some support versioning and
attributes. This commit adds the new keywords with the additional features
they support (eg. attributes and version), alongside their markup test.
The VAR mode had no `scope` set, thus Perl variables were not being matched
and highlighted at all. This commit adds the `variable` scope and update all
tests to consider the new `<span class="variable"></span>`, including those
that use Perl as sub-language (eg. Mojolicious).
Mojolicious uses `%=` as one of the ways to inform the templating engine
Perl code will be embedded after it, however, it was being matched against
Perl's variable scope, `<span class="variable">%=</span>`, even though it's
not a valid Perl variable. This commit updates one of the Perl's variable
variants in other to allow only `$=` as valid variable for it, which has
special meaning, while `@=` and `%=` are not valid, thus solving the
conflict with the tag used by Mojolicious.
Add the required line to the CHANGES.md file.
@github-actions
Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

3 files changed

Total change +225 B

View Changes
file base pr diff
es/languages/perl.min.js 1.87 KB 1.98 KB +111 B
highlight.min.js 8.17 KB 8.17 KB +1 B
languages/perl.min.js 1.87 KB 1.98 KB +113 B

@joshgoebel joshgoebel merged commit 99f70f2 into highlightjs:main Oct 27, 2023
13 of 14 checks passed
@joshgoebel
Copy link
Member

Thanks for the help!

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.

(perl) add support for the new class system Cor.
2 participants