[TxMt] [PATCH] more perl quoting
Grant Hollingworth
grant at antiflux.org
Tue Nov 21 17:40:04 UTC 2006
I added support for some more valid (if unusual) Perl quoting.
* added <> delimiters for q, qq, qw, qx, m
* allow whitespace before delimiters (broken for s///)
* fixed s[][]
* fixed s()()
I'm a little confused by string.regexp.replaceXXX. Was it intended to replace string.regexp.replace.perl?
-------------- next part --------------
Index: Perl.plist
===================================================================
--- Perl.plist (revision 6192)
+++ Perl.plist (working copy)
@@ -54,7 +54,7 @@
<key>applyEndPatternLast</key>
<integer>1</integer>
<key>begin</key>
- <string>\b(?=qr[^\s\w])</string>
+ <string>\b(?=qr\s*[^\s\w])</string>
<key>comment</key>
<string>string.regexp.compile.perl</string>
<key>end</key>
@@ -81,7 +81,7 @@
<array>
<dict>
<key>begin</key>
- <string>(qr)\{</string>
+ <string>(qr)\s*\{</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -117,7 +117,7 @@
</dict>
<dict>
<key>begin</key>
- <string>(qr)\[</string>
+ <string>(qr)\s*\[</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -153,7 +153,7 @@
</dict>
<dict>
<key>begin</key>
- <string>(qr)<</string>
+ <string>(qr)\s*<</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -189,7 +189,7 @@
</dict>
<dict>
<key>begin</key>
- <string>(qr)\(</string>
+ <string>(qr)\s*\(</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -225,7 +225,7 @@
</dict>
<dict>
<key>begin</key>
- <string>(qr)\'</string>
+ <string>(qr)\s*\'</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -253,7 +253,7 @@
</dict>
<dict>
<key>begin</key>
- <string>(qr)([^\s\w\'\{\[\(\<])</string>
+ <string>(qr)\s*([^\s\w\'\{\[\(\<])</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -293,11 +293,11 @@
<key>applyEndPatternLast</key>
<integer>1</integer>
<key>begin</key>
- <string>\b(?=(s)(\s+\S|\s*[;\,\#\{\}\)]|$))</string>
+ <string>\b(?=(s)(\s+\S|\s*[;\,\#\{\}\(\)\[<]|$))</string>
<key>comment</key>
<string>string.regexp.replace.perl</string>
<key>end</key>
- <string>((([egimosx]*)))(?=(\s+\S|\s*[;\,\#\{\}\)]|$))</string>
+ <string>((([egimosx]*)))(?=(\s+\S|\s*[;\,\#\{\}\)\]>]|$))</string>
<key>endCaptures</key>
<dict>
<key>1</key>
@@ -320,7 +320,7 @@
<array>
<dict>
<key>begin</key>
- <string>(s)\{</string>
+ <string>(s)\s*\{</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -352,7 +352,7 @@
</dict>
<dict>
<key>begin</key>
- <string>(s)\[</string>
+ <string>(s)\s*\[</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -384,7 +384,7 @@
</dict>
<dict>
<key>begin</key>
- <string>(s)<</string>
+ <string>(s)\s*<</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -416,7 +416,7 @@
</dict>
<dict>
<key>begin</key>
- <string>(s)\(</string>
+ <string>(s)\s*\(</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -657,7 +657,7 @@
<array>
<dict>
<key>begin</key>
- <string>(s)([^\s\w\[({<])</string>
+ <string>(s\s*)([^\s\w\[({<])</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -739,7 +739,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\b(?=(?<!\\)s([^\s\w\[({<]))</string>
+ <string>\b(?=(?<!\\)s\s*([^\s\w\[({<]))</string>
<key>comment</key>
<string>string.regexp.replace.extended</string>
<key>end</key>
@@ -766,7 +766,7 @@
<array>
<dict>
<key>begin</key>
- <string>(s)(.)</string>
+ <string>(s)\s*(.)</string>
<key>captures</key>
<dict>
<key>0</key>
@@ -1145,6 +1145,45 @@
</array>
</dict>
<dict>
+ <key>begin</key>
+ <string>\b(m)\s*(?<!\\)\<</string>
+ <key>beginCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.string.begin.perl</string>
+ </dict>
+ </dict>
+ <key>end</key>
+ <string>\></string>
+ <key>endCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.string.end.perl</string>
+ </dict>
+ </dict>
+ <key>name</key>
+ <string>string.regexp.find-m-ltgt.perl</string>
+ <key>patterns</key>
+ <array>
+ <dict>
+ <key>include</key>
+ <string>#escaped_char</string>
+ </dict>
+ <dict>
+ <key>include</key>
+ <string>#nested_ltgt_interpolated</string>
+ </dict>
+ <dict>
+ <key>include</key>
+ <string>#variable</string>
+ </dict>
+ </array>
+ </dict>
+ <dict>
<key>captures</key>
<dict>
<key>1</key>
@@ -1726,7 +1765,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqq([^\(\{\[\w\s])</string>
+ <string>\bqq\s*([^\(\{\[\<\w\s])</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -1761,7 +1800,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqx([^'\(\{\[\w\s])</string>
+ <string>\bqx\s*([^'\(\{\[\<\w\s])</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -1796,7 +1835,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqx'</string>
+ <string>\bqx\s*'</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -1862,7 +1901,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqw?([^\(\{\[\w\s])</string>
+ <string>\bqw?\s*([^\(\{\[\<\w\s])</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -1961,7 +2000,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqq\(</string>
+ <string>\bqq\s*\(</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -2000,7 +2039,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqq\{</string>
+ <string>\bqq\s*\{</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -2039,7 +2078,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqq\[</string>
+ <string>\bqq\s*\[</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -2078,7 +2117,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqx\(</string>
+ <string>\bqq\s*\<</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -2088,6 +2127,45 @@
</dict>
</dict>
<key>end</key>
+ <string>\></string>
+ <key>endCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.string.end.perl</string>
+ </dict>
+ </dict>
+ <key>name</key>
+ <string>string.quoted.other.qq-ltgt.perl</string>
+ <key>patterns</key>
+ <array>
+ <dict>
+ <key>include</key>
+ <string>#escaped_char</string>
+ </dict>
+ <dict>
+ <key>include</key>
+ <string>#nested_ltgt_interpolated</string>
+ </dict>
+ <dict>
+ <key>include</key>
+ <string>#variable</string>
+ </dict>
+ </array>
+ </dict>
+ <dict>
+ <key>begin</key>
+ <string>\bqx\s*\(</string>
+ <key>beginCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.string.begin.perl</string>
+ </dict>
+ </dict>
+ <key>end</key>
<string>\)</string>
<key>endCaptures</key>
<dict>
@@ -2117,7 +2195,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqx\{</string>
+ <string>\bqx\s*\{</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -2156,7 +2234,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqx\[</string>
+ <string>\bqx\s*\[</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -2195,7 +2273,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqw?\(</string>
+ <string>\bqx\s*\<</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -2205,6 +2283,45 @@
</dict>
</dict>
<key>end</key>
+ <string>\></string>
+ <key>endCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.string.end.perl</string>
+ </dict>
+ </dict>
+ <key>name</key>
+ <string>string.interpolated.qx-ltgt.perl</string>
+ <key>patterns</key>
+ <array>
+ <dict>
+ <key>include</key>
+ <string>#escaped_char</string>
+ </dict>
+ <dict>
+ <key>include</key>
+ <string>#nested_ltgt_interpolated</string>
+ </dict>
+ <dict>
+ <key>include</key>
+ <string>#variable</string>
+ </dict>
+ </array>
+ </dict>
+ <dict>
+ <key>begin</key>
+ <string>\bqw?\s*\(</string>
+ <key>beginCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.string.begin.perl</string>
+ </dict>
+ </dict>
+ <key>end</key>
<string>\)</string>
<key>endCaptures</key>
<dict>
@@ -2230,7 +2347,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqw?\{</string>
+ <string>\bqw?\s*\{</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -2265,7 +2382,7 @@
</dict>
<dict>
<key>begin</key>
- <string>\bqw?\[</string>
+ <string>\bqw?\s*\[</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
@@ -2300,6 +2417,41 @@
</dict>
<dict>
<key>begin</key>
+ <string>\bqw?\s*\<</string>
+ <key>beginCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.string.begin.perl</string>
+ </dict>
+ </dict>
+ <key>end</key>
+ <string>\></string>
+ <key>endCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.string.end.perl</string>
+ </dict>
+ </dict>
+ <key>name</key>
+ <string>string.quoted.other.q-ltgt.perl</string>
+ <key>patterns</key>
+ <array>
+ <dict>
+ <key>include</key>
+ <string>#escaped_char</string>
+ </dict>
+ <dict>
+ <key>include</key>
+ <string>#nested_ltgt</string>
+ </dict>
+ </array>
+ </dict>
+ <dict>
+ <key>begin</key>
<string>^__\w+__</string>
<key>beginCaptures</key>
<dict>
-------------- next part --------------
#!/usr/bin/env perl -l
# recent:
# <> delimiters for q, qq, qw, qx, m
# whitespace before delimiters (broken for s///)
# fixed s[][]
# fixed s()()
my $foo = "WRONG";
my $bar = 'right';
# variables can have braces
print "** variables with braces";
print ${bar};
print;
# double-quoted -- $bar should be highlighted
print "** double-quoted strings";
print "this is $bar";
print qq{this is $bar};
print qq {some${bar}thing};
print qq~this is $bar~;
print qq ~this is $bar~;
print qq(this is $bar);
print qq (this is (this is $bar));
print qq{this is {this is (this is $bar)}};
print qx{echo -n 'this is $bar'};
print qx {echo -n 'this is $bar'};
print `echo -n this is $bar`;
print qq'this is $bar';
print qq 'this is $bar';
print qq<this is $bar>;
print qq <this is $bar>;
print eval{qqwrongw}; # should not be a string\n
print eval{qq{right}};
print <<END;
this is $bar
END
# END should not be a string
# print << END;
# this is $bar
# END
# single-quoted -- $foo should *not* be highlighted
print "** single-quoted strings";
print 'this is $foo';
print q{this is $foo};
print q {this is $foo};
print q~this is $foo~;
print q ~this is $foo~;
print q/this is $foo/;
print q /this is $foo/;
print q<this is $foo>;
print q <this is $foo>;
print q{this is {nested $foo}};
print qx'echo -n this is eaten by the shell: $foo';
print qx 'echo -n eaten: $foo';
print(join(" ", qw/this is $foo/));
print(join(" ", qw'this is $foo'));
print eval{qwrongw}; # should not be a string
print <<'END';
this is $foo
END
# regex
m/bar/;
m{bar};
m(bar);
m[bar];
m<bar>;
/this is $foo/;
qr/this is $bar/; # interpolated
qr /this is $bar/;
qr'this is $foo'; # not interpolated
qr 'this is $foo';
qr<this is $bar>;
qr <this is $bar>;
qr{this is $bar};
qr {this is $bar};
qr(this is $bar);
qr (this is $bar);
eval{qrthisismonkeyt}; # should not be a regex
s{bar}{this is $bar}; # second part should be a double-quoted string (?)
s'bar'this is $foo'; # second part should be a single-quoted string
s/some$bar/is interpolated/;
s/some$/is not interpolated/;
s/bar/this is $bar/;
s/bar/$m = "monkey"/e; # second part should be an expression
s<this><that>;
s <this><that>;
s[this][that];
s [this][that];
s{this}{that};
s {this}{that};
s(this)(that);
s (this)(that);
# broken
s /bar/foo/;
s#this#that#;
s #this#that#;
tr{abc}{def}; #too much work
s/bar/foo/ #comment
;
s{bar}{foo} #comment
;
s 'bar'this is $foo';
More information about the textmate
mailing list