Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 03, 2018 Is the grammar spec usable for generating parsers? | ||||
---|---|---|---|---|
| ||||
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? |
November 03, 2018 Re: Is the grammar spec usable for generating parsers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | 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 |
November 03, 2018 Re: Is the grammar spec usable for generating parsers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Iain Buclaw | 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.html
Thanks.
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.
|
November 04, 2018 Re: Is the grammar spec usable for generating parsers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | 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: > > 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 > > Thanks. > > 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. 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. -- Iain |
Copyright © 1999-2021 by the D Language Foundation