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:
$db->query(" 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'; begin = '"\s*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER)\b)';
I tried changing this to:
begin = '"[\s\n\r]*(?=(SELECT|INSERT|UPDATE|DELETE|CREATE|REPLACE|ALTER)\b)';
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, Quinn
On 29 Jul 2014, at 20:34, Quinn Comendant wrote:
[…] I tried many variations of the following, added just below the existing meta.embedded.sql rule
I only see one rule with that name, it is included as part of `heredoc_interior`.
So I think you’re adding it in the wrong place.
It should probably go somehwere in the `patterns` array under `repository` → `language` (for me that starts at line 500 and the first rule in that array is for comments).
On Thu, 31 Jul 2014 13:05:52 +0200, Allan Odgaard wrote:
[…] I tried many variations of the following, added just below the existing meta.embedded.sql rule
I only see one rule with that name, it is included as part of `heredoc_interior`.
I mean _I_ added it just below the existing meta.embedded.sql rule, like this:
{ name = 'meta.embedded.sql'; begin = '(<<<)\s*([''"]?)(SQL)(\2)\s*$\n?'; end = '^(\3)\b'; beginCaptures = { 0 = { name = 'punctuation.section.embedded.begin.php'; }; 1 = { name = 'punctuation.definition.string.php'; }; 3 = { name = 'keyword.operator.heredoc.php'; }; }; endCaptures = { 0 = { name = 'punctuation.section.embedded.end.php'; }; 1 = { name = 'keyword.operator.heredoc.php'; }; }; contentName = 'source.sql'; patterns = ( { include = 'source.sql'; } ); }, { 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'; } ); },
The first one is stock, the second a custom rule. Or is it illegal to have two rules with the same 'name'? Clearly I've forgotten how to do this correctly, any advice is appreciated.
Quinn
On 31 Jul 2014, at 15:52, Quinn Comendant wrote:
On Thu, 31 Jul 2014 13:05:52 +0200, Allan Odgaard wrote:
[…] I tried many variations of the following, added just below the existing meta.embedded.sql rule
I only see one rule with that name, it is included as part of `heredoc_interior`.
I mean _I_ added it just below the existing meta.embedded.sql rule, like this:
I am saying that you are adding the rule in the wrong place.
It should NOT go after meta.embedded.sql unless you only want it active in a here-doc context.
As written in the other mail, you want to add it after line 500.
On Thu, 31 Jul 2014 16:44:34 +0200, Allan Odgaard wrote:
It should NOT go after meta.embedded.sql unless you only want it active in a here-doc context.
Oh, got it—that makes sense. I got it working by adding this in the `patterns` array under `repository` → `language`:
{ name = 'meta.embedded.sql'; begin = '(?:mysql_query|dbQuery|DB(::)query|($db)(->)(query))('; end = ');'; beginCaptures = { 1 = { name = 'keyword.operator.php'; }; 2 = { name = 'variable.other.php'; }; 3 = { name = 'keyword.operator.php'; }; 4 = { name = 'meta.function-call.object.php'; }; }; contentName = 'source.sql'; patterns = ( { name = 'string.quoted.double.php'; contentName = 'source.sql.embedded'; begin = '"'; end = '"'; patterns = ( { match = '\.'; }, { match = "'"; }, { include = 'source.sql'; }, { include = '#var_global'; }, ); }, { include = '$self'; }, { include = 'source.sql'; } ); },