// Compiles an (optional) argument list and then calls it. private void MethodCall(Instruction instruction, string name, int length) { Signature signature = new Signature { Type = SignatureType.Getter, Arity = 0, Name = name, Length = length }; // Parse the argument list, if any. if (Match(TokenType.LeftParen)) { signature.Type = SignatureType.Method; // Allow empty an argument list. if (Peek() != TokenType.RightParen) { FinishArgumentList(signature); } Consume(TokenType.RightParen, "Expect ')' after arguments."); } // Parse the block argument, if any. if (Match(TokenType.LeftBrace)) { // Include the block argument in the arity. signature.Type = SignatureType.Method; signature.Arity++; Compiler fnCompiler = new Compiler(_parser, this, true); // Make a dummy signature to track the arity. Signature fnSignature = new Signature { Arity = 0 }; // Parse the parameter list, if any. if (Match(TokenType.Pipe)) { fnCompiler.FinishParameterList(fnSignature); Consume(TokenType.Pipe, "Expect '|' after function parameters."); } fnCompiler._numParams = fnSignature.Arity; fnCompiler.FinishBody(false); // TODO: Use the name of the method the block is being provided to. fnCompiler.EndCompiler(); } // TODO: Allow Grace-style mixfix methods? CallSignature(instruction, signature); }
// Compiles a method signature for a subscript operator. private static void SubscriptSignature(Compiler c, Signature signature) { signature.Type = SignatureType.Subscript; // The signature currently has "[" as its name since that was the token that // matched it. Clear that out. signature.Length = 0; signature.Name = ""; // Parse the parameters inside the subscript. c.FinishParameterList(signature); c.Consume(TokenType.RightBracket, "Expect ']' after parameters."); c.MaybeSetter(signature); }