Skip to content

Commit

Permalink
[Perl] Add unquoted hash keys highlighting (#2026)
Browse files Browse the repository at this point in the history
In order to access an item of a hash (dictionary), the caller can use
an unquoted string as key.

In the other way round: The `item_key` in `$the_hash{item_key}` is a simple unquoted string.

Prior to this commit, the key was not scoped at all and would so as function/method call in the future.
  • Loading branch information
deathaxe authored and wbond committed Aug 1, 2019
1 parent ddbebc8 commit d1494f4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Perl/Perl.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,12 @@ contexts:
- include: groups-nested
- include: expressions
- regexp-pop
- match: (\{)\s*({{identifier}})\s*(\})
scope: meta.item-access.perl
captures:
1: punctuation.section.item-access.begin.perl
2: string.unquoted.perl
3: punctuation.section.item-access.end.perl
- match: \{
scope: punctuation.section.item-access.begin.perl
push:
Expand Down
47 changes: 47 additions & 0 deletions Perl/syntax_test_perl.pl
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,9 @@ =head1 B<--param>
# ^ punctuation.definition.variable.perl
# ^^ punctuation.accessor.double-colon.perl
# ^^^^^^ support.class.perl
# ^ punctuation.section.item-access.begin.perl
# ^^^^^^^^^^ string.quoted.single.perl
# ^ punctuation.section.item-access.end.perl
-f
# ^^ keyword.operator.filetest.perl
-foo
Expand All @@ -787,12 +790,56 @@ =head1 B<--param>
# ^^^^^ string.quoted.double.perl
# ^ punctuation.definition.string.end.perl
# ^ punctuation.terminator.statement.perl
$foo{bar}
# ^^^^ variable.other.readwrite.global.perl
# ^ punctuation.definition.variable.perl
# ^ punctuation.section.item-access.begin.perl
# ^^^^^ meta.item-access.perl
# ^^^ string.unquoted.perl
# ^ punctuation.section.item-access.end.perl
$foo{bar()}
# ^^^^ variable.other.readwrite.global.perl
# ^ punctuation.definition.variable.perl
# ^ punctuation.section.item-access.begin.perl
# ^^^^^ meta.item-access.perl
# ^^^ variable.function.perl
# ^ punctuation.section.item-access.end.perl
$foo{10 + $bar}
# ^^^^ variable.other.readwrite.global.perl
# ^ punctuation.definition.variable.perl
# ^ punctuation.section.item-access.begin.perl
# ^^^^^^^^^^^ meta.item-access.perl
# ^^ constant.numeric.integer.decimal.perl
# ^ keyword.operator.arithmetic.perl
# ^^^^ variable.other.readwrite.global.perl
# ^ punctuation.section.item-access.end.perl
%{$foo{bar}{baz}} = 'excl';
# ^^^^^^^^^^^^^^^^^ meta.braces.perl variable.other.readwrite.global.perl
# ^^^^^^^^^^ meta.item-access.perl
# ^^ punctuation.definition.variable.begin.perl
# ^ punctuation.definition.variable.perl
# ^^^^ variable.other.readwrite.global.perl variable.other.readwrite.global.perl
# ^ punctuation.section.item-access.begin.perl
# ^^^ string.unquoted.perl
# ^ punctuation.section.item-access.end.perl
# ^^^ string.unquoted.perl
# ^ punctuation.section.item-access.end.perl
# ^ punctuation.definition.variable.end.perl
# ^ keyword.operator.assignment.perl
# ^^^^^^ string.quoted.single.perl
# ^ punctuation.terminator.statement.perl
%{$foo{'bar'}{'bar'}} = 'excl';
# ^^^^^^^^^^^^^^^^^^^^^ meta.braces.perl variable.other.readwrite.global.perl
# ^^^^^^^^^^^^^^ meta.item-access.perl
# ^^ punctuation.definition.variable.begin.perl
# ^ punctuation.definition.variable.perl
# ^^^^ variable.other.readwrite.global.perl variable.other.readwrite.global.perl
# ^ punctuation.section.item-access.begin.perl
# ^^^^^ string.quoted.single.perl
# ^ punctuation.section.item-access.end.perl
# ^ punctuation.section.item-access.begin.perl
# ^^^^^ string.quoted.single.perl
# ^ punctuation.section.item-access.end.perl
# ^ punctuation.definition.variable.end.perl
# ^ keyword.operator.assignment.perl
# ^^^^^^ string.quoted.single.perl
Expand Down

0 comments on commit d1494f4

Please sign in to comment.