changeset 631:2feb88f5c867

Added dil.parser.ExpressionParser and dil.parser.Factory.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 12 Jan 2008 01:56:04 +0100
parents 5197bd351e5f
children 20dddcc54621
files trunk/src/dil/Messages.d trunk/src/dil/ast/Expressions.d trunk/src/dil/parser/ExpressionParser.d trunk/src/dil/parser/Factory.d trunk/src/dil/parser/Parser.d trunk/src/main.d
diffstat 6 files changed, 71 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/Messages.d	Fri Jan 11 21:01:07 2008 +0100
+++ b/trunk/src/dil/Messages.d	Sat Jan 12 01:56:04 2008 +0100
@@ -146,4 +146,5 @@
   auto DeclConflictsWithDecl = "declaration '{}' conflicts with declaration @{}";
   auto VariableConflictsWithDecl = "variable '{}' conflicts with declaration @{}";
   auto InterfaceCantHaveVariables = "an interface can't have member variables";
+  auto MixinArgumentMustBeString = "the mixin argument must evaluate to a string";
 }
--- a/trunk/src/dil/ast/Expressions.d	Fri Jan 11 21:01:07 2008 +0100
+++ b/trunk/src/dil/ast/Expressions.d	Sat Jan 12 01:56:04 2008 +0100
@@ -12,6 +12,7 @@
 import dil.ast.Parameters;
 import dil.ast.BaseClass;
 import dil.lexer.Identifier;
+import dil.parser.ExpressionParser;
 import dil.semantic.Scope;
 import dil.semantic.Types;
 import common;
@@ -930,20 +931,29 @@
     this.expr = expr;
   }
 
-  // import dil.Parser;
   override Expression semantic(Scope scop)
   {
+    if (type)
+      return this.expr;
     // TODO:
-    /+
     auto expr = this.expr.semantic(scop);
-    auto strExpr = Cast!(StringExpression)(expr);
-    // if (strExpr is null)
-    //  error(scop, MID.MixinExpressionMustBeString);
-    auto parser = new Parser(strExpr.getString(), "", scop.infoMan);
-    expr = parser.start2();
+    expr = expr.evaluate();
+    if (expr is null)
+      return this;
+    auto strExpr = TryCast!(StringExpression)(expr);
+    if (strExpr is null)
+     error(scop, MSG.MixinArgumentMustBeString);
+    else
+    {
+      auto loc = this.begin.getLocation();
+      auto filePath = loc.filePath;
+      auto parser = new_ExpressionParser(strExpr.getString(), filePath, scop.infoMan);
+      expr = parser.parse();
+      expr = expr.semantic(scop);
+    }
+    this.expr = expr;
+    this.type = expr.type;
     return expr;
-    +/
-    return null;
   }
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trunk/src/dil/parser/ExpressionParser.d	Sat Jan 12 01:56:04 2008 +0100
@@ -0,0 +1,19 @@
+/++
+  Author: Aziz Köksal
+  License: GPL3
++/
+module dil.parser.ExpressionParser;
+
+import dil.ast.Expression;
+import dil.Information;
+import common;
+
+interface ExpressionParser
+{
+  Expression parse();
+}
+
+ExpressionParser function(char[] srcText,
+                          string filePath,
+                          InfoManager infoMan = null)
+  new_ExpressionParser;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trunk/src/dil/parser/Factory.d	Sat Jan 12 01:56:04 2008 +0100
@@ -0,0 +1,30 @@
+/++
+  Author: Aziz Köksal
+  License: GPL3
++/
+module dil.parser.Factory;
+
+import dil.parser.ExpressionParser;
+import dil.parser.Parser;
+import dil.ast.Expression;
+import dil.Information;
+import common;
+
+static this()
+{
+  dil.parser.ExpressionParser.new_ExpressionParser =
+    function ExpressionParser(char[] srcText, string filePath, InfoManager infoMan = null)
+    {
+      class ExpressionParser_ : Parser, ExpressionParser
+      {
+        this(char[] srcText, string filePath, InfoManager infoMan = null)
+        { super(srcText, filePath, infoMan); }
+
+        Expression parse()
+        {
+          return Parser.start2();
+        }
+      }
+      return new ExpressionParser_(srcText, filePath, infoMan);
+    };
+}
--- a/trunk/src/dil/parser/Parser.d	Fri Jan 11 21:01:07 2008 +0100
+++ b/trunk/src/dil/parser/Parser.d	Sat Jan 12 01:56:04 2008 +0100
@@ -20,7 +20,7 @@
 import common;
 
 /++
-  The Parser produces an abstract syntax tree (AST) by analyzing
+  The Parser produces a full parse tree by analyzing
   the tokens of the provided source code.
 +/
 class Parser
--- a/trunk/src/main.d	Fri Jan 11 21:01:07 2008 +0100
+++ b/trunk/src/main.d	Sat Jan 12 01:56:04 2008 +0100
@@ -5,6 +5,7 @@
 module main;
 
 import dil.parser.Parser;
+import dil.parser.Factory;
 import dil.lexer.Lexer,
        dil.lexer.Token;
 import dil.ast.Declarations,