Perl6::Parser available for Perl 6

It’s by no means complete, but it’s available for trial from your friendly neighborhood Panda installer. This tool uses Perl 6’s own internal parser in order to generate a parse tree for Perl 6 code, and has enough information to reconstruct the original Perl 6 source, complete with whitespace and comments.

perl6-Perl6-Parser is available in the ecosystem for trial. It’s very much rough around the edges, and can so far handle only a relatively narrow range of Perl 6 code, but that will quickly change, I’m sure. Once it’s further along you should be able to integrate this into things such as pretty-printers, editors, syntax highlighting and other tools. It takes compilable Perl 6 source and generates a tree of Perl 6 objects, which themselves have a .perl6 method to return the original Perl 6 source. Or feel free to override the .perl6 method and format your Perl 6 code how you want it.

Again, this is very crude, and I’ve released it just to get the idea out there. It handles some fairly complex code, such as:

sub median {
  my @a = sort @_;
  return (@a[@a.end / 2] + @a[@a / 2]) / 2;


sub propdivsum (\x) {
    my @l = x > 1, gather for 2 .. x.sqrt.floor -> \d {
        my \y = x div d;
        if y * d == x { take d; take y unless y == d }
    [+] gather @l.deepmap(*.take);

It’s of necessity slow going as I’m accounting for every bit of whitespace and backslash on the way, but it’s working so far. And yes, it does handle here-docs.

Join me online for 3 hours of Perl 6 training courtesy O'Reilly

Top Ten Things You Need To Know about Perl 6

As the title says, I'm working with O'Reilly to deliver a 3-hour training seminar on the basics of Perl 6 in mid-October. This is going to be more targeted to those learning Perl 6 ab initio, rather than seasoned Perl 5 programmers. I do intend to throw a f…

From Regular Expressions to Grammars (in Perl 6) Part IV

The fourth and final installment of the Perl 6 regular expression -> grammars tutorial has hit the blog: From Regular Expressions to Grammars, Part 4

Part 3 of Perl 6: Regular Expressions to Grammars

Part 3 of the Regular Expressions to Grammars tutorial is now up at - This covers parsing of a short JavaScript blurb into a form that the compiler we're going to write next time can understand.

From Regular Expressions to Grammars (in Perl 6) Part II

Part 2 of my Regular Expressions to Grammars tutorial is now up at The Perl Fisher. The previous part covered the basic metacharacters, this fills out the set and demonstrates how to use regular expressions inside Perl 6 code.