On Saturday, 3 August 2013 at 09:24:25 UTC, Bosak wrote:
"The D Programming Language" is kind of old and out of date for
the current version of D. There aren't many books for D so you
have not much choice.
Attributes can be declared with 3 different syntaxes. For
example one could write:
//--1--
/*Explicitly state attribute before every declaration*/
public int number;
public string name;
//--2--
/*State the attribute and then curly brackets and all the
declarations inside have the attribute specified. Also note
that those brackets don't introduce a new scope*/
public
{
    int number;
    string name;
}
//--3--
/*Use C++ style atributes. All the declarations after the attribute declaration have the attribute. If you declare another attribute the same way after that, then the old attribute is replaced with the new one for the declarations that follow*/
public:
    int number;
    string value;
private:
    //everything below is private

Thank you Bosak, I managed to glean as much from the 'Attributes'[http://dlang.org/attribute.htm] page. What tripped me up is the redundancy in the 'import' declaration [http://dlang.org/module.html#ImportDeclaration].

If you follow the documentation (as it currently stands) to it's conclusion then the following should be valid D:

static {
  *static* import teleport;
  *static* import time_travel, warp;
}

--AND--

static:
  *static* import teleport;
  *static* import time_travel, warp;


Whereas all the following constructions can just as easily be parsed when the 'static import ImportList ;' production is removed from 'ImportDeclaration'.

static {
  import teleport;
  public import time_travel, warp;
}

static:
  import teleport;
  public import time_travel, warp;

public:
  import teleport;
  static import time_travel, warp;

private:
  import teleport;
  static import time_travel, warp;

along with the more standard fare:

import std.stdio;
import phobos.std.stdio;
import foo, bar;
static import stat.std.stdio;
public import pub.stdio;
static import teleport, time_travel, warp;
import list = util.container.finite.linear.list;
import widget : fun, gun;
import std.stdio : writefln, foo = writef;


The only issue for the parser is that I need to keep track of the implied block for the 'Attribute :' construction. By that I mean that the parse trees for X in 'public { X }' and 'public: X' should probably be indistinguishable, and naively rewriting 'Attribute :' into 'Attribute : DeclDefs?' will not do.

Reply via email to