def call(self) -> Expr.Expr: an_expr = self.primary() while True: if self.match(LEFT_PAREN): an_expr = self.finish_call(an_expr) elif self.match(DOT): name = self.consume(IDENTIFIER, "Expect property name after '.'") an_expr = Expr.Get(an_expr, name) else: break return an_expr
def call(self) -> Expr.Expr: expression = self.primary() while True: if self.match(Token.TokenType.LEFT_PAREN): expression = self.finish_call(expression) elif self.match(Token.TokenType.DOT): name = self.consume(Token.TokenType.IDENTIFIER, "Expect property name after '.'.") expression = Expr.Get(expression, name) else: break return expression
def call(self): ''' Function call -> when we see an identifier matching to a function name as returned by "primary()" and match with an immediate "(" then we know we're entering a function call. Object getter -> if we see a "." followed by a property identifier then we're trying to access that property just like in Python. ''' expr = self.primary() while True: if self.match(TokenType.LEFT_PAREN): expr = self.finish_call(expr) elif self.match(TokenType.DOT): name = self.consume(TokenType.IDENTIFIER, "Expect property name after '.'.") expr = Expr.Get(expr, name) else: break return expr