Skip to content

Commit

Permalink
[Perl] Fix a few regexp related issues and
Browse files Browse the repository at this point in the history
Fix issue sublimehq#541 with  space at the beginnign of a regexp
Fix issue sublimehq#1495 and sublimehq#1594 where // can break the syntax highlighting
Fix issue sublimehq#1325 and sublimehq#1029 related to regexp modifier

Fix issue sublimehq#1326 with variable starting with underscore
  • Loading branch information
Clamsax committed May 10, 2018
1 parent 1cb4c3e commit 7c1e8be
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Perl/Perl.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,16 @@ contexts:
- include: escaped_char
- include: variable
- match: \s+
- match: '((([egimosx]*)))(?=(\s+\S|\s*[;\,\#\{\}\)\]>]|$))'
- match: '((([egimosxpr]*)))(?=(\s+\S|\s*[;\,\#\{\}\)\]>]|$))'
captures:
1: string.regexp.replace.perl
2: punctuation.definition.string.perl
3: keyword.control.regexp-option.perl
pop: true
- match: '\b(?=s([^\s\w\[({<]).*\1([egimos]*)([\}\)\;\,]|\s+))'
- match: '\b(?=s([^\s\w\[({<]).*\1([egimosxpr]*)([\}\)\;\,]|\s+))'
comment: string.regexp.replaceXXX
push:
- match: '((([egimos]*)))(?=([\}\)\;\,]|\s+|$))'
- match: '((([egimosxpr]*)))(?=([\}\)\;\,]|\s+|$))'
captures:
1: string.regexp.replace.perl
2: punctuation.definition.string.perl
Expand Down Expand Up @@ -339,11 +339,12 @@ contexts:
scope: constant.other.key.perl
- match: '(?<={)\s*\w+\s*(?=})'
scope: constant.other.bareword.perl
- match: '(?<!\\)((~\s*)?\/)(\S.*?)(?<!\\)(\\{2})*(\/)'
scope: string.regexp.find.perl
- match: '(?<!\\)(~\s*)?((\/)(.+?)(?<!\\)(\\{2})*(\/)([cgimosxpr]*))'
captures:
1: punctuation.definition.string.perl
5: punctuation.definition.string.perl
2: string.regexp.find.perl
3: punctuation.definition.string.perl
6: punctuation.definition.string.perl
7: keyword.control.regexp-option.perl
- match: (?<!\\)(\~\s*\/)
captures:
0: punctuation.definition.string.perl
Expand Down Expand Up @@ -1087,11 +1088,11 @@ contexts:
scope: variable.other.subpattern.perl
captures:
1: punctuation.definition.variable.perl
- match: '([\$\@\%](#)?)([a-zA-Zx7f-xff\$]|::)([a-zA-Z0-9_x7f-xff\$]|::)*\b'
- match: '([\$\@\%](#)?)([a-zA-Zx7f-xff\$_]|::)([a-zA-Z0-9_x7f-xff\$]|::)*\b'
scope: variable.other.readwrite.global.perl
captures:
1: punctuation.definition.variable.perl
- match: '(\$\{)(?:[a-zA-Zx7f-xff\$]|::)(?:[a-zA-Z0-9_x7f-xff\$]|::)*(\})'
- match: '(\$\{)(?:[a-zA-Zx7f-xff\$_]|::)(?:[a-zA-Z0-9_x7f-xff\$]|::)*(\})'
scope: variable.other.readwrite.global.perl
captures:
1: punctuation.definition.variable.perl
Expand Down
136 changes: 136 additions & 0 deletions Perl/syntax_test_perl.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# SYNTAX TEST "Perl.sublime-syntax"

# Variable
$foo = 'bar'
# <- variable.other.readwrite.global.perl punctuation.definition.variable.perl
#^^^ variable.other.readwrite.global.perl

$_foo = 'bar'
# <- variable.other.readwrite.global.perl punctuation.definition.variable.perl
#^^^ variable.other.readwrite.global.perl

@foo = 'bar'
# <- variable.other.readwrite.global.perl punctuation.definition.variable.perl
#^^^ variable.other.readwrite.global.perl

@_foo = 'bar'
# <- variable.other.readwrite.global.perl punctuation.definition.variable.perl
#^^^ variable.other.readwrite.global.perl

%foo = 'bar'
# <- variable.other.readwrite.global.perl punctuation.definition.variable.perl
#^^^ variable.other.readwrite.global.perl

%_foo = 'bar'
# <- variable.other.readwrite.global.perl punctuation.definition.variable.perl
#^^^ variable.other.readwrite.global.perl

${%_foobar} = ''
# ^ variable.other.readwrite.global.perl punctuation.definition.variable.perl
# ^^^^^^^ variable.other.readwrite.global.perl

###################
# Regexp Handling #

