Is the grammar spec usable for generating parsers?

Peter Alexander peter.alexander.au at gmail.com
Sat Nov 3 22:15:09 UTC 2018


I'm writing D support for tree-sitter 
(http://tree-sitter.github.io/tree-sitter/) using the grammar 
from the spec (https://dlang.org/spec/grammar.html) as a guide. 
When manually converting the spec grammar to tree-sitter's 
grammar rules, I've encountered a conflict early on and I'm 
wondering if the spec can be trusted or if there is a better spec.

The conflict I encountered is with static imports, e.g.

```
static import foo;
```

This should be an ImportDeclaration, but the grammar from the 
spec would parse it as an AttributeSpecifier (static) followed by 
an ImportDeclaration, i.e. as if it were

```
static { import foo; }
```

(but without the { })

Of course, I can fix this easily enough, but I'm wondering how 
much the grammar can be trusted. Has anyone  else specified a 
more correct grammar for D?


More information about the Digitalmars-d mailing list