Hello D-world!

My name is Andre Artus, and I'm a programmer from Johannesburg, South Africa.

I'm relatively new to D, but so far quite impressed by it. I have been reading Andrei Alexandrescu's "The D Programming Language" and Ali Çehreli's "Programming in D" to get up to speed. Both are quite good.

1st Q: Are there other S'frican D'philes on this forum?

2nd Q:

I have noticed Andrei's use of the following construct with regard to static imports (p 346):

static {
  import teleport;
  import time_travel, warp;
}

This does not seem to comport with the grammar specified here:
http://dlang.org/module.html#ImportDeclaration

Is this a deprecated or (fringe| unblessed) form?

Andrei's book, and the aforementioned page (module.html) mentions "public imports", which are also absent from the ImportDeclaration.

I have put together an ANTLR4 grammar for the import declarations, but would like to amend it to reflect the correct grammar rules.

grammar DLanguageGrammar;

WS             : [\u0020\u0009\u000b\u000c\u000a\u000d]+ -> skip;
ASSIGN          : '=';
COLON           : ':';
COMMA           : ',';
IMPORT          : 'import';
PUBLIC          : 'public';
SEMICOLON       : ';';
STATIC          : 'static';

//I realize this probably does not cover universal alpha,
// will burn that bridge at some later date.
Identifier : [a-zA-Z_]([a-zA-Z0-9_])*;


importDeclaration:
   (PUBLIC | STATIC)?
   IMPORT importList SEMICOLON
    ;

importList:
    simpleImport (COMMA simpleImport)*
    | importBindings
    ;

simpleImport:
    moduleAliasIdentifier ASSIGN moduleFullyQualifiedName
    | moduleFullyQualifiedName
    ;

importBindings:
    simpleImport COLON importBindList
    ;

importBindList:
    importBind (COMMA importBind)*
    ;
importBind:
    Identifier (ASSIGN Identifier)?
    ;

This seems to work fine against the following:
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;

But will of course not work against,
static {
  import teleport;
  import time_travel, warp;
}

is there a similar construct for public, e.g.

public {
  import teleport;
  import time_travel, warp;
}

Thanks,

Andre

Reply via email to