[TxMt] [PATCH] perl quote-like operators

Grant Hollingworth grant at antiflux.org
Thu Nov 16 06:38:15 UTC 2006


* Grant Hollingworth <grant at antiflux.org> [2006-11-15 23:23]:
>I fixed up the scoping and interpolation of some of Perl's quote-like 
>operators: q//, qq//, qw//, qx//, and m//. s///, tr///, and heredocs still 
>need some work.

oops.  The test script had a syntax error, and qw// isn't interpolated.
-------------- next part --------------
#!/usr/bin/env perl -l

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 (this is $bar));
print qq{this is {this is (this is $bar)}};
print qx{echo -n 'this is $bar'};
print `echo -n 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 {nested $foo}};
print qx'echo -n this is eaten by the shell: $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];
qr/this is $bar/; # interpolated
qr'this is $foo'; # not interpolated
qr{this is monkey};
qr(this is monkey);
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/bar/foo/;  # ditto
tr{abc}{def}; #too much work

s/bar/foo/ #comment
;
s{bar}{foo} #comment
;
-------------- next part --------------
Index: info.plist
===================================================================
--- info.plist	(revision 6150)
+++ info.plist	(working copy)
@@ -44,7 +44,6 @@
 	<key>ordering</key>
 	<array>
 		<string>2F3DB2EF-6B9E-4E5F-87A8-3675680E5C0D</string>
-		<string>02196551-D037-4254-8A2F-7A075A628EF1</string>
 		<string>DA0A5F4B-5F16-11D9-B9C3-000D93589AF6</string>
 		<string>DA0A6096-5F16-11D9-B9C3-000D93589AF6</string>
 		<string>CF2CA4F9-82A7-11D9-8753-000D9332809C</string>
@@ -68,9 +67,9 @@
 		<string>4FB403FC-F441-447F-9AAD-E2BE13AD49ED</string>
 		<string>CEE866A5-FA4B-4C5D-A80C-137A620E825E</string>
 		<string>4F1B9AE2-F90C-4A1B-B7D0-FE59D236B12B</string>
-		<string>A08E9AF5-1D0A-48C9-A7A9-25C1E59B02A7</string>
 		<string>EDBFE125-6B1C-11D9-9189-000D93589AF6</string>
 		<string>C1EE8DC8-117D-4BC6-8E69-97D51EAA58D2</string>
+		<string>1B0FB64D-63C1-469E-B0B6-945477603B01</string>
 	</array>
 	<key>uuid</key>
 	<string>4679B572-6227-11D9-BFB1-000D93589AF6</string>
Index: Syntaxes/Perl.plist
===================================================================
--- Syntaxes/Perl.plist	(revision 6150)
+++ Syntaxes/Perl.plist	(working copy)
@@ -1023,11 +1023,128 @@
 				</dict>
 			</dict>
 			<key>match</key>
-			<string>\b(m)\s*(?<!\\)([^A-Za-z0-9\s])(.*?)(?<!\\)(\\{2})*(\2)</string>
+			<string>\b(m)\s*(?<!\\)([^\[\{\(A-Za-z0-9\s])(.*?)(?<!\\)(\\{2})*(\2)</string>
 			<key>name</key>
 			<string>string.regexp.find-m.perl</string>
 		</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-paren.perl</string>
+			<key>patterns</key>
+			<array>
+				<dict>
+					<key>include</key>
+					<string>#escaped_char</string>
+				</dict>
+				<dict>
+					<key>include</key>
+					<string>#nested_parens_interpolated</string>
+				</dict>
+				<dict>
+					<key>include</key>
+					<string>#variable</string>
+				</dict>
+			</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-brace.perl</string>
+			<key>patterns</key>
+			<array>
+				<dict>
+					<key>include</key>
+					<string>#escaped_char</string>
+				</dict>
+				<dict>
+					<key>include</key>
+					<string>#nested_braces_interpolated</string>
+				</dict>
+				<dict>
+					<key>include</key>
+					<string>#variable</string>
+				</dict>
+			</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-bracket.perl</string>
+			<key>patterns</key>
+			<array>
+				<dict>
+					<key>include</key>
+					<string>#escaped_char</string>
+				</dict>
+				<dict>
+					<key>include</key>
+					<string>#nested_brackets_interpolated</string>
+				</dict>
+				<dict>
+					<key>include</key>
+					<string>#variable</string>
+				</dict>
+			</array>
+		</dict>
+		<dict>
 			<key>captures</key>
 			<dict>
 				<key>1</key>
@@ -1609,7 +1726,7 @@
 		</dict>
 		<dict>
 			<key>begin</key>
-			<string>\bqq([^\(\{\[])</string>
+			<string>\bqq([^\(\{\[\w\s])</string>
 			<key>beginCaptures</key>
 			<dict>
 				<key>0</key>
@@ -1644,6 +1761,41 @@
 		</dict>
 		<dict>
 			<key>begin</key>
+			<string>\bq[wx]([^'\(\{\[\w\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>\1</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.double.q.perl</string>
+			<key>patterns</key>
+			<array>
+				<dict>
+					<key>include</key>
+					<string>#escaped_char</string>
+				</dict>
+				<dict>
+					<key>include</key>
+					<string>#variable</string>
+				</dict>
+			</array>
+		</dict>
+		<dict>
+			<key>begin</key>
 			<string>"</string>
 			<key>beginCaptures</key>
 			<dict>
@@ -1679,6 +1831,37 @@
 		</dict>
 		<dict>
 			<key>begin</key>
+			<string>\bq([^\(\{\[\w\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>\1</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.single.q.perl</string>
+			<key>patterns</key>
+			<array>
+				<dict>
+					<key>include</key>
+					<string>#escaped_char</string>
+				</dict>
+			</array>
+		</dict>
+		<dict>
+			<key>begin</key>
 			<string>'</string>
 			<key>beginCaptures</key>
 			<dict>
@@ -1747,7 +1930,7 @@
 		</dict>
 		<dict>
 			<key>begin</key>
-			<string>\bq[qwx]*\(</string>
+			<string>\bq[qwx]\(</string>
 			<key>beginCaptures</key>
 			<dict>
 				<key>0</key>
@@ -1776,13 +1959,17 @@
 				</dict>
 				<dict>
 					<key>include</key>
-					<string>#nested_parens</string>
+					<string>#nested_parens_interpolated</string>
 				</dict>
+				<dict>
+					<key>include</key>
+					<string>#variable</string>
+				</dict>
 			</array>
 		</dict>
 		<dict>
 			<key>begin</key>
-			<string>\bq[qwx]*\{</string>
+			<string>\bq[qwx]\{</string>
 			<key>beginCaptures</key>
 			<dict>
 				<key>0</key>
@@ -1811,13 +1998,17 @@
 				</dict>
 				<dict>
 					<key>include</key>
-					<string>#nested_braces</string>
+					<string>#nested_braces_interpolated</string>
 				</dict>
+				<dict>
+					<key>include</key>
+					<string>#variable</string>
+				</dict>
 			</array>
 		</dict>
 		<dict>
 			<key>begin</key>
-			<string>\bq[qwx]*\[</string>
+			<string>\bq[qwx]\[</string>
 			<key>beginCaptures</key>
 			<dict>
 				<key>0</key>
@@ -1846,6 +2037,115 @@
 				</dict>
 				<dict>
 					<key>include</key>
+					<string>#nested_brackets_interpolated</string>
+				</dict>
+				<dict>
+					<key>include</key>
+					<string>#variable</string>
+				</dict>
+			</array>
+		</dict>
+		<dict>
+			<key>begin</key>
+			<string>\bq\(</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.single.q-paren.perl</string>
+			<key>patterns</key>
+			<array>
+				<dict>
+					<key>include</key>
+					<string>#escaped_char</string>
+				</dict>
+				<dict>
+					<key>include</key>
+					<string>#nested_parens</string>
+				</dict>
+			</array>
+		</dict>
+		<dict>
+			<key>begin</key>
+			<string>\bq\{</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.single.q-brace.perl</string>
+			<key>patterns</key>
+			<array>
+				<dict>
+					<key>include</key>
+					<string>#escaped_char</string>
+				</dict>
+				<dict>
+					<key>include</key>
+					<string>#nested_braces</string>
+				</dict>
+			</array>
+		</dict>
+		<dict>
+			<key>begin</key>
+			<string>\bq\[</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.single.q-bracket.perl</string>
+			<key>patterns</key>
+			<array>
+				<dict>
+					<key>include</key>
+					<string>#escaped_char</string>
+				</dict>
+				<dict>
+					<key>include</key>
 					<string>#nested_brackets</string>
 				</dict>
 			</array>
@@ -2310,8 +2610,27 @@
 							<key>name</key>
 							<string>punctuation.definition.variable.perl</string>
 						</dict>
+						<key>2</key>
+						<dict>
+							<key>name</key>
+							<string>punctuation.definition.variable.perl</string>
+						</dict>
 					</dict>
 					<key>match</key>
+					<string>(\$\{)(?:[a-zA-Zx7f-xff\$]|::)(?:[a-zA-Z0-9_x7f-xff\$]|::)*(\})</string>
+					<key>name</key>
+					<string>variable.other.readwrite.global.perl</string>
+				</dict>
+				<dict>
+					<key>captures</key>
+					<dict>
+						<key>1</key>
+						<dict>
+							<key>name</key>
+							<string>punctuation.definition.variable.perl</string>
+						</dict>
+					</dict>
+					<key>match</key>
 					<string>([\$\@\%](#)?)[0-9_]\b</string>
 					<key>name</key>
 					<string>variable.other.readwrite.global.special.perl</string>


More information about the textmate mailing list