public override bool Equals(object obj, bool includeChildren) { if (!base.Equals(obj, includeChildren)) { return(false); } PropertyAccessToken other = (PropertyAccessToken)obj; if (Host != null) { if (!Host.Equals(other.Host)) { return(false); } } else if (other.Host != null) { return(false); } if (Property != null) { if (!Property.Equals(other.Property)) { return(false); } } else if (other.Property != null) { return(false); } return(true); }
public void TestTokenProperties() { IntegerToken lhs = new IntegerToken(1); IdentifierToken rhs = new IdentifierToken("blah"); PropertyAccessToken result = new PropertyAccessToken(0, lhs, rhs); Assert.AreEqual(lhs, result.Host); Assert.AreEqual(rhs, result.Property); }
public void TestValidStartMemberKeyedAccess() { InitCompiler("host.property[123]", 13); PropertyAccessToken propertyAccess = new PropertyAccessToken(4, new IdentifierToken("host", 0), new IdentifierToken("property", 5)); compiler.Parent.AddChild(propertyAccess); Assert.IsTrue(parser.Parse(compiler)); Assert.AreEqual(18, compiler.Pos); Assert.AreEqual(1, root.Children.Count); KeyedAccessToken expected = new KeyedAccessToken(13, propertyAccess); expected.AddChild(new IntegerToken(123, 14)); Assert.AreEqual(expected, root.Children[0]); Assert.AreSame(root, compiler.Parent); }
public void TestValidStartMemberFunction() { InitCompiler("host.function(a+b) * 2", 13); PropertyAccessToken propertyAccess = new PropertyAccessToken(4, new IdentifierToken("host", 0), new IdentifierToken("function", 5)); compiler.Parent.AddChild(propertyAccess); Assert.IsTrue(parser.Parse(compiler)); Assert.AreEqual(18, compiler.Pos); Assert.AreEqual(1, root.Children.Count); FunctionToken expected = new FunctionToken(13, propertyAccess); expected.Children.Add(new AdditionToken(15, new IdentifierToken("a", 14), new IdentifierToken("b", 16))); Assert.AreEqual(expected, root.Children[0]); Assert.AreSame(root, compiler.Parent); }
private FunctionDetails ResolveFunction(UnityELEvaluator context) { FunctionDetails functionDetails = new FunctionDetails(); // See if there is a host object, otherwise we're looking for a static function on the evaluator if (FunctionName is PropertyAccessToken) { PropertyAccessToken propertyAccess = (PropertyAccessToken)FunctionName; functionDetails.Host = propertyAccess.Host.Evaluate(context); if (functionDetails.Host == null) { return(null); } functionDetails.Name = propertyAccess.Property.Value; } else if (FunctionName is IdentifierToken) { IdentifierToken identifier = (IdentifierToken)FunctionName; functionDetails.Host = null; functionDetails.Name = identifier.Value; } // Resolve arguments (if any) functionDetails.Parameters = new List <object>(); List <System.Type> types = new List <System.Type>(); int argIndex = 0; foreach (TokenImpl childToken in Children) { object value = null; if (childToken is ArgumentGroupToken) { value = ((ArgumentGroupToken)childToken).EvaluateForArgument(context, functionDetails.Name, argIndex); } else { value = childToken.Evaluate(context); } functionDetails.Parameters.Add(value); if (value != null) { types.Add(value.GetType()); } else { types.Add(null); } ++argIndex; } if (functionDetails.Host != null) { if (context.MemberFunctionResolver == null) { functionDetails.ResolutionFailedReason = $"Cannot resolve a member function as no MemberFunctionResolver has been configured on the context"; } else { functionDetails.Function = context.MemberFunctionResolver.ResolveFunction(functionDetails.Host.GetType(), functionDetails.Name, types.ToArray()); } /*} else if (functionDetails.Namespace != null) { * if (!context.FunctionResolvers.ContainsKey(functionDetails.Namespace)) { * functionDetails.ResolutionFailedReason = $"Unknown function namespace: {functionDetails.Namespace}"; * } else { * functionDetails.Function = context.FunctionResolvers[functionDetails.Namespace].ResolveFunction(functionDetails.Name, types.ToArray()); * }*/ } else { if (context.DefaultFunctionResolver == null) { functionDetails.ResolutionFailedReason = $"No function namespace was supplied and no default function resolver was setup"; } else { functionDetails.Function = context.DefaultFunctionResolver.ResolveFunction(functionDetails.Name, types.ToArray()); } } return(functionDetails); }