Syntax:...::Perl6(3)

πŸ“¦
version 0.88 Β· 2 versions
, in fedora 43

✨ Syntax::Highlight::Perl6 ✨

okay so bestie, welcome to the manual page for Syntax::Highlight::Perl6(3) β€” straight out of the User Contributed Perl Documentation collection πŸŽ€ it's a Perl 6 Syntax Highlighter and honestly? iconic.


πŸ’œ VERSION

version 0.88


🌈 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 an array of token records (useful for other libraries)
print $p->tokens;

so like, let's break down the vibe of what's happening here πŸ¦‹:

  • $p β€” that's your shiny new Perl6 syntax highlighter object, made with new(text => 'my $foo;')
  • snippet_html β€” spits out html you can just embed in your pages
  • simple_html β€” html with css, perfect for full pages
  • full_html β€” html that comes with a JavaScript node viewer
  • ansi_text β€” ANSI escaped color sequences, so good for console and IRC output
  • tokens β€” an array of token records, chef's kiss for other libraries
heads up bestie: that use STD; line is needed right now, and it's gonna be removed in future releases. not me warning you early πŸ’…

🌸 DESCRIPTION

Syntax::Highlight::Perl6 parses Perl 6 source code using the STD cpan package. It matches parse tree nodes to colors and then returns them in different output formats ✨

so like, you can use it to build web pages with colorful source code samples in its simple and snippet html modes, or β€” and this is the fun part β€” you can use it as a learning tool to examine STD.pm6's output with the JavaScript node viewer in its full html mode. or you can take its parse tree Perl 5 records and go build your next great idea πŸ‘‘

the available output formats are:

  • HTML (snippet, simple and full)
  • ANSI escaped color sequences
  • Perl 5 array of parse trees

🫢 SUBROUTINES/METHODS

this is an object-oriented module, periodt. the following methods are available:

πŸ’– new(options)

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

  • text β€” this one is a required option. this is where you should provide the Perl 6 code πŸ“
  • rule β€” parse rule name for STD.pm6 to parse against (default: TOP)
  • 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))
  • tmp_prefix β€” STD temporary files directory prefix. (default: q{})

πŸ’– snippet_html

Returns the Perl 6 highlighted HTML string that can be embedded. No CSS or JavaScript is inside. clean. minimal. aesthetic πŸŽ€

πŸ’– 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 be inlined if the inline_resources option is 1. the way it gives full package πŸ’…

πŸ’– ansi_text

Returns a Perl highlighted ANSI escape color string.

πŸ’– tokens

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
};

😭 INCOMPATIBILITIES

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. sorry bestie πŸ’€


πŸ¦‹ SEE ALSO

Discussion about this module and STD.pm6 is usually in #perl6 (irc://irc.freenode.net/perl6). This module lives in http://svn.perlide.org/padre/trunk/Syntax-Highlight-Perl6. Larry Wall's STD.pm6 lives in http://github.com/perl6/std.

iykyk πŸ‘‘


πŸ™ˆ 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.pm6 line 5269.

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

use STD; # this must be first for now
use Syntax::Highlight::Perl6;

⭐ ACKNOWLEDGEMENTS

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".

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 ;-)


πŸ‘‘ AUTHOR

Ahmad M. Zawawi <ahmad.zawawi@gmail.com>


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.


πŸŽ€ POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 732:

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

and that's the whole page bestie πŸ’– this doc came to you courtesy of perl v5.42.0, dated 2025-07-25, and filed under Syntax:...::Perl6(3). go forth and highlight something gorgeous βœ¨πŸ’…

πŸ“¦ where this page comes from