public INode ParseNode() { var node = this.ParseSimpleNode(); if (node == null) { return(null); } var token = this.NextToken(); if (token != null && token.Type == TokenType.Name) { var expr = this.ParseExpressionNode(); node = new InvokeMethodNode(node, token.Value, new INode[] { expr }); } else if (token != null) { this.PushToken(token); } this.ParseEndOfCommand(); return(node); }
public void CreateInvokeMethodNode() { INode target = new NameNode("foo"); IList <INode> arguments = new List <INode>() { new ConstantNode(42) }; InvokeMethodNode node = new InvokeMethodNode(target, "append", arguments); node.RegisterInContext(null); Assert.AreSame(target, node.Target); Assert.AreSame(arguments, node.Arguments); Assert.AreEqual("append", node.MethodName); }
private INode ParseSimpleNode() { var token = this.NextToken(); if (token == null) { return(null); } if (token.Type == TokenType.Name && token.Value == "class") { return(this.ParseClassNode()); } if (token.Type == TokenType.Name && token.Value == "object") { return(this.ParseObjectNode()); } if (token.Type == TokenType.Name && token.Value == "val") { return(this.ParseValNode()); } if (token.Type == TokenType.Name && token.Value == "var") { return(this.ParseVarNode()); } if (token.Type == TokenType.Name && token.Value == "def") { return(this.ParseDefNode()); } this.PushToken(token); INode node = this.ParseExpressionNode(); if (node == null) { return(null); } while (true) { INode newnode = node; while (this.TryParseToken(TokenType.Delimiter, ".")) { newnode = new DotNameNode(newnode, this.ParseName()); } while (this.TryParseToken(TokenType.Delimiter, "(")) { IList <INode> arguments = new List <INode>(); while (!this.TryParseToken(TokenType.Delimiter, ")")) { if (arguments.Count > 0) { this.ParseToken(TokenType.Delimiter, ","); } arguments.Add(this.ParseExpressionNode()); } if (newnode is DotNameNode) { newnode = new InvokeMethodNode(((DotNameNode)newnode).Target, ((DotNameNode)newnode).Name, arguments); } else { newnode = new InvokeNode(newnode, arguments); } } if (node == newnode) { break; } node = newnode; } return(node); }