Mercurial > projects > dil
changeset 364:1059295c2727
- Every command module has an execute method now.
- Added module cmd.ImportGraph.
- Renamed ModuleName to ModuleFQN.
- Added module dil.Module.
- Added member 'imports' to class Parser.
author | aziz |
---|---|
date | Fri, 31 Aug 2007 00:53:00 +0000 |
parents | 2b387a3c6b58 |
children | ed67acc82268 |
files | trunk/src/cmd/Generate.d trunk/src/cmd/ImportGraph.d trunk/src/cmd/Statistics.d trunk/src/dil/Declarations.d trunk/src/dil/Module.d trunk/src/dil/Parser.d trunk/src/main.d |
diffstat | 7 files changed, 104 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/cmd/Generate.d Thu Aug 30 12:02:04 2007 +0000 +++ b/trunk/src/cmd/Generate.d Fri Aug 31 00:53:00 2007 +0000 @@ -17,6 +17,14 @@ XML = 1<<3 } +void execute(string fileName, DocOption options) +{ + if (options & DocOption.Syntax) + syntaxToDoc(fileName, options); + else + tokensToDoc(fileName, options); +} + char[] xml_escape(char[] text) { char[] result;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/cmd/ImportGraph.d Fri Aug 31 00:53:00 2007 +0000 @@ -0,0 +1,24 @@ +/++ + Author: Aziz Köksal + License: GPL3 ++/ +module cmd.ImportGraph; +import dil.SyntaxTree; +import dil.Declarations; +import dil.Token; +import dil.Parser, dil.Lexer; +import dil.File; +import dil.Module; + +void execute(string fileName) +{ + auto mod = new Module(fileName); + auto root = mod.root; + + Module[] modules; + + foreach (decl; root.children) + { + + } +}
--- a/trunk/src/cmd/Statistics.d Thu Aug 30 12:02:04 2007 +0000 +++ b/trunk/src/cmd/Statistics.d Fri Aug 31 00:53:00 2007 +0000 @@ -18,7 +18,7 @@ uint commentCount; } -void statistics(string fileName) +void execute(string fileName) { auto sourceText = loadFile(fileName); auto lx = new Lexer(sourceText, fileName);
--- a/trunk/src/dil/Declarations.d Thu Aug 30 12:02:04 2007 +0000 +++ b/trunk/src/dil/Declarations.d Fri Aug 31 00:53:00 2007 +0000 @@ -58,30 +58,36 @@ } } -alias Token*[] ModuleName; // Identifier(.Identifier)* +/// FQN = fully qualified name +alias Token*[] ModuleFQN; // Identifier(.Identifier)* class ModuleDeclaration : Declaration { - ModuleName moduleName; // module name sits at end of array - this(ModuleName moduleName) + Token* moduleName; + Token*[] packages; + this(ModuleFQN moduleFQN) { super(false); mixin(set_kind); - this.moduleName = moduleName; + if (moduleFQN.length) + { + this.moduleName = moduleFQN[$-1]; + this.packages = moduleFQN[0..$-1]; + } } } class ImportDeclaration : Declaration { - ModuleName[] moduleNames; + ModuleFQN[] moduleFQNs; Token*[] moduleAliases; Token*[] bindNames; Token*[] bindAliases; - this(ModuleName[] moduleNames, Token*[] moduleAliases, Token*[] bindNames, Token*[] bindAliases) + this(ModuleFQN[] moduleFQNs, Token*[] moduleAliases, Token*[] bindNames, Token*[] bindAliases) { super(false); mixin(set_kind); - this.moduleNames = moduleNames; + this.moduleFQNs = moduleFQNs; this.moduleAliases = moduleAliases; this.bindNames = bindNames; this.bindAliases = bindAliases;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/dil/Module.d Fri Aug 31 00:53:00 2007 +0000 @@ -0,0 +1,41 @@ +/++ + Author: Aziz Köksal + License: GPL3 ++/ +module dil.Module; +import dil.SyntaxTree; +import dil.Declarations; +import dil.Parser; +import dil.File; + +class Module +{ + string fileName; /// Path to the source file. + string packageName; + string moduleName; + Declarations root; /// The root of the AST. + ImportDeclaration[] imports; + ModuleDeclaration moduleDecl; + + this(string fileName) + { + this.fileName = fileName; + } + + void parse() + { + auto sourceText = loadFile(fileName); + auto parser = new Parser(sourceText, fileName); + parser.start(); + + this.root = parser.parseModule(); + + if (root.children.length) + { + // moduleDecl will be null if first node can't be casted to ModuleDeclaration. + this.moduleDecl = Cast!(ModuleDeclaration)(root.children[0]); + + this.imports = parser.imports; + } + } +}
--- a/trunk/src/dil/Parser.d Thu Aug 30 12:02:04 2007 +0000 +++ b/trunk/src/dil/Parser.d Fri Aug 31 00:53:00 2007 +0000 @@ -24,6 +24,8 @@ Information[] errors; + ImportDeclaration[] imports; + this(char[] srcText, string fileName) { lx = new Lexer(srcText, fileName); @@ -119,14 +121,14 @@ if (token.type == T.Module) { auto begin = token; - ModuleName moduleName; + ModuleFQN moduleFQN; do { nT(); - moduleName ~= requireId(); + moduleFQN ~= requireId(); } while (token.type == T.Dot) require(T.Semicolon); - decls ~= set(new ModuleDeclaration(moduleName), begin); + decls ~= set(new ModuleDeclaration(moduleFQN), begin); } decls ~= parseDeclarationDefinitions(); return decls; @@ -220,6 +222,8 @@ break; case T.Import: decl = parseImportDeclaration(); + assert(decl && decl.kind == NodeKind.ImportDeclaration); + imports ~= cast(ImportDeclaration)cast(void*)decl; break; case T.Enum: decl = parseEnumDeclaration(); @@ -781,7 +785,7 @@ nT(); } - ModuleName[] moduleNames; + ModuleFQN[] moduleFQNs; Token*[] moduleAliases; Token*[] bindNames; Token*[] bindAliases; @@ -789,7 +793,7 @@ nT(); // Skip import keyword. while (1) { - ModuleName moduleName; + ModuleFQN moduleFQN; Token* moduleAlias; moduleAlias = requireId(); @@ -798,11 +802,11 @@ if (token.type == T.Assign) { nT(); - moduleName ~= requireId(); + moduleFQN ~= requireId(); } else // import Identifier [^=] { - moduleName ~= moduleAlias; + moduleFQN ~= moduleAlias; moduleAlias = null; } @@ -810,11 +814,11 @@ while (token.type == T.Dot) { nT(); - moduleName ~= requireId(); + moduleFQN ~= requireId(); } // Push identifiers. - moduleNames ~= moduleName; + moduleFQNs ~= moduleFQN; moduleAliases ~= moduleAlias; if (token.type == T.Colon) @@ -853,7 +857,7 @@ require(T.Semicolon); - return new ImportDeclaration(moduleNames, moduleAliases, bindNames, bindAliases); + return new ImportDeclaration(moduleFQNs, moduleAliases, bindNames, bindAliases); } Declaration parseEnumDeclaration()
--- a/trunk/src/main.d Thu Aug 30 12:02:04 2007 +0000 +++ b/trunk/src/main.d Fri Aug 31 00:53:00 2007 +0000 @@ -13,6 +13,7 @@ import dil.File; import cmd.Generate; import cmd.Statistics; +import cmd.ImportGraph; void main(char[][] args) { @@ -43,13 +44,10 @@ } if (!(options & (DocOption.XML | DocOption.HTML))) options |= DocOption.XML; // Default to XML. - if (options & DocOption.Syntax) - syntaxToDoc(fileName, options); - else - tokensToDoc(fileName, options); + cmd.Generate.execute(fileName, options); break; case "stats", "statistics": - statistics(args[2]); + cmd.Statistics.execute(args[2]); break; case "parse": if (args.length == 3)