示例#1
0
        public void InvokeMethod()
        {
            SubrDotInvoke subr = new SubrDotInvoke("ToString");

            var result = subr.Apply(List.Create(new object[] { 123 }), null);

            Assert.IsNotNull(result);
            Assert.AreEqual("123", result);
        }
示例#2
0
        public void InvokeMethodWithArguments()
        {
            SubrDotInvoke subr = new SubrDotInvoke("Substring");

            var result = subr.Apply(List.Create(new object[] { "foobarfoo", 3, 3 }), null);

            Assert.IsNotNull(result);
            Assert.AreEqual("bar", result);
        }
示例#3
0
        public void GetProperty()
        {
            SubrDotInvoke subr = new SubrDotInvoke("Length");

            var result = subr.Apply(List.Create(new object[] { "foo" }), null);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result);
        }
示例#4
0
        private List CompileList()
        {
            if (this.NextTokenIs(TokenType.Separator, ')'))
            {
                return(null);
            }

            object first = this.CompileTerm();

            if (first is Identifier)
            {
                var id = (Identifier)first;

                if (id.Name.Length > 1)
                {
                    if (id.Name.EndsWith("."))
                    {
                        first = new SubrDotNew(id.Name.Substring(0, id.Name.Length - 1));
                    }
                    else if (id.Name.StartsWith("."))
                    {
                        first = new SubrDotInvoke(id.Name.Substring(1));
                    }
                }
            }

            object rest;

            if (this.NextTokenIs(TokenType.Name, "."))
            {
                rest = this.CompileTerm();
                this.ParseNextToken(TokenType.Separator, ')');
            }
            else
            {
                rest = this.CompileList();
            }

            List list = new List(first, rest);

            return(list);
        }