Saturday, December 5, 2009

Extra parsing for better errors

Something that I think is a unique feature of Perl 6 is that it goes out of its way to parse things that aren't in the language so that it can give you a really good error message. For instance, in Perl 5 and other C-like languages there is a for loop that looks like this:


Perl 6's version of that loop doesn't start with "for" since it uses "for" exclusively as an iterator of lists. However, if you happen to write a for loop as above, there is code in the standard Perl 6 parser that matches it and tells you what you did wrong and how to fix it. If you read the grammar for Perl 6, you find this sort of thing all over the place.

Perhaps it's just that Perl is in the unique position of having two major versions of the language that have significant differences in syntax and semantics that such extra parsing is almost required. But, I wonder how many other languages do this to the extent of Perl 6?

No comments:

Post a Comment