View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
أحمد محمد زواوي - Ahmad M. Zawawi > Syntax-Highlight-Perl6 > Syntax::Highlight::Perl6



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.88   Source  


Syntax::Highlight::Perl6 - Perl 6 Syntax Highlighter


version 0.88


    ### NOTE: This is needed and will be removed in future releases
    use STD;
    use Syntax::Highlight::Perl6;

    # Creates the Perl6 syntax highlighter object
    my $p = Syntax::Highlight::Perl6->new(
        text => 'my $foo;'

    # Prints html that can be embedded in your pages
    print $p->snippet_html;

    # Prints html with css (useful for full pages)
    print $p->simple_html;

    # Prints html that has a JavaScript node viewer
    print $p->full_html;

    # Prints ANSI escaped color sequences (useful for console and IRC output)
    print $p->ansi_text;

    # Prints an array of token records (useful for other libraries)
    print $p->tokens;


Syntax::Highlight::Perl6 parses Perl 6 source code using STD cpan package. It matches parse tree nodes to colors then returns them in different output formats. It can be used to create web pages with colorful source code samples in its simple and snippet html modes, or it can be used as a learning tool in examining STD.pm6's output using the JavaScript node viewer in its full html mode. Or you can use its parse tree Perl 5 records to build your next great idea.

The available output formats are:


This is an object-oriented module. The following methods are available:


Returns the syntax highlighting object. It needs a hash of options. The following options are available:


Returns the Perl 6 highlighted HTML string that can be embedded. No CSS or JavaScript is inside.


Returns the Perl 6 highlighted HTML string. The HTML code is the same as full_html but lacks a JavaScript Parse Tree Viewer.


Returns the Perl 6 highlighted HTML string. The HTML consists of a JavaScript Parse Tree Viewer along with CSS-styling. It can inlined if inline_resources option is 1.


Returns a Perl highlighted ANSI escape color string.


Returns an array of hashes containing parsed token records. The hash record is structured as:

    | Matched   | Matched | Matched   | Parse tree | Matched |
    | Last      | string  | rule      | separated  | Line    |
    | Position  | buffer  | name      | by spaces  | Number  |
    |           |         |           |            |         |
    | $last_pos | $buffer | $rule     | $tree      | $lineno |

An example of the tokens method in action:

    use Data::Dumper;
    print Dumper($p->tokens);

The shortened output looks like:

    $VAR1 = {
      'tree' => '',
      'rule' => 0,
      'buffer' => '',
      'last_pos' => 0
    $VAR2 = {
      'tree' => 'statementlist statement statement_modexpr statement_expr EXPR termish noun value number integer ',
      'rule' => 'number',
      'buffer' => '1',
      'last_pos' => 1
    $VAR3 = {
      'tree' => 'statementlist eat_terminator ',
      'rule' => 0,
      'buffer' => ';',
      'last_pos' => 2


This module is dependent on Perl 5.10 features namely the regex engine and state variables (for STD.pm6). So there will be no Perl 5.8.x support in the future.


Discussion about this module and STD.pm6 is usually in #perl6 (irc:// This module lives in . Larry Wall's STD.pm6 lives in


If you find any bugs, please submit them to Thanks.

These are the bugs that i am currently aware of:


The project idea was inspired by Moritz Lenz (moritz) - . Larry Wall's gimme5-generated Perl5 STD.pmc is included to parse Perl 6 code. The initial STD tree traversal code was written by Paweł Murias (pmurias). It was replaced afterwards for performance reasons with Larry Wall's redspans traversal code. redspans stands for red for reductions, and spans from the "from/to span calculations".

This library also includes the following libraries:

JQuery by John Resig (dual licensed under the MIT and GPL licenses).

Thanks guys. I could not have done it without you ;-)


Ahmad M. Zawawi <>


This software is copyright (c) 2010 by Ahmad M. Zawawi.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: