Re(2): [TxMt] excluding match from language pattern

Quinn Comendant quinn at strangecode.com
Wed Mar 8 08:10:06 UTC 2006


On Tue, 7 Mar 2006 16:47:55 +0100, Allan Odgaard wrote:

[...]

>I have written an example of matching the first construct below, let  
>me know if you have further questions.
>
>    {  begin = '(\$sql) = '; end = ';';

[...]


Thanks Allan

But it doesn't work correctly yet. It _does_ apply source.sql to the
contents of the double-quoted string, but most everything else breaks.
Here is a more specific example to describe what is wrong...

$sql = "SELECT * FROM some_tbl WHERE foo = '$foo' AND bar = '" . $this-
>bar() . "'";

Problem 1: The SQL is treated as a double quoted string, which it is,
but I want source.sql.embedded to override string.quoted.double.php. I
added contentName = 'source.sql.embedded'; and now it works.

Problem 2: $foo should be variable.other.php. Ok, I think I know how to
do this, using captures, right? Or maybe even better would be to use {	
include = '#var_basic'; }? Nope, none of those work.

Problem 3: '" . $this->bar() . "' should be source.php but instead it
considers it a string.quoted.single.php

I solved the last two problems by adding {	match = "'"; }, but I have no
more than an intuitive sense why this works. What does it mean to use a
pattern with only a "match" statement? What is "\\."? But there is a
problem with this solution: it doesn't allow for single-quoted strings
here, for example if '$foo' needs to be 'foo'.

In the end here is what I came up with:

{   begin = '(\$\w*(?:sql|where)\w*)\s*=\s*';
    end = ';';
    beginCaptures = { 1 = { name = 'variable.other.php'; }; };
    patterns = (
        {   name = 'string.quoted.double.php';
            begin = '"';
            end = '"';
            patterns = (
                {   match = '\\.'; },
                {   match = "'"; },
                {   include = 'source.sql'; },
                {   include = '#var_global'; },
            );
            contentName = 'source.sql.embedded';
        },
        {   include = '$self'; },
    );
},


Unrelated question: what is "swallow"? It seems to be undocumented.

And how far is it to the moon? In miles - how far? And what is the principle 
element in the composition of moon rock? And what is the electric bill
of the white house? And how do you make vegan bread pudding?

Q




More information about the textmate mailing list