[TxMt] Bug in perl syntax?

Grant Hollingworth grant at antiflux.org
Thu Feb 15 17:01:19 UTC 2007


* Allan Odgaard <throw-away-1 at macromates.com> [2007-02-14 21:37]:
>I assume variables are allowed in regexps?
>
>So likely Perl distinguish between end-of-line-$ and start-of- 
>variable-$ by what follows the character? We could make the regexp  
>variable rule do the same in TM.

Right.  The problem is that Perl allows almost any punctuation character to be a regexp delimiter.  For paired delimiters we specify the end character explicitly:

  name = 'string.regexp.compile.nested_braces.perl';
	begin = '(qr)\s*\{';
	end = '\}';
	captures = {
		0 = { name = 'punctuation.definition.string.perl'; };
		1 = { name = 'support.function.perl'; };
	};
	patterns = (
		{	include = '#escaped_char'; },
		{	include = '#variable'; },
		{	include = '#nested_braces_interpolated'; },
	);
	
Here, including the variable pattern works properly.

For single-character delimiters, we define the end character as \2 from the match:

  name = 'string.regexp.compile.simple-delimiter.perl';
	begin = "(qr)\s*([^\s\w\'\{\[\(\<])";
	end = '\2';
	captures = {
		0 = { name = 'punctuation.definition.string.perl'; };
		1 = { name = 'support.function.perl'; };
	};
	patterns = (
		{	include = '#escaped_char'; },
		{	include = '#variable'; },
		{	include = '#nested_parens_interpolated'; },
	);

Here, the variable pattern seems to have precedence over \2.



More information about the textmate mailing list