[TxMt] Modifying the embedded SQL rule in the PHP language bundle

Quinn Comendant quinn at strangecode.com
Tue Jul 29 18:34:57 UTC 2014

I want to modify the regex in the PHP language bundle item that applies the meta.embedded.sql scope to a string. I did this successfully in TM1, but with TM2 I opted to start with a fresh set of bundles and have been having trouble adding this functionality back in.

The PHP code continuing a string of SQL is this:

        UPDATE table
        SET foo = bar
        WHERE foo = '" . function($variable) . "'

I tried many variations of the following, added just below the existing meta.embedded.sql rule:

    {	name = 'meta.embedded.sql';
    	begin = '(\$db)->(query)\((")';
    	end = '(\3)\);';
    	beginCaptures = {
    		0 = { name = 'variable.other.php'; };
    		1 = { name = 'meta.function-call.object.php'; };
    		2 = { name = 'string.quoted.double.php'; };
    	endCaptures = {
    		0 = { name = 'string.quoted.double.php'; };
    	contentName = 'source.sql';
    	patterns = ( { include = 'source.sql'; } );

I've even tried simplifying it with only the 'name,' 'begin,' and 'end' and the scope isn't applied where I'd expect it. I can't see why. 

I also found this rule (here is only a portion), which I thought I would modify:

    name = 'string.quoted.double.sql.php';

I tried changing this to:


so that it would match the code example above, but the regex doesn't seem to be matching over multiple lines; it only works if the quote mark is on the same line as the UPDATE.

Can somebody please show me how to do this (with whichever of the above rules is more better)?

Once I get a working rule, I would like to add this to a custom bundle that includes the default PHP grammar and adds this modification to it so that I have a stock PHP bundle that is unmodified. Does anybody have an example of an extended PHP bundle so I can see how this should be done?

Thanks thanks,

More information about the textmate mailing list