1Syntax::Highlight::PerlU6s(e3r)Contributed Perl DocumentSaytnitoanx::Highlight::Perl6(3)
2
3
4
6 Syntax::Highlight::Perl6 - Perl 6 Syntax Highlighter
7
9 ### NOTE: This is needed and will be removed in future releases
10 use STD;
11 use Syntax::Highlight::Perl6;
12
13 # Creates the Perl6 syntax highlighter object
14 my $p = Syntax::Highlight::Perl6->new(
15 text => 'my $foo;'
16 );
17
18 # Prints html that can be embedded in your pages
19 print $p->snippet_html;
20
21 # Prints html with css (useful for full pages)
22 print $p->simple_html;
23
24 # Prints html that has a JavaScript node viewer
25 print $p->full_html;
26
27 # Prints ANSI escaped color sequences (useful for console and IRC output)
28 print $p->ansi_text;
29
30 # Prints an array of token records (useful for other libraries)
31 print $p->tokens;
32
34 "Syntax::Highlight::Perl6" parses Perl 6 source code using an embedded
35 STD.pm. It matches parse tree nodes to colors then returns them in
36 different output formats. It can be used to create web pages with
37 colorful source code samples in its simple and snippet html modes, or
38 it can be used as a learning tool in examining STD.pm's output using
39 the JavaScript node viewer in its full html mode. Or you can use its
40 parse tree Perl 5 records to build your next great idea.
41
42 The available output formats are:
43
44 · HTML (snippet,simple and full)
45
46 · ANSI escaped color sequences
47
48 · Perl 5 array of parse trees
49
51 This is an object-oriented module. The following methods are available:
52
53 new(options)
54 Returns the syntax highlighting object. It needs a hash of options.
55 The following options are available:
56
57 · text
58
59 This is a required option. This is where you should provide the
60 Perl 6 code.
61
62 · rule
63
64 parse rule name for STD.pm to parse against (default: TOP)
65
66 · inline_resources
67
68 Flag to enable/disable CSS/JavaScript HTML inlining. (default: 0
69 (Disabled))
70
71 · resource_url
72
73 HTML resource url that will be appended when resource inlining is
74 disabled.
75
76 · page_title
77
78 HTML page title for "simple_html" and "full_html" (default: q{})
79
80 · utf8_decode
81
82 Flag to enable/disable utf8 decoding. (default: 1 (Enabled))
83
84 · tmp_prefix
85
86 STD temporary files directory prefix. (default: q{})
87
88 snippet_html
89 Returns the Perl 6 highlighted HTML string that can be embedded. No
90 CSS or JavaScript is inside.
91
92 simple_html
93 Returns the Perl 6 highlighted HTML string. The HTML code is the same
94 as "full_html" but lacks a JavaScript Parse Tree Viewer.
95
96 full_html
97 Returns the Perl 6 highlighted HTML string. The HTML consists of a
98 JavaScript Parse Tree Viewer along with CSS-styling. It can inlined if
99 "inline_resources" option is 1.
100
101 ansi_text
102 Returns a Perl highlighted ANSI escape color string.
103
104 tokens
105 Returns an array of hashes containing parsed token records. The hash
106 record is structured as:
107
108 +-----------+---------+-----------+------------+---------+
109 | Matched | Matched | Matched | Parse tree | Matched |
110 | Last | string | rule | separated | Line |
111 | Position | buffer | name | by spaces | Number |
112 | | | | | |
113 | $last_pos | $buffer | $rule | $tree | $lineno |
114 +-----------+---------+-----------+------------+---------+
115
116 An example of the "tokens" method in action:
117
118 use Data::Dumper;
119 print Dumper($p->tokens);
120
121 The shortened output looks like:
122
123 $VAR1 = {
124 'tree' => '',
125 'rule' => 0,
126 'buffer' => '',
127 'last_pos' => 0
128 };
129 $VAR2 = {
130 'tree' => 'statementlist statement statement_modexpr statement_expr EXPR termish noun value number integer ',
131 'rule' => 'number',
132 'buffer' => '1',
133 'last_pos' => 1
134 };
135 $VAR3 = {
136 'tree' => 'statementlist eat_terminator ',
137 'rule' => 0,
138 'buffer' => ';',
139 'last_pos' => 2
140 };
141
143 This module is dependent on Perl 5.10 features namely the regex engine
144 and state variables (for STD.pm). So Perl 5.8.x support will NOT be
145 available for now.
146
148 Discussion about this module and STD.pm is usually in #perl6
149 (irc://irc.freenode.net/perl6). This module lives in
150 http://svn.perlide.org/padre/trunk/Syntax-Highlight-Perl6 . Larry
151 Wall's "STD.pm" lives in http://svn.pugscode.org/pugs/src/perl6 .
152
154 If you find any bugs, please submit them to
155 http://rt.cpan.org/NoAuth/Bugs.html?Dist=Syntax::Highlight::Perl6.
156 Thanks.
157
158 These are the bugs that i am currently aware of:
159
160 · Can't call method "bless" on an undefined value at STD.pm line
161 5269.
162
163 You have to put "use STD;" before using this module.
164
165 use STD; # this must be first for now
166 use Syntax::Highlight::Perl6;
167
168 · Directory 'lex' is created when using this module.
169
170 STD.pm caches digraphs and the matched rules in there. So this is
171 Pretty Voodoo Stuff. Otherwise it will be pretty slow.
172
173 · Slow startup when using the module for the first time
174
175 That is related to the creation of the cached 'lex'ing directory by
176 STD.pm. This happens only once.
177
179 Written by Ahmad M. Zawawi "<ahmad.zawawi at gmail.com>" ("azawawi" in
180 "#perl6").
181
182 The project idea was inspired by Moritz Lenz (moritz) -
183 http://www.nntp.perl.org/group/perl.perl6.users/2008/07/msg788.html .
184 Larry Wall's "gimme5"-generated Perl5 "STD.pmc" is included to parse
185 Perl 6 code. The initial STD tree traversal code was written by
186 PaweAaX Murias (pmurias). It was replaced afterwards for performance
187 reasons with Larry Wall's "redspans" traversal code. "redspans" stands
188 for "red" for reductions, and "spans" from the "from/to span
189 calculations".
190
191 Thanks guys. I could not have done it without you ;-)
192
194 Copyright (C) 2008-2009 by Ahmad Zawawi
195
196 This program is free software; you can redistribute it and/or modify it
197 under the same terms as Perl itself.
198
199 This library also includes the following libraries:
200
201 STD.pm by Larry Wall (Artistic License 2.0)
202
203 JQuery by John Resig (dual licensed under the MIT and GPL licenses).
204
205
206
207perl v5.12.0 2010-01-10 Syntax::Highlight::Perl6(3)