my @config_info = split / /, get_configuration( "//foo/config", $file_handler );
# ^^^^^ support.function.perl
# ^ string.regexp.find.perl punctuation.definition.string.perl
# ^ string.regexp.find.perl
# ^ string.regexp.find.perl punctuation.definition.string.perl
# ^^^^^^^^^^^^ string.quoted.double.perl
# ^ variable.other.readwrite.global.perl punctuation.definition.variable.perl
# ^^^^^^^^^^^^ variable.other.readwrite.global.perl

$rex = qr/my.STRING/is;
# ^^ string.regexp.compile.simple-delimiter.perl punctuation.definition.string.perl support.function.perl
# ^ string.regexp.compile.simple-delimiter.perl punctuation.definition.string.perl
# ^ string.regexp.compile.simple-delimiter.perl punctuation.definition.string.perl
# ^^ string.regexp.compile.perl punctuation.definition.string.perl keyword.control.regexp-option.perl

$i //= '08';
# ^ string.quoted.single.perl punctuation.definition.string.begin.perl
# ^^ string.quoted.single.perl

$foo =~ m/fee|fie|foe|fum/

my @string = split /foo\/bar/, $string;
# ^^^^^^^^ string.regexp.find.perl

my @string = split /[:,\s\/]+/, $string;
# ^^^^^^^^^ string.regexp.find.perl

if(/ foo/) {
# ^^^^ string.regexp.find.perl
}
if($str =~/ foo/) {
# ^ string.regexp.find.perl punctuation.definition.string.perl
# ^^^^ string.regexp.find.perl
some($code);
}

$home = $ENV{HOME}
// $ENV{LOGDIR}
# ^^^^^^ constant.other.bareword.perl
// (getpwuid($<))[7]
# ^^^^^^^^ support.function.perl
// die "You're homeless!\n";
# ^^^ keyword.control.perl
# ^ string.quoted.double.perl punctuation.definition.string.begin.perl


$regex =~ s/bar/foo/gr;
# ^ string.regexp punctuation.definition.string.perl support.function.perl
# ^^ string.regexp.replace.perl punctuation.definition.string.perl keyword.control.regexp-option.perl
$regex =~ qr/sdf/x;
# ^^ string.regexp.compile.simple-delimiter.perl punctuation.definition.string.perl support.function.perl
# ^ string.regexp.compile.simple-delimiter.perl punctuation.definition.string.perl
# ^^^ string.regexp.compile.simple-delimiter.perl
# ^ string.regexp.compile.simple-delimiter.perl punctuation.definition.string.perl
# ^ string.regexp.compile.perl punctuation.definition.string.perl keyword.control.regexp-option.perl
$regex =~ /sdf/g;
# ^ string.regexp.find.perl keyword.control.regexp-option.perl
# ^ -punctuation.definition.string.perl
$regex =~ s/sdf/bar/p
# ^ string.regexp punctuation.definition.string.perl support.function.perl
# ^ string.regexp.replace.perl punctuation.definition.string.perl keyword.control.regexp-option.perl
$regex =~ s/sdf/bar/xx;
# ^ string.regexp punctuation.definition.string.perl support.function.perl
# ^^ string.regexp.replace.perl punctuation.definition.string.perl keyword.control.regexp-option.perl
$regex =~ s/sdf/bar/r;
# ^ string.regexp.replace.perl punctuation.definition.string.perl keyword.control.regexp-option.perl

my $sentence_rx = qr{
# ^ string.regexp.compile.nested_braces.perl punctuation.definition.string.perl
(?: (?<= ^ ) | (?<= \s ) ) # after start-of-string or
# whitespace
\p{Lu} # capital letter
.*? # a bunch of anything
(?<= \S ) # that ends in non-
# whitespace
(?<! \b [DMS]r ) # but isn't a common abbr.
(?<! \b Mrs )
(?<! \b Sra )
(?<! \b St )
[.?!] # followed by a sentence
# ender
(?= $ | \s ) # in front of end-of-string
# or whitespace
}sx;
# ^ string.regexp.compile.nested_braces.perl punctuation.definition.string.perl
# ^^ string.regexp.compile.perl punctuation.definition.string.perl keyword.control.regexp-option.perl


#############
# Functions #

sub get_configuration {
# <- meta.function.perl storage.type.sub.perl
# ^^^^^^^^^^^^^^^^^ meta.function.perl entity.name.function.perl
my $param1 = shift;
# ^^^^^ support.function.perl
return "configuration";
# ^^^^^^ keyword.control.perl
# ^ string.quoted.double.perl punctuation.definition.string.begin.perl
# ^^^^^^^^^^^^^ string.quoted.double.perl
# ^ string.quoted.double.perl punctuation.definition.string.end.perl
}

0 comments on commit 7c1e8be

Please sign in to comment.