def call(self): ast = self.primary() while self.match(TokenType.LEFT_PAREN, TokenType.DOT): op = self.nextToken() if op.type == TokenType.LEFT_PAREN: ast = Expr.Call(ast, op, self.callArgs()) self.consume(TokenType.RIGHT_PAREN, exp=')') else: # op.type == TokenType.DOT ast = Expr.Attrib(ast, op, self.identifier()) return ast
def finishCall(self, callee: Expr.Expr) -> Expr.Expr: arguments: List[Expr.Expr] = [] if not self.check(TokenType.RIGHT_PAREN): while True: if len(arguments) >= 32: self.error(self.peek(), "Cannot have more than 32 arguments") arguments.append(self.expression()) if not self.match(TokenType.COMMA): break paren = self.consume(TokenType.RIGHT_PAREN, "Expected ')' after arguments") return Expr.Call(callee, paren, arguments)
def finish_call(self, callee: Expr.Expr) -> Expr.Call: # we are here because we've seen callee( -- don't leave without ')' args = [] # there are only 3 ways out of this loop: seeing a ')' at an # appropriate place, or somebody raises an error exception. while not self.check(RIGHT_PAREN): # next token is not ')' args.append(self.expression()) # expression complete: next token is not legal as an expression if len(args) >= Parser.Max_Args: raise Parser.ParseError( self.peek, f"Function may not have {len(args)} arguments") self.match(COMMA) # if it is a comma, eat it # next token is not comma: could be start of expression, or ')' # next token is ')' without question rparen = self.consume(RIGHT_PAREN, "This message cannot be displayed") return Expr.Call(callee, rparen, args)
def finish_call(self, callee): ''' Will create a Call Expression that will bundle up a function/method callee with a ')' paren and token arguments to be interpreted by the visit_Call method later ''' arguments = [] if not self.check(TokenType.RIGHT_PAREN): arguments.append(self.expression()) while self.match(TokenType.COMMA): if len(arguments) >= 255: self.error(self.peek(), "Can't have more than 255 arguments") arguments.append(self.expression()) paren = self.consume(TokenType.RIGHT_PAREN, "Expect ')' after arguments.") return Expr.Call(callee, paren, arguments)