Exemplo n.º 1
0
 public virtual object Walk(SelfExpression node)
 {
     if (Enter(node))
     {
         // Insert code here
     }
     Exit(node);
     return(null);
 }
Exemplo n.º 2
0
        private SelfExpression ParseSelfExpression()
        {
            var exp = new SelfExpression {
                Token = Next()
            };

            Match(TokenType.This);
            return(exp);
        }
Exemplo n.º 3
0
        private IExpression ParseCallExpression(IExpression receiver)
        {
            CallExpression exp;

            if (CurTokenIs(TokenType.LParen))
            {
                var m       = ((Identifier)receiver).Value;
                var selftok = new Token {
                    Type = TokenType.Self, Literal = "self", Line = CurToken.Line
                };
                var self = new SelfExpression {
                    Token = selftok
                };
                receiver = self;

                exp = new CallExpression {
                    Token = CurToken, Receiver = receiver, Method = m
                };
                exp.Arguments = ParseCallArguments();
            }
            else
            {
                exp = new CallExpression {
                    Token = CurToken, Receiver = receiver
                };
                if (!ExpectPeek(TokenType.Ident))
                {
                    return(null);
                }
                exp.Method = CurToken.Literal;
                if (PeekTokenIs(TokenType.LParen))
                {
                    NextToken();
                    exp.Arguments = ParseCallArguments();
                }
                else
                {
                    exp.Arguments = new List <IExpression>();
                }
            }

            if (PeekTokenIs(TokenType.Assign))
            {
                exp.Method = exp.Method + "=";
                NextToken();
                NextToken();
                exp.Arguments.Add(ParseExpression(LOWEST));
            }

            if (PeekTokenIs(TokenType.Do))
            {
                ParseBlockParameters(exp);
            }

            return(exp);
        }
Exemplo n.º 4
0
        public void Evaluate()
        {
            Machine        machine = new Machine();
            SelfExpression expr    = new SelfExpression();

            var result = expr.Evaluate(machine.RootContext);

            Assert.IsNotNull(result);
            Assert.AreSame(machine.RootContext.Self, result);
        }
Exemplo n.º 5
0
        public void ParseSelfExpression()
        {
            Parser parser   = new Parser("self");
            var    expected = new SelfExpression();
            var    result   = parser.ParseExpression();

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result);

            Assert.IsNull(parser.ParseCommand());
        }
Exemplo n.º 6
0
        public void Equals()
        {
            SelfExpression expr1 = new SelfExpression();
            SelfExpression expr2 = new SelfExpression();

            Assert.IsFalse(expr1.Equals(null));
            Assert.IsFalse(expr1.Equals(123));
            Assert.IsFalse(expr1.Equals("foo"));

            Assert.IsTrue(expr1.Equals(expr2));
            Assert.IsTrue(expr2.Equals(expr1));
            Assert.AreEqual(expr1.GetHashCode(), expr2.GetHashCode());
        }
Exemplo n.º 7
0
        private IExpression ParseDefExpression()
        {
            string           name  = this.ParseName();
            INamedExpression named = null;

            if (name == "self")
            {
                named = new SelfExpression();
            }
            else
            {
                named = new NameExpression(name);
            }

            while (true)
            {
                if (this.TryParseToken(TokenType.Separator, "."))
                {
                    string newname = this.ParseName();
                    named = new DotExpression(named, newname, new IExpression[0]);
                    continue;
                }

                if (this.TryParseToken(TokenType.Separator, "::"))
                {
                    string newname = this.ParseName();
                    named = new DoubleColonExpression(named, newname);
                    continue;
                }

                break;
            }

            IList <string> parameters = this.ParseParameterList();
            IExpression    body       = this.ParseCommandList();

            return(new DefExpression(named, parameters, body));
        }
Exemplo n.º 8
0
        private ClassExpression ParseClassExpression()
        {
            string           name  = this.ParseName();
            INamedExpression named = null;

            if (name == "self")
            {
                named = new SelfExpression();
            }
            else
            {
                named = new NameExpression(name);
            }

            while (true)
            {
                if (this.TryParseToken(TokenType.Separator, "::"))
                {
                    string newname = this.ParseName();
                    named = new DoubleColonExpression(named, newname);
                    continue;
                }

                break;
            }

            this.ParseEndOfCommand();
            IExpression body = this.ParseCommandList();

            if (!Predicates.IsConstantName(named.Name))
            {
                throw new SyntaxError("class/module name must be a CONSTANT");
            }

            return(new ClassExpression(named, body));
        }
Exemplo n.º 9
0
 private SelfExpression ParseSelfExpression()
 {
     var exp = new SelfExpression {Token = Next()};
     Match(TokenType.This);
     return exp;
 }
Exemplo n.º 10
0
 public virtual object Walk(SelfExpression node)
 {
     if (Enter(node))
     {
         // Insert code here
     }
     Exit(node);
     return null;
 }
Exemplo n.º 11
0
 public override bool Enter(SelfExpression node)
 {
     Print("SelfExpression");
     level++;
     return true;
 }
Exemplo n.º 12
0
 public override void Exit(SelfExpression node)
 {
     level--;
 }
Exemplo n.º 13
0
 public virtual bool Enter(SelfExpression node)
 {
     return true;
 }
Exemplo n.º 14
0
 public virtual void Exit(SelfExpression node)
 {
 }
 public virtual bool Enter(SelfExpression node)
 {
     return(true);
 }
 public virtual void Exit(SelfExpression node)
 {
 }
Exemplo n.º 17
0
 public virtual void Accept(SelfExpression self)
 {
 }
Exemplo n.º 18
0
 public override object Walk(SelfExpression node)
 {
     return Context.CurrentFrame.Resolve("this");
 }
Exemplo n.º 19
0
 public override bool Enter(SelfExpression node)
 {
     Print("SelfExpression");
     level++;
     return(true);
 }
Exemplo n.º 20
0
 public override object Walk(SelfExpression node)
 {
     return(Context.CurrentFrame.Resolve("this"));
 }
Exemplo n.º 21
0
 public override void Exit(SelfExpression node)
 {
     level--;
 }