Mercurial > projects > dang
diff parser/Action.d @ 99:857f0d530789 new_gen
Imports and improved module statement
Allow "module a.b.c"
Supports most forms of D's import.
import A, B;
import A, B = C;
import A, B : a = b, c;
author | Anders Halager <halager@gmail.com> |
---|---|
date | Tue, 06 May 2008 21:59:22 +0200 |
parents | 48bb2287c035 |
children | cd066f3b539a |
line wrap: on
line diff
--- a/parser/Action.d Tue May 06 21:55:29 2008 +0200 +++ b/parser/Action.d Tue May 06 21:59:22 2008 +0200 @@ -60,6 +60,25 @@ } /** + Represents a fully qualified name, with some packages and a final identifier. + The identifier should always be set, but packages may have length 0. + **/ +struct ModuleName +{ + Id id; + Id[] packages; + + /// Get the full ranged spanned by packages and identifier + SourceRange asRange() + { + SourceRange r = id.tok.asRange(); + foreach (identifier; packages) + r = r + identifier.tok.asRange(); + return r; + } +} + +/** All methods are optional. Warning: Interface is not stable yet. Use the `override` keyword in all classes @@ -82,7 +101,18 @@ // -- Modules -- - ModuleT actOnModule(char[] name) + ModuleT actOnModule(ref Token _module, char[] name) + { + return null; + } + + /** + This action is called when a file does not start with a module + declaration - in which case there is no Token available. + + Instead a SLoc to the start of the file is given. + */ + ModuleT actOnImplicitModule(SourceLocation fileStart, char[] name) { return null; } @@ -94,6 +124,23 @@ // -- Declarations -- /** + Called for an import statement, that may be renamed. Id name is null, + there is no rename. + + If there are selective imports, its handled in add + */ + DeclT actOnImport(ref Token _import, ref ModuleName target, Id* name) + { + return null; + } + + /** + */ + void addSelectiveImport(DeclT _import, ref Id target, Id* name) + { + } + + /** Either we should have one case that handles a lot of things, or we should have a lot of separate cases. As an example, this method could handle the params in `int f(int, int)`