// Compiles a method signature for an infix operator. static void InfixSignature(Compiler c, Signature signature) { // Add the RHS parameter. signature.Type = SignatureType.Method; signature.Arity = 1; // Parse the parameter name. c.Consume(TokenType.LeftParen, "Expect '(' after operator name."); c.DeclareNamedVariable(); c.Consume(TokenType.RightParen, "Expect ')' after parameter name."); }
// Compiles a method signature for an operator that can either be unary or // infix (i.e. "-"). private static void MixedSignature(Compiler c, Signature signature) { signature.Type = SignatureType.Getter; // If there is a parameter, it's an infix operator, otherwise it's unary. if (c.Match(TokenType.LeftParen)) { // Add the RHS parameter. signature.Type = SignatureType.Method; signature.Arity = 1; // Parse the parameter name. c.DeclareNamedVariable(); c.Consume(TokenType.RightParen, "Expect ')' after parameter name."); } }