[TxMt] How to mark up variable length parameter lists?

Timothy Bates timothy.c.bates at gmail.com
Mon Aug 6 13:12:38 UTC 2007


God Day all,
What advice do people have for marking up a language grammar containing
statements with a variable (and potentially lengthy) list of parameters,
which are themselves morphologically complex?

I saw here  <http://macromates.com/blog/2005/language-grammars/>, the idea
of using $self to re-parse the detected fragment using the whole language
grammar

{   name = "markup.bold.html";
    begin = "<b>"; end = "</b>";
    patterns = ( // really means ³contains²
        { include = "$self"; }
    );
}

And also the idea of using a repository of named rules to direct the second
level of parsing. Are there bundles that use that and upon which which I
could base my work ?

The statements I want to match are of the form

 latentVar BY var var var var...;

This should be parsed into <variable.latent> <keyword.BY> <variable.dv>...

The tricky bit is that each variable has its own syntax and can appear n one
of three forms

 name      // <variable.name>
 name at n // <variable.name><keyword.at> <numeric.value>
 name*n  // <variable.name><keyword.start> <numeric.value>

So that each variable gets matched like this:
   \s+(\w+)((@|\*)([-\.\d]+))?\s+

A test case might be

 e1 BY item1 at 1  item2 item3*0.51;

It is obviously pretty redundant  and unmaintainable to make a big list like
that in a single rule, and ultimately not possible as the variable list
might exceed the rule's length.

Suggestions gratefully received.

Tim





More information about the textmate mailing list