Tracker: Bugs

5 4.3pre13: Perl highlighting: autoquoting hash subscripts - ID: 1947157
Last Update: Comment added ( vanza )

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.)


Markus Laker ( markuslaker ) - 2008-04-20 12:13

5

Open

None

Marcelo Vanzin

None

None

Public


Comments ( 2 )

Date: 2008-05-01 05:00
Sender: vanza


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


Date: 2008-04-20 18:54
Sender: ezustProject AdminAccepting Donations


moving to patches tracker


Attached File

No Files Currently Attached

Changes ( 5 )

Field Old Value Date By
data_type 100588 2008-05-01 05:00 vanza
assigned_to nobody 2008-04-25 18:05 ezust
data_type 300588 2008-04-20 18:54 ezust
category_id text area and syntax packages 2008-04-20 18:54 ezust
artifact_group_id normal bug 2008-04-20 18:54 ezust