[TxMt] Re: question RE code reuse in language grammar

Phil Schumm pschumm at uchicago.edu
Sun Apr 21 16:14:18 UTC 2013


On Apr 21, 2013, at 4:03 AM, Allan Odgaard wrote:
> You have two patterns, ‘prefix’ and ‘cmd’.
> 
> Can these be made into two rules that are placed in the repository and included where needed?


Yes, that's what I'd like to do -- I just can't figure out how to put them together.


> I have a feeling that the issue is the ordering, e.g. sometimes you want to force ‘cmd’ to be anchored to a previous ‘prefix’ match, and othertimes you do not?!?


Exactly.


> There is some support for anchoring mathces in 2.0 by using \G in the pattern. This’ll anchor the match to the end of the previous match, a simple example:
> 
>  { begin    = 'st';
>    end      = '$';
>    patterns = (
>      { match = '\Gart'; name = 'meta.innert'; }
>    );
>  };
> 
> This will match: ‘start' and ‘st art’, but only in the first case, will ‘art’ be scoped as ‘meta.inner’.


Thanks -- knowing about \G is great.  Now in your example, what if 'art' were in the repository?  Could I do the following:

    { begin    = 'st';
      end      = '$';
      patterns = ( { include = '#art'; } );
    }

where in the repository I have

    art = {
        name  = 'meta.innert';
        match = '\Gart';
    }

Finally, suppose 'art' were also valid at the beginning of a line?  It seems like if I wanted to reuse the definition (including the scope), I would add:

    { begin    = '^';
      end      = '$';
      patterns = ( { include = '#art'; } );
    }

Does that make sense?  Moreover, since this would then match every line in the file, would there be a substantial speed hit?


-- Phil



More information about the textmate mailing list