Mercurial > projects > dil
changeset 114:83bb5190c0fc
- Completed implementation of parseImportDeclaration().
- Added class ImportDeclaration.
author | aziz |
---|---|
date | Mon, 09 Jul 2007 11:29:02 +0000 |
parents | 20d8ae8a3fd9 |
children | cea36caeec42 |
files | trunk/src/Declarations.d trunk/src/Parser.d |
diffstat | 2 files changed, 118 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Declarations.d Sun Jul 08 21:24:03 2007 +0000 +++ b/trunk/src/Declarations.d Mon Jul 09 11:29:02 2007 +0000 @@ -11,12 +11,29 @@ } +alias string[] ModuleName; // Identifier(.Identifier)* + class ModuleDeclaration : Declaration { - string[] idents; // module name sits at end of array - this(string[] idents) + ModuleName moduleName; // module name sits at end of array + this(ModuleName moduleName) { - this.idents = idents; + this.moduleName = moduleName; + } +} + +class ImportDeclaration : Declaration +{ + ModuleName[] moduleNames; + string[] moduleAliases; + string[] bindNames; + string[] bindAliases; + this(ModuleName[] moduleNames, string[] moduleAliases, string[] bindNames, string[] bindAliases) + { + this.moduleNames = moduleNames; + this.moduleAliases = moduleAliases; + this.bindNames = bindNames; + this.bindAliases = bindAliases; } }
--- a/trunk/src/Parser.d Sun Jul 08 21:24:03 2007 +0000 +++ b/trunk/src/Parser.d Mon Jul 09 11:29:02 2007 +0000 @@ -196,7 +196,104 @@ nT(); } - return decl; + ModuleName[] moduleNames; + string[] moduleAliases; + string[] bindNames; + string[] bindAliases; + + do + { + ModuleName moduleName; + string moduleAlias; + + if (token.type == T.Identifier) + { + moduleAlias = token.identifier; + nT(); + } + else + errorIfNot(T.Identifier); // TODO: better error msg + + // import Identifier [^=] + if (token.type != T.Assign) + { + moduleName ~= moduleAlias; + moduleAlias = null; + } + else + { + nT(); + // AliasName = ModuleName + if (token.type == T.Identifier) + { + moduleName ~= token.identifier; + nT(); + } + else + errorIfNot(T.Identifier); + } + + // parse Identifier(.Identifier)* + while (token.type == T.Dot) + { + nT(); + if (token.type == T.Identifier) + { + moduleName ~= token.identifier; + nT(); + } + else + errorIfNot(T.Identifier); + } + + // Push identifiers. + moduleNames ~= moduleName; + moduleAliases ~= moduleAlias; + + // parse : BindAlias = BindName(, BindAlias = BindName)*; + // : BindName(, BindName)*; + if (token.type == T.Colon) + { + string bindName, bindAlias; + do + { + nT(); + if (token.type == T.Identifier) + { + bindAlias = token.identifier; + nT(); + } + else + errorIfNot(T.Identifier); + + if (token.type == T.Assign) + { + nT(); + if (token.type == T.Identifier) + { + bindName = token.identifier; + nT(); + } + else + errorIfNot(T.Identifier); + } + else + { + bindName = bindAlias; + bindAlias = null; + } + + // Push identifiers. + bindNames ~= bindName; + bindAliases ~= bindAlias; + + } while (token.type == T.Comma) + break; + } + } while (token.type == T.Comma) + require(T.Semicolon); + + return new ImportDeclaration(moduleNames, moduleAliases, bindNames, bindAliases); } Declaration parseEnumDeclaration()