diff trunk/src/dil/Parser.d @ 368:2adf808343d6

- Renamed method start() to init() in Parser. - Renamed method parseModule() to start() in Parser. - Added method parseModuleDeclaration(). - Added class ImportParser which inherits from Parser. It's used as a lightweight parser for parsing module and import declarations. - Added member isLightweight to Module. - Removed calls to Parser.parseModule() and replaced them with Parser.start().
author aziz
date Sat, 01 Sep 2007 11:23:01 +0000
parents dda55fae37de
children 27767e203d64
line wrap: on
line diff
--- a/trunk/src/dil/Parser.d	Fri Aug 31 23:07:05 2007 +0000
+++ b/trunk/src/dil/Parser.d	Sat Sep 01 11:23:01 2007 +0000
@@ -16,6 +16,35 @@
 
 private alias TOK T;
 
+class ImportParser : Parser
+{
+  this(char[] srcText, string fileName)
+  {
+    super(srcText, fileName);
+  }
+
+  Declarations start()
+  {
+    auto decls = new Declarations;
+    super.init();
+    if (token.type == T.Module)
+      decls ~= parseModuleDeclaration();
+    while (token.type != T.EOF)
+    {
+      if (token.type == T.Import)
+      {
+        auto decl = parseImportDeclaration();
+        assert(decl && decl.kind == NodeKind.ImportDeclaration);
+        super.imports ~= cast(ImportDeclaration)cast(void*)decl;
+        decls ~= decl;
+      }
+      else
+        nT();
+    }
+    return decls;
+  }
+}
+
 class Parser
 {
   Lexer lx;
@@ -33,7 +62,7 @@
 
   debug char* prev;
 
-  void start()
+  private void init()
   {
     debug prev = lx.text.ptr;
     nT();
@@ -114,26 +143,29 @@
   + Declaration parsing methods +
   ++++++++++++++++++++++++++++++/
 
-  Declarations parseModule()
+  Declarations start()
   {
+    init();
     auto decls = new Declarations;
-
     if (token.type == T.Module)
-    {
-      auto begin = token;
-      ModuleFQN moduleFQN;
-      do
-      {
-        nT();
-        moduleFQN ~= requireId();
-      } while (token.type == T.Dot)
-      require(T.Semicolon);
-      decls ~= set(new ModuleDeclaration(moduleFQN), begin);
-    }
+      decls ~= parseModuleDeclaration();
     decls ~= parseDeclarationDefinitions();
     return decls;
   }
 
+  Declaration parseModuleDeclaration()
+  {
+    auto begin = token;
+    ModuleFQN moduleFQN;
+    do
+    {
+      nT();
+      moduleFQN ~= requireId();
+    } while (token.type == T.Dot)
+    require(T.Semicolon);
+    return set(new ModuleDeclaration(moduleFQN), begin);
+  }
+
   Declarations parseDeclarationDefinitions()
   {
     auto decls = new Declarations;