Mercurial > projects > dil
changeset 365:ed67acc82268
- Added option includes to config.d.
- Added methods getName() and getPackageName() to class ModuleDeclaration.
- Added method isNonReservedIdentifier() to class Lexer.
- Added private member parser to class Module.
- Initializing members moduleName and packageName in Module.parse().
author | aziz |
---|---|
date | Fri, 31 Aug 2007 11:07:05 +0000 |
parents | 1059295c2727 |
children | dcbd3bf9bf74 |
files | trunk/src/cmd/ImportGraph.d trunk/src/config.d trunk/src/dil/Declarations.d trunk/src/dil/Lexer.d trunk/src/dil/Module.d |
diffstat | 5 files changed, 54 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/cmd/ImportGraph.d Fri Aug 31 00:53:00 2007 +0000 +++ b/trunk/src/cmd/ImportGraph.d Fri Aug 31 11:07:05 2007 +0000 @@ -13,6 +13,7 @@ void execute(string fileName) { auto mod = new Module(fileName); + mod.parse(); auto root = mod.root; Module[] modules;
--- a/trunk/src/config.d Fri Aug 31 00:53:00 2007 +0000 +++ b/trunk/src/config.d Fri Aug 31 11:07:05 2007 +0000 @@ -1,1 +1,2 @@ option langfile = "lang_en.d"; +option includes = [];
--- a/trunk/src/dil/Declarations.d Fri Aug 31 00:53:00 2007 +0000 +++ b/trunk/src/dil/Declarations.d Fri Aug 31 11:07:05 2007 +0000 @@ -69,11 +69,26 @@ { super(false); mixin(set_kind); - if (moduleFQN.length) - { - this.moduleName = moduleFQN[$-1]; - this.packages = moduleFQN[0..$-1]; - } + assert(moduleFQN.length != 0); + this.moduleName = moduleFQN[$-1]; + this.packages = moduleFQN[0..$-1]; + } + + string getName() + { + if (moduleName) + return moduleName.identifier; + return null; + } + + string getPackageName(char separator) + { + char[] pname; + foreach (pckg; packages) + if (pckg) + pname ~= pckg.identifier ~ separator; + pname = pname[0..$-1]; + return pname; } }
--- a/trunk/src/dil/Lexer.d Fri Aug 31 00:53:00 2007 +0000 +++ b/trunk/src/dil/Lexer.d Fri Aug 31 11:07:05 2007 +0000 @@ -1658,6 +1658,23 @@ return head; } + static bool isNonReservedIdentifier(char[] ident) + { + static Identifier[string] reserved_ids_table; + if (reserved_ids_table is null) + foreach(k; keywords) + reserved_ids_table[k.str] = k; + + try + foreach (dchar c; ident) + if (!isident(c) && !isUniAlpha(c)) + return false; + catch (Exception e) + return false; + + return !(ident in reserved_ids_table); + } + private void encodeUTF8(inout char[] str, dchar d) { char[6] b;
--- a/trunk/src/dil/Module.d Fri Aug 31 00:53:00 2007 +0000 +++ b/trunk/src/dil/Module.d Fri Aug 31 11:07:05 2007 +0000 @@ -6,7 +6,9 @@ import dil.SyntaxTree; import dil.Declarations; import dil.Parser; +import dil.Lexer; import dil.File; +import std.path; class Module { @@ -16,6 +18,7 @@ Declarations root; /// The root of the AST. ImportDeclaration[] imports; ModuleDeclaration moduleDecl; + private Parser parser; this(string fileName) { @@ -25,7 +28,7 @@ void parse() { auto sourceText = loadFile(fileName); - auto parser = new Parser(sourceText, fileName); + this.parser = new Parser(sourceText, fileName); parser.start(); this.root = parser.parseModule(); @@ -34,6 +37,17 @@ { // moduleDecl will be null if first node can't be casted to ModuleDeclaration. this.moduleDecl = Cast!(ModuleDeclaration)(root.children[0]); + if (moduleDecl) + { + this.moduleName = moduleDecl.getName(); + this.packageName = moduleDecl.getPackageName('/'); + } + else + { + auto str = getBaseName(getName(fileName)); + if (Lexer.isNonReservedIdentifier(str)) + this.moduleName = str; + } this.imports = parser.imports; }