示例#1
0
		public TagAttribute(string name, Expression expression)
		{
			this.name = name;
			this.expression = expression;
		}
示例#2
0
		protected object EvalExpression(Expression exp)
		{
			currentExpression = exp;

			if (exp is StringLiteral)
				return ((StringLiteral)exp).Content;
			else if (exp is Name)
			{
				object obj = variables[((Name)exp).Id];
				return obj;
			}
			else if (exp is FieldAccess)
			{
				FieldAccess fa = (FieldAccess)exp;
				object obj = variables[fa.Exp];
				string propertyName = fa.Field;
				return EvalProperty(obj, propertyName);
			}
			else if (exp is IntLiteral)
				return ((IntLiteral)exp).Value;
			else if (exp is FCall)
			{
				FCall fcall = (FCall)exp;
				if (!functions.ContainsKey(fcall.Name))
				{
					string msg = string.Format("Function {0} is not defined", fcall.Name);
					WriteError(msg, exp.Line, exp.Col);
					return null;
				}

				TemplateFunction func = functions[fcall.Name];
				object[] values = new object[fcall.Args.Length];
				for (int i = 0; i < values.Length; i++)
					values[i] = EvalExpression(fcall.Args[i]);

				return func(values);
			}
			else if (exp is StringExpression)
			{
				StringExpression stringExp = (StringExpression)exp;
				StringBuilder sb = new StringBuilder();
				foreach (Expression ex in stringExp.Expressions)
					sb.Append(EvalExpression(ex));

				return sb.ToString();
			}

			return null;
		}
示例#3
0
		protected void ProcessExpression(Expression exp)
		{
			object value = EvalExpression(exp);
			WriteValue(value);
		}
示例#4
0
		public void Add(Expression exp)
		{
			exps.Add(exp);
		}
示例#5
0
文件: TagIf.cs 项目: nkaluva/helper
		public TagIf(int line, int col, Expression test)
			:base(line, col, "if")
		{
			this.test = test;
		}
示例#6
0
文件: FCall.cs 项目: nkaluva/helper
		public FCall(int line, int col, string name, Expression[] args)
			:base(line, col)
		{
			this.name = name;
			this.args = args;
		}