def _parse_function_literal(self) -> Optional[ast.FunctionLiteral]: token = self._current_token if not self._expect_peek(TokenType.LPAREN): return None parameters = self._parse_function_parameters() if parameters is None: return None if not self._expect_peek(TokenType.LBRACE): return None body = self._parse_block_statement() return ast.FunctionLiteral(token, parameters, body)
def parseFunctionLiteral(self): lit = ast.FunctionLiteral(Token= self.curToken, Parameters=None, Body=None) if not self.expectPeek(tokens.LPAREN): return None lit.Parameters = self.parseFunctionParameters() if not self.expectPeek(tokens.LBRACE): return None lit.Body = self.parseBlockStatement() return lit
def parseFunctionLiteral(self): function = ast.FunctionLiteral(self.currToken) if not self.expectedPeekToken(tkn.LPAREN): return None function.Parameters = self.parseFunctionParameters() if not self.expectedPeekToken(tkn.LBRACE): return None function.Body = self.parseBlockStatement() return function
def parse_function_literal(self): self.step() if not isinstance(self.current, tokens.LPARAN): raise ParserError( f"Expected `(` after function name, found {self.current}") if isinstance(self.read_char(), tokens.RPARAN): return ast.FunctionCall(ident, []) params = [] while True: if isinstance(self.current, tokens.RPARAN): break params.append(self.parse_expr()) if isinstance(self.current, tokens.COMMA): self.step() self.step() body = self.parse_block() return ast.FunctionLiteral(params, body)