I'm just updating the Perl language definition to support the new keywords and operators in 5.10. I notice that keyword.control.perl includes 'switch' and 'case' (which aren't Perl keywords; it's given/ when in 5.10) and also 'select' which is a function rather than a control keyword.
Is there a compelling reason not to remove switch, case and move select to the functions list?
Also, because I'm a TM language definition newbie, does anyone have any tips about how to handle the // (defined or) operator? In some contexts // is an empty regex; in others it's an operator
my @x = split //, $line; # regex, common idiom to chop into chars my $x = $y // $z; # operator, equiv: my $x = defined $y ? $y : $z
On 1 Jan 2008, at 15:39, Andy Armstrong wrote:
[...] Is there a compelling reason not to remove switch, case and move select to the functions list?
The switch/case might be the result of initially basing the grammar on the C grammar. So presumably it should be removed.
Also, because I'm a TM language definition newbie, does anyone have any tips about how to handle the // (defined or) operator? In some contexts // is an empty regex; in others it's an operator
In the Ruby grammar we have a list of functions that take regexp arguments to solve the division/regexp ambiguity -- something similar could be done for perl wrt the split case.
On 3 Feb 2008, at 11:43, Allan Odgaard wrote:
The switch/case might be the result of initially basing the grammar on the C grammar. So presumably it should be removed.
Also, because I'm a TM language definition newbie, does anyone have any tips about how to handle the // (defined or) operator? In some contexts // is an empty regex; in others it's an operator
In the Ruby grammar we have a list of functions that take regexp arguments to solve the division/regexp ambiguity -- something similar could be done for perl wrt the split case.
I should have been more explicit. In Perl 5.10.0 // could be an empty regex or the new 'defined or' operator:
my $foo = $bar // 'not defined'; # new defined-or operator my @f = split //, $baz; # empty regex
And yes, "only perl can parse Perl" :)
On Feb 3, 2008, at 6:24 AM, Andy Armstrong wrote:
I should have been more explicit. In Perl 5.10.0 // could be an empty regex or the new 'defined or' operator:
my $foo = $bar // 'not defined'; # new defined-or operator my @f = split //, $baz; # empty regex
The relevant bit from the ruby grammar:
http://pastie.textmate.org/private/zuh0beeg1ciwdqbqlovmaa
Basically we define a list of items a regex can follow, anything else and it's a division operator. What you can do is the same expect only with empty regexes. Match // that follows words that regexes can follow, anything not caught will be caught by the lower // operator match. It's not perfect in Ruby but it's pretty close.