digitalmars.D - Is the grammar spec usable for generating parsers?
- Peter Alexander (20/20) Nov 03 2018 I'm writing D support for tree-sitter
- Iain Buclaw (7/27) Nov 03 2018 First have a look here, from memory I ended up basing the D grammar in
- Peter Alexander (6/9) Nov 03 2018 Thanks.
- Iain Buclaw (7/17) Nov 03 2018 Ah, yes. Indeed that looks correct as per grammar. In the built up
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?
Nov 03 2018
On Sat, 3 Nov 2018 at 23:20, Peter Alexander via Digitalmars-d <digitalmars-d 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
Nov 03 2018
On Saturday, 3 November 2018 at 22:29:59 UTC, Iain Buclaw wrote: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.htmlThanks. Unfortunately, it seems that libdparse doesn't know about 'static import' and instead parses it as an importDeclaration within a 'static' attribute block. I suppose this could be re-interpreted after the parsing stage.
Nov 03 2018
On Sun, 4 Nov 2018 at 00:05, Peter Alexander via Digitalmars-d <digitalmars-d puremagic.com> wrote:On Saturday, 3 November 2018 at 22:29:59 UTC, Iain Buclaw wrote:Ah, yes. Indeed that looks correct as per grammar. In the built up parse tree, static funcDecl and static importDecl would be storing the same information, but interpreted differently in semantic. -- IainFirst have a look here, from memory I ended up basing the D grammar in gdb on this version instead. https://libdparse.dlang.io/grammar.htmlThanks. Unfortunately, it seems that libdparse doesn't know about 'static import' and instead parses it as an importDeclaration within a 'static' attribute block. I suppose this could be re-interpreted after the parsing stage.
Nov 03 2018