line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pistachio::Language; |
2
|
|
|
|
|
|
|
# ABSTRACT: provides an API for plugging arbitrary language tokenizers and stylizers into Pistachio |
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
24
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
83
|
|
5
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
948
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.10'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# @param string $type Object type. |
9
|
|
|
|
|
|
|
# @param string $lang A language identifier. E.g., 'Perl5'. |
10
|
|
|
|
|
|
|
# @param hash %subs Map of {string => coderef}. |
11
|
|
|
|
|
|
|
# @return Pistachio::Language |
12
|
|
|
|
|
|
|
sub new { |
13
|
6
|
|
|
6
|
0
|
30
|
my ($type, $lang, %subs) = (shift, shift, @_); |
14
|
0
|
|
|
0
|
|
0
|
bless [ |
15
|
|
|
|
|
|
|
$lang, |
16
|
|
|
|
|
|
|
$subs{tokens}, |
17
|
|
|
|
|
|
|
$subs{type_to_style}, |
18
|
|
|
|
|
|
|
$subs{transform_rules} || sub {[]} |
19
|
6
|
|
100
|
|
|
80
|
], $type; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# @param Pistachio::Language $this |
23
|
|
|
|
|
|
|
# @return string A language identifier. E.g., 'Perl5'. |
24
|
0
|
|
|
0
|
0
|
0
|
sub language { my $this = shift; $this->[0] } |
|
0
|
|
|
|
|
0
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# @param Pistachio::Language $this |
27
|
|
|
|
|
|
|
# @param scalar/ref Input text. |
28
|
|
|
|
|
|
|
# @return arrayref Array of Pistachio::Tokens. |
29
|
4
|
|
|
4
|
0
|
10
|
sub tokens { my $this = shift; $this->[1]->(shift) } |
|
4
|
|
|
|
|
17
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# @param Pistachio::Language $this |
32
|
|
|
|
|
|
|
# @param string A Pistachio::Token type. |
33
|
|
|
|
|
|
|
# @return string CSS style definition, per token type. |
34
|
4
|
|
|
4
|
0
|
6
|
sub type_to_style { my $this = shift; $this->[2]->(shift) } |
|
4
|
|
|
|
|
12
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# @param Pistachio::Language $this |
37
|
|
|
|
|
|
|
# @return arrayref Transform rules (possibly empty). |
38
|
23
|
|
|
23
|
0
|
30
|
sub transform_rules { my $this = shift; $this->[3]->() } |
|
23
|
|
|
|
|
61
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |