[TxMt] Composable grammars

Jacob Carlborg doob at me.com
Wed Apr 6 20:14:46 UTC 2016

I've been working for quite a while with trying to rewrite the grammar 
for the D bundle to be more accurate to the official grammar. The 
grammar for D is quite complex, that in the combination with the syntax 
for grammars in TextMate doesn't allow any good ways to reuse or compose 
rules making it very difficult to describe a grammar. I know it's 
possible to reuse rules with the repository, but that seems to be mostly 
useful when matching with "begin" and "end".

For example, this is the grammar for a function declaration from the 
official D grammar:

     StorageClasses(opt) BasicType FuncDeclarator FunctionBody

     StorageClasses Identifier FuncDeclaratorSuffix FunctionBody

     BasicType2(opt) Identifier FuncDeclaratorSuffix

     Parameters MemberFunctionAttributes(opt)
     TemplateParameters Parameters MemberFunctionAttributes(opt) 

Each of these parts/rules of the grammar consists of several other 
rules, many levels deep.

It would be really nice if the TextMate grammar syntax allowed, somehow, 
to define rules, or parts of a rule, which the other rules can be 
composed of, similar to above.

Or is there a way to already do something similar with the current syntax?

/Jacob Carlborg

More information about the textmate mailing list