NAME

Syntax::Highlight::Perl6 - a Perl 6 syntax highlighter

SYNOPSIS

### 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 the Perl 5 array of parse trees (useful for building stuff on top of it)
print $p->parse_trees;

# Prints VIM syntax highlighted html
print $p->vim_html;

DESCRIPTION

This module parses Perl 6 source code using STD.pm, then matches nodes to colors and 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.pm's parsing using the JavaScript node viewer in its full html mode.

The available output formats are:

  • HTML (snippet,simple and full)

  • ANSI escaped color sequences

  • Perl 5 array of parse trees

SUBROUTINES/METHODS

The following methods are available:

  • new(options)

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

    • text

      This is a required option. This is where you should provide the Perl 6 code.

    • rule

      parse rule name for STD.pm to parse against (default: comp_unit)

    • inline_resources

      Flag to enable/disable CSS/JavaScript HTML inlining. (default: 0 (Disabled))

    • resource_url

      HTML resource url that will be appended when resource inlining is disabled.

    • page_title

      HTML page title for simple_html and full_html (default: q{})

    • utf8_decode

      Flag to enable/disable utf8 decoding. (default: 1 (Enabled))

  • snippet_html()

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

  • simple_html()

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

  • full_html()

    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.

  • ansi_text()

    Returns a Perl highlighted ANSI escape color string.

  • parse_trees()

    Returns a Perl 5 array containing parse tree records. The array consists of one or more of the following record:

    +-----------------------------------------------+
    | Matched  | Matched | Matched   | Parse tree   |
    | Start    | string  | rule      | separated    |
    | Position | buffer  | name      | by spaces    |
    +-----------------------------------------------+
    
    #...
    use Data::Dumper;
    print Dumper($p->parse_trees);
    
    #$VAR1 = [
    #      [
    #        8,
    #        ';',
    #        0,
    #        'statementlist eat_terminator '
    #      ]
  • vim_html()

    Returns the Perl 6 highlighted HTML string that was generated using VIM's excellent syntax coloring engine. Please remember to copy perl6.vim to your ~/.vim/syntax.

    NOTE: This method needs VIM to work properly along with Text::VimColor.

SEE ALSO

Text::VimColor

Discussion about this module and STD.pm is usually in #perl6 (irc://irc.freenode.net/perl6). Larry Wall's STD.pm lives in http://svn.pugscode.org/pugs/src/perl6 . perl6.vim lives in http://svn.pugscode.org/pugs/util/perl6.vim .

BUGS AND LIMITATIONS

If you find any bugs, please submit them to http://rt.cpan.org/NoAuth/Bugs.html?Dist=Syntax::Highlight::Perl6. Thanks.

These are the bugs that i am currently aware of:

  • Can't call method "bless" on an undefined value at STD.pm line 5269.

    You have to put "use STD;" before using this module.

    use STD; # this must be first for now
    use Syntax::Highlight::Perl6;
  • A log file is always created when using this module.

    This is a bug and im working on it. Most probably it is STD.pm-related

  • Directory 'lex' is created when using this module.

    STD.pm caches digraphs and the matched rules in there. So this is Pretty Voodoo Stuff. Otherwise it will be pretty slow.

  • Slow startup when using the module for the first time

    That is related to the creation of the cached 'lex'ing directory by STD.pm. This happens only once.

AUTHOR

Written by Ahmad M. Zawawi <ahmad.zawawi@gmail.com> (aka azawawi in #perl6).

The project idea was inspired by Moritz Lenz (moritz) - http://www.nntp.perl.org/group/perl.perl6.users/2008/07/msg788.html . 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". The included perl6.vim is written by Luke Palmer, Moritz Lenz, and Hinrik Ãn Sigurðsson. T

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

LICENSE AND COPYRIGHT

Copyright (C) 2008 by Ahmad Zawawi

This library is free software; you can redistribute it and/or modify it under the same terms as the Artistic License 2.0

This library also includes the following libraries:

STD.pm by Larry Wall (Artistic License 2.0 - same license)

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

1 POD Error

The following errors were encountered while parsing the POD:

Around line 732:

Non-ASCII character seen before =encoding in 'Paweł'. Assuming UTF-8