Larry Wall on Perl 6 usability

Sunday, 31 Aug 2008

Larry Wall:

The rule for parsing the ternary operator just treats it as a real fat infix operator that happens to have an expression embedded in the middle. This [points at EXPR rule in Perl 6 grammar on screen] is calling into the rule that happens to be the operator precedence parser and as with any rule – since they’re all just methods underneath anyway – they can be parametrised, and we’ve parametrised it with the maximum precedence level that’s allowed in there. And if it doesn’t get that, then we know fairly accurately which mistake they made – you know, they put an assignment inside where it doesn’t make sense, something like that. A lot of this is designed to give a very useful compiler to the end user, to give them a message where they don’t have to scratch their head for 5 minutes to try to figure out what went wrong.

Another notion that we have here that has not been truly explored yet is the idea of Suppose Points. As you’re going through and doing a parse, oftentimes you’ll come to a spot where you say, “well, the right way to parse it is this, but it looks like they might have a mistake here. I don’t know if they did or not; they might mean this.” So we will suppose that they knew what they were doing, but we’ll remember this. And if somewhere later on we get a parse error, it’s going to come back to here to this Suppose Point and it’s going to say “well, what if they had written it the other way.” So we do a hypothetical parse at this point, going forward again, and if it gets further than it did before, we can be almost certain that that is the mistake they made. Now we don’t go as far as a lot of the compilers in the 1960s and try to fix it for them – that would be, uh, bad –, but we can give them a very, very good error message.