[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:

FuncDeclaration:
     StorageClasses(opt) BasicType FuncDeclarator FunctionBody
     AutoFuncDeclaration

AutoFuncDeclaration:
     StorageClasses Identifier FuncDeclaratorSuffix FunctionBody

FuncDeclarator:
     BasicType2(opt) Identifier FuncDeclaratorSuffix

FuncDeclaratorSuffix:
     Parameters MemberFunctionAttributes(opt)
     TemplateParameters Parameters MemberFunctionAttributes(opt) 
Constraint(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