package dyvil.tools.gensrc.ast.expression;

import dyvil.tools.gensrc.ast.scope.Scope;
import dyvil.tools.parsing.ASTNode;

public interface Expression extends ASTNode
{
	default boolean evaluateBoolean(Scope scope)
	{
		return Boolean.parseBoolean(this.evaluateString(scope));
	}

	default long evaluateInteger(Scope scope)
	{
		try
		{
			return Long.parseLong(this.evaluateString(scope));
		}
		catch (NumberFormatException ex)
		{
			return 0L;
		}
	}

	default double evaluateDouble(Scope scope)
	{
		try
		{
			return Double.parseDouble(this.evaluateString(scope));
		}
		catch (NumberFormatException ex)
		{
			return 0;
		}
	}

	String evaluateString(Scope scope);

	default Iterable<Expression> evaluateIterable(Scope scope)
	{
		return new ExpressionList(this);
	}

	@Override
	void toString(String indent, StringBuilder builder);
}

@@ -37,16 +37,161 @@
 ssion;%0A%0A
+import dyvil.collection.iterator.ArrayIterator;%0Aimport dyvil.collection.iterator.SingletonIterator;%0Aimport dyvil.source.position.SourcePosition;%0A
 import d
@@ -881,38 +881,516 @@
 %7B%0A%09%09
-return new ExpressionList(this
+final SourcePosition position = this.getPosition();%0A%09%09final String string = this.evaluateString(scope);%0A%0A%09%09if (string.indexOf(',') %3C 0)%0A%09%09%7B%0A%09%09%09final StringValue value = new StringValue(position, string);%0A%09%09%09return () -%3E new SingletonIterator%3C%3E(value);%0A%09%09%7D%0A%0A%09%09final String%5B%5D split = string.split(%22%5C%5Cs*,%5C%5Cs*%22);%0A%09%09final Expression%5B%5D array = new Expression%5Bsplit.length%5D;%0A%09%09for (int i = 0; i %3C split.length; i++)%0A%09%09%7B%0A%09%09%09array%5Bi%5D = new StringValue(position, split%5Bi%5D);%0A%09%09%7D%0A%09%09return () -%3E new ArrayIterator%3C%3E(array
 );%0A%09

Improve Iterable Conversion in For Directives