On 6 April 2016 at 22:14, Jacob Carlborg <doob(a)me.com> wrote:
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
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?
I tried to approximate something like this with my Maude grammar.
It's been a while, but I believe the basic idea was to split scopes into
parts using lookaheads and -behinds and to include specific rules there.
Take #equation as an example: An equation begins with `eq` and ends with
`.`, but in between I can differentiate the left hand side from the
right hand side using (entirely too many) lookarounds.
Of course this only works because I can use `==` as a kind of anchor in
between, I'm assuming most rules of the grammar you quoted above don't
include any meaningful symbols but are mostly one (or, worse, possibly
So this approach probably won't help you that much. It's just as far as I got.