-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh(perl) add support for the new class system (#3856)
* Enhance support for floating point numbers 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. * Add support for Perl new classes system 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. * Fix missing scope for Perl variables 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). * Fix Perl and Mojolicious conflict on variables 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.
- Loading branch information
Showing
9 changed files
with
144 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
<span class="language-perl">%layout <span class="hljs-string">'bootstrap'</span>;</span><span class="language-xml"> | ||
<span class="language-perl">% layout <span class="hljs-string">'bootstrap'</span>;</span><span class="language-xml"> | ||
</span><span class="language-perl">% title <span class="hljs-string">"Import your subs"</span>;</span><span class="language-xml"> | ||
</span><span class="language-perl">%= form_for <span class="hljs-string">'/settings/import'</span> => (<span class="hljs-string">method =></span> <span class="hljs-string">'post'</span>, <span class="hljs-string">enctype =></span> <span class="hljs-string">'multipart/form-data'</span>) => begin</span><span class="language-xml"> | ||
</span><span class="language-perl"> %= file_field <span class="hljs-string">'opmlfile'</span> => <span class="hljs-string">multiple =></span> <span class="hljs-string">'true'</span></span><span class="language-xml"> | ||
</span><span class="language-perl"> %= submit_button <span class="hljs-string">'Import'</span>, <span class="hljs-string">'class'</span> => <span class="hljs-string">'btn'</span></span><span class="language-xml"> | ||
</span><span class="language-perl">% end</span><span class="language-xml"> | ||
<span class="hljs-tag"><<span class="hljs-name">div</span>></span> | ||
</span><span class="language-perl">% <span class="hljs-keyword">if</span> ($subs) {</span><span class="language-xml"> | ||
</span><span class="language-perl">% <span class="hljs-keyword">if</span> (<span class="hljs-variable">$subs</span>) {</span><span class="language-xml"> | ||
<span class="hljs-tag"><<span class="hljs-name">dl</span>></span> | ||
</span><span class="language-perl">% <span class="hljs-keyword">for</span> <span class="hljs-keyword">my</span> $item (@$subs) {</span><span class="language-xml"> | ||
</span><span class="language-perl">% <span class="hljs-keyword">my</span> ($dir, $align) = ($item->{rtl}) ? (<span class="hljs-string">'rtl'</span>, <span class="hljs-string">'right'</span>) : (<span class="hljs-string">'ltr'</span>, <span class="hljs-string">'left'</span>);</span><span class="language-xml"> | ||
<span class="hljs-tag"><<span class="hljs-name">dt</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"<%=</span></span></span><span class="language-perl"> $align </span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">%>"</span>></span><span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"<%=</span></span></span><span class="language-perl"> $item->{<span class="hljs-string">'xmlUrl'</span>} </span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">%>"</span>></span><span class="hljs-tag"><<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"icon-rss"</span>></span><span class="hljs-tag"></<span class="hljs-name">i</span>></span> rss<span class="hljs-tag"></<span class="hljs-name">a</span>></span> | ||
<span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">dir</span>=<span class="hljs-string">"<%=</span></span></span><span class="language-perl"> $dir </span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">%>"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"<%=</span></span></span><span class="language-perl"> $item->{htmlUrl} </span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">%>"</span>></span><%==</span><span class="language-perl"> $item->{title} </span><span class="language-xml">%><span class="hljs-tag"></<span class="hljs-name">a</span>></span> | ||
</span><span class="language-perl">% <span class="hljs-keyword">for</span> <span class="hljs-keyword">my</span> <span class="hljs-variable">$item</span> (<span class="hljs-variable">@$</span>subs) {</span><span class="language-xml"> | ||
</span><span class="language-perl">% <span class="hljs-keyword">my</span> (<span class="hljs-variable">$dir</span>, <span class="hljs-variable">$align</span>) = (<span class="hljs-variable">$item</span>->{rtl}) ? (<span class="hljs-string">'rtl'</span>, <span class="hljs-string">'right'</span>) : (<span class="hljs-string">'ltr'</span>, <span class="hljs-string">'left'</span>);</span><span class="language-xml"> | ||
<span class="hljs-tag"><<span class="hljs-name">dt</span> <span class="hljs-attr">align</span>=<span class="hljs-string">"<%=</span></span></span><span class="language-perl"> <span class="hljs-variable">$align</span> </span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">%>"</span>></span><span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"<%=</span></span></span><span class="language-perl"> <span class="hljs-variable">$item</span>->{<span class="hljs-string">'xmlUrl'</span>} </span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">%>"</span>></span><span class="hljs-tag"><<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"icon-rss"</span>></span><span class="hljs-tag"></<span class="hljs-name">i</span>></span> rss<span class="hljs-tag"></<span class="hljs-name">a</span>></span> | ||
<span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">dir</span>=<span class="hljs-string">"<%=</span></span></span><span class="language-perl"> <span class="hljs-variable">$dir</span> </span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">%>"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"<%=</span></span></span><span class="language-perl"> <span class="hljs-variable">$item</span>->{htmlUrl} </span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">%>"</span>></span><%==</span><span class="language-perl"> <span class="hljs-variable">$item</span>->{title} </span><span class="language-xml">%><span class="hljs-tag"></<span class="hljs-name">a</span>></span> | ||
<span class="hljs-tag"></<span class="hljs-name">dt</span>></span> | ||
<span class="hljs-tag"><<span class="hljs-name">dd</span>></span><span class="hljs-tag"><<span class="hljs-name">b</span>></span>Categories<span class="hljs-tag"></<span class="hljs-name">b</span>></span> | ||
</span><span class="language-perl">%= <span class="hljs-keyword">join</span> <span class="hljs-string">q{, }</span>, <span class="hljs-keyword">sort</span> @{ $item->{categories} || [] };</span><span class="language-xml"> | ||
</span><span class="language-perl">%= <span class="hljs-keyword">join</span> <span class="hljs-string">q{, }</span>, <span class="hljs-keyword">sort</span> @{ <span class="hljs-variable">$item</span>->{categories} || [] };</span><span class="language-xml"> | ||
<span class="hljs-tag"></<span class="hljs-name">dd</span>></span> | ||
<span class="hljs-tag"></<span class="hljs-name">dl</span>></span> | ||
</span><span class="language-perl">% }</span><span class="language-xml"> | ||
<span class="hljs-tag"></<span class="hljs-name">div</span>></span> | ||
</span> | ||
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<span class="hljs-keyword">use</span> <span class="hljs-number">v5.38</span>; | ||
|
||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Example</span>::<span class="hljs-title">Subclass</span><span class="hljs-attr"> :isa(Example::Base 2.345)</span> </span>{ | ||
<span class="hljs-keyword">field</span> <span class="hljs-variable">$_config<span class="hljs-attr"> :param</span><span class="hljs-attr"> :param</span><span class="hljs-attr"> :param</span></span>; | ||
<span class="hljs-keyword">field</span> <span class="hljs-variable">$_name<span class="hljs-attr"> : param</span></span> = <span class="hljs-string">'Test'</span>; | ||
|
||
<span class="hljs-function"><span class="hljs-keyword">method</span> <span class="hljs-title">test</span>() </span>{ | ||
<span class="hljs-variable">$_name</span> == <span class="hljs-string">'Test'</span> ? <span class="hljs-string">'y'</span> : <span class="hljs-string">'n'</span>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use v5.38; | ||
|
||
class Example::Subclass :isa(Example::Base 2.345) { | ||
field $_config :param :param :param; | ||
field $_name : param = 'Test'; | ||
|
||
method test() { | ||
$_name == 'Test' ? 'y' : 'n'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<span class="hljs-keyword">use</span> <span class="hljs-number">v5.38</span>; | ||
<span class="hljs-keyword">use</span> <span class="hljs-number">5.0020</span>; | ||
|
||
<span class="hljs-keyword">my</span> <span class="hljs-variable">$number</span> = <span class="hljs-number">9</span>; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">0</span>; | ||
<span class="hljs-variable">$number</span> = 0_; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">00</span>; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">0.99</span>; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">99</span>; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">99.9</span>; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">99.99</span>; | ||
<span class="hljs-variable">$number</span> = ._99; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">0x99FF</span>; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">0x99_EE_FF</span>; | ||
<span class="hljs-variable">$number</span> = 0x_99_FF; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">0b00101011</span>; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">0b0010_1011</span>; | ||
<span class="hljs-variable">$number</span> = 0b_0010_1011; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">0777</span>; | ||
<span class="hljs-variable">$number</span> = <span class="hljs-number">07_7_7</span>; | ||
<span class="hljs-variable">$number</span> = 0_777; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use v5.38; | ||
use 5.0020; | ||
|
||
my $number = 9; | ||
$number = 0; | ||
$number = 0_; | ||
$number = 00; | ||
$number = 0.99; | ||
$number = 99; | ||
$number = 99.9; | ||
$number = 99.99; | ||
$number = ._99; | ||
$number = 0x99FF; | ||
$number = 0x99_EE_FF; | ||
$number = 0x_99_FF; | ||
$number = 0b00101011; | ||
$number = 0b0010_1011; | ||
$number = 0b_0010_1011; | ||
$number = 0777; | ||
$number = 07_7_7; | ||
$number = 0_777; |