Tuesday, July 14, 2009

Perl 6 Parsing Generously?

I just started a new little Perl 6 project by grabbing a little 99 line Perl 5 script, sticking use v6; at the top, and running it through Rakduo. Much to my surprise, a lot fewer things were complained about than I expected. (So far, I'm only about one-third through the first stage of the port.)

It did complain about my $in_file = shift; to store the next value from @ARGV/@*ARGS, about foreach $arg (@*ARGS), and about using dot from string concatenation. But it did not complain about if ($arg =~ /^\-sd/), for ($i = $1; $i <= $2; $i++), or open IN_FILE, $in_file or die. I wouldn't have expected any of those to get through the parser? (I'm assuming they'll fail when the code finally is ported enough to reach proper execution.)

I'm also trying to figure out how to automatically test this script. I guess I can easily enough throw a few files at it and check to make sure the results are correct. Does it make sense to try to unit test something this small? (As it is, the Perl 5 version has no subs at all!) And what is the accepted way of doing such testing in Perl 6?

2 comments:

  1. Rakudo's parser isn't quite as good as one might hope for.

    Instead I recommend feeding the script into STD.pm, which warns about a lot of Perl5isms that can be detected at parse time.

    Eventually Rakudo will use STD.pm, but we need proto regexes and longest token matching for that...

    ReplyDelete
  2. Expect speed from Rakudo and accuracy from STD.pm and ease-of-use from Padre Perl 6. Imagine when we will have all three put together! I was going to improve Perl 6 plugin a lot last week but life is now a bit hectic for me but do not worry I will manage :)

    ReplyDelete