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

Allan Odgaard mailinglist at textmate.org
Sun Apr 21 09:03:13 UTC 2013


On Apr 19, 2013, at 0:28, Phil Schumm <pschumm at uchicago.edu> wrote:

> […] As I'm thinking about this now, it seems that it would be ideal if I could define the prefix (which itself requires a rather complicated regex) in one place, and then refer to that in other places, such as where a specific command that can follow a prefix is defined.  I am familiar with the language repository and have used it for recursive constructs and to embed one grammar within another, but can't figure out how it might be used here (if at all).

I’m having a hard time following the requirements here.

You have two patterns, ‘prefix’ and ‘cmd’.

Can these be made into two rules that are placed in the repository and included where needed?

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?!?

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’.



More information about the textmate mailing list