Is the grammar spec usable for generating parsers?

Iain Buclaw ibuclaw at gdcproject.org
Sat Nov 3 22:29:59 UTC 2018


On Sat, 3 Nov 2018 at 23:20, Peter Alexander via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> 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?

First have a look here, from memory I ended up basing the D grammar in
gdb on this version instead.

https://libdparse.dlang.io/grammar.html

-- 
Iain


More information about the Digitalmars-d mailing list