Menu

#3063 4.3pre13: Perl highlighting: autoquoting hash subscripts

open
None
5
2011-12-06
2008-04-20
No

Background:

In Perl, if a hash called %h has an element whose key is 'foo', you can address it in two equivalent ways:

$h{'foo'}
$h{foo}

In the second case, 'foo' is said to be autoquoted.

The bug:

Create and save this file:

#!/usr/bin/perl -l

my %hash = (height => 2, width => 3);
my $rh = \%hash;

print $hash{height};
print $$rh{height};
print $rh->{height};

my @a = map {quotemeta} keys %hash;
for (@a) {print};

In each of the three print statements, jEdit correctly spots that `height' is autoquoted, and highlights it as a literal string. However, in the last two lines, it also highlights `quotemeta' and `print' as literal strings; this is a bug.

A heuristic that's probably good enough is to autoquote the contents of the braces only if the open-brace is immediately preceded by a non-blank character. That would fix the behaviour in this example.

We probably need a fix for bug 1946895 (look-behind not working) before we can fix this autoquoting bug. If we had that, a possible fix would be to change this paragraph of perl.xml --

<!-- non-quoted literals in hashes -->
<SPAN_REGEXP TYPE="OPERATOR" HASH_CHAR="{" NO_LINE_BREAK="TRUE" DELEGATE="LITERAL">
<BEGIN>\{(?=\s*[\p{Alpha}_\-][\p{Alnum}_]*\s*\})</BEGIN>
<END>}</END>
</SPAN_REGEXP>

-- to look like this:

<!-- non-quoted literals in hashes -->
<SPAN_REGEXP TYPE="OPERATOR" HASH_CHAR="{" NO_LINE_BREAK="TRUE" DELEGATE="LITERAL">
<BEGIN>(?&lt;=\S)\{(?=\s*[\p{Alpha}_\-][\p{Alnum}_]*\s*\})</BEGIN>
<END>}</END>
</SPAN_REGEXP>

(The change consists of a few characters added immediately after <BEGIN> tag.)

Discussion

  • Alan Ezust

    Alan Ezust - 2008-04-20
    • labels: 102669 -->
    • milestone: 101608 -->
     
  • Alan Ezust

    Alan Ezust - 2008-04-20

    Logged In: YES
    user_id=935841
    Originator: NO

    moving to patches tracker

     
  • Alan Ezust

    Alan Ezust - 2008-04-25
    • assigned_to: nobody --> vanza
     
  • Marcelo Vanzin

    Marcelo Vanzin - 2008-05-01

    Logged In: YES
    user_id=75113
    Originator: NO

    There's not really a patch here, 'tis a bug. :-)

     
  • Marcelo Vanzin

    Marcelo Vanzin - 2011-11-10
    • assigned_to: vanza --> nobody
     
  • Alan Ezust

    Alan Ezust - 2011-12-06
    • assigned_to: nobody --> przemo_w
     

Log in to post a comment.