Skip to content

Commit

Permalink
[Perl] Small whitespace related improvements (sublimehq#1644)
Browse files Browse the repository at this point in the history
* [Perl] Allow any kind of whitespace around accessors

The accessor `::` may be surrounded by spaces and tabs. Not sure whether
someone makes use of tabs in such situations, but it should not fail if
one decides to do so.

HEREDOC indention still accepts normal spaces only at the moment as the
amount of spaces in front of the starting and terminating keyword must be
the same which might be tricky to handle if mixed indention is used.

* [Perl] Remove an isolated regexp flag

Inspired by PR sublimehq#1640 this commit removes the isolated (?x) from
the `pragma` context.

Even though no related issues were found this style of flag is used
in the `functions` context already. So this change ensures the same
coding style to be used in both contexts.
  • Loading branch information
deathaxe authored and Charlie Vieth committed Jul 25, 2018
1 parent d1b63d6 commit 95edbed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
16 changes: 8 additions & 8 deletions Perl/Perl.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ first_line_match: ^#!.*\bperl\b
scope: source.perl

variables:
break: (?!\w| *::)
break: (?!\w|\s*::)
identifier: '\b[_[:alpha:]]\w*{{break}}'
module: '\b[_[:upper:]]\w*\b'
member: '\b[_[:lower:]]\w*\b'
Expand Down Expand Up @@ -243,8 +243,8 @@ contexts:
# SEE: http://perldoc.perl.org/index-pragmas.html
# http://perldoc.perl.org/perlmodlib.html#Pragmatic-Modules
- match: |-
\b(?x)
(?:attributes|autodie(?:::(?:exception(?:::system)|hints|skip))?|autouse
\b(?x:
attributes|autodie(?:\s*::\s*(?:exception(?:\s*::\s*system)|hints|skip))?|autouse
|base|bigint|bignum|bigrat|blib|bytes
|charnames|constant
|diagnostics
Expand All @@ -260,7 +260,7 @@ contexts:
|threads|threads::shared
|utf8
|vars|vmsish
|warnings|warnings::register){{break}}
|warnings|warnings\s*::\s*register){{break}}
scope: storage.modifier.perl
### [ EXPRESSIONS ]###########################################################
Expand Down Expand Up @@ -589,16 +589,16 @@ contexts:
### [ CLASSES ]################################################################

class:
- match: '{{module}}(?= *(?:::|[#;]|$))'
- match: '{{module}}(?=\s*(?:::|[#;]|$))'
scope: support.class.perl
push: members-pop

members-pop:
- match: ' *(::) *({{module}})'
- match: \s*(::)\s*({{module}})
captures:
1: punctuation.accessor.double-colon.perl
2: support.class.perl
- match: ' *(::) *({{identifier}})'
- match: \s*(::)\s*({{identifier}})
captures:
1: punctuation.accessor.double-colon.perl
2: variable.other.member.perl
Expand Down Expand Up @@ -1029,7 +1029,7 @@ contexts:
1: punctuation.definition.variable.perl
# $Module::SubModule::member
# $::SubModule::member
- match: ([\$\@\%]#?)({{module}})?(?= *::)
- match: ([\$\@\%]#?)({{module}})?(?=\s*::)
captures:
1: punctuation.definition.variable.perl
2: support.class.perl
Expand Down
21 changes: 20 additions & 1 deletion Perl/syntax_test_perl.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,17 @@ =head1 B<--param>
# ^^^^^^^^^^^^^^^^^^ meta.import.require.perl
# ^^^^ - meta.import.require.perl
# ^^^^^^^ keyword.control.import.require.perl
eval { require Mail :: Send; };
#<- support.function.perl
#^^^ support.function.perl
# ^ punctuation.section.block.begin.perl
# ^^^^^^^^^^^^^^^^^^^^ meta.import.require.perl
# ^^^^ support.class.perl
# ^^^^ - support.class
# ^^ punctuation.accessor.double-colon.perl
# ^^^^ support.class.perl
# ^^^^ - meta.import.require.perl
# ^^^^^^^ keyword.control.import.require.perl
use strict;
# <- meta.use.perl keyword.control.import.use.perl
#^^^^^^^^^ meta.use.perl
Expand Down Expand Up @@ -1103,7 +1114,6 @@ =head1 B<--param>
#^^ keyword.control.import.use.perl
# ^^^^ support.class.perl
# ^ punctuation.terminator.statement.perl
use File::data;
# <- meta.use.perl keyword.control.import.use.perl
#^^^^^^^^^^^^^ meta.use.perl
Expand All @@ -1112,6 +1122,15 @@ =head1 B<--param>
# ^^ punctuation.accessor.double-colon.perl
# ^^^^ variable.other.member.perl
# ^ punctuation.terminator.statement.perl
use warnings :: register File :: data;
# <- meta.use.perl keyword.control.import.use.perl
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.use.perl
#^^ keyword.control.import.use.perl
# ^^^^^^^^^^^^^^^^^^^^ storage.modifier.perl
# ^^^^ support.class.perl
# ^^ punctuation.accessor.double-colon.perl
# ^^^^ variable.other.member.perl
# ^ punctuation.terminator.statement.perl
no strict;
# <- meta.no.perl keyword.declaration.no.perl
#^^^^^^^^ meta.no.perl
Expand Down

0 comments on commit 95edbed

Please sign in to comment.