def call(self): res = ParseResult() atom = res.register(self.atom()) if res.error: return res if self.current_tok.type == token.T_LPAREN: res.register_advancement() self.advance() arg_nodes = [] if self.current_tok.type == token.T_RPAREN: res.register_advancement() self.advance() else: arg_nodes.append(res.register(self.expr())) if res.error: return res.failure( errors.InvalidSyntaxError( self.current_tok.pos_start, self.current_tok.pos_end, "Expected ')', 'var', 'if', 'for', 'while', 'func', int, float, identifier, '+', '-', '(', '[' or 'not'" )) while self.current_tok.type == token.T_COMMA: res.register_advancement() self.advance() arg_nodes.append(res.register(self.expr())) if res.error: return res if self.current_tok.type != token.T_RPAREN: return res.failure( errors.InvalidSyntaxError(self.current_tok.pos_start, self.current_tok.pos_end, "Expected ',' or ')'")) res.register_advancement() self.advance() return res.success(nodes.CallNode(atom, arg_nodes)) return res.success(atom)
def call(self): res = ParseResult() atom = res.register(self.atom()) if res.error: return res if self.current_tok.type == token.T_LPAREN: res.register_advancement() self.advance() arg_nodes = [] optional_arg_name_nodes = [] optional_arg_value_nodes = [] if self.current_tok.type == token.T_RPAREN: res.register_advancement() self.advance() else: arg_nodes.append(res.register(self.expr())) if res.error: return res.failure( errors.InvalidSyntaxError( self.current_tok.pos_start, self.current_tok.pos_end, "Expected ')', 'var', 'if', 'for', 'while', 'func', int, float, identifier, '+', '-', '(', '[' or 'not'" )) while self.current_tok.type == token.T_COMMA: res.register_advancement() self.advance() arg_nodes.append(res.register(self.expr())) if res.error: return res if self.current_tok.type == token.T_EQ: ident = arg_nodes.pop(-1) if type(ident) != nodes.VarAccessNode: return res.failure( errors.InvalidSyntaxError( self.current_tok.pos_start, self.current_tok.pos_end, "Expected an identifier")) optional_arg_name_nodes.append(ident.var_name_tok) res.register_advancement() self.advance() optional_arg_value_nodes.append(res.register(self.expr())) if res.error: return res.failure( errors.InvalidSyntaxError( self.current_tok.pos_start, self.current_tok.pos_end, "Expected int, float, string or boolean")) while self.current_tok.type == token.T_COMMA: res.register_advancement() self.advance() if self.current_tok.type != token.T_IDENTIFIER: return res.failure( errors.InvalidSyntaxError( self.current_tok.pos_start, self.current_tok.pos_end, f"Expected identifier")) optional_arg_name_nodes.append(self.current_tok) res.register_advancement() self.advance() if self.current_tok.type != token.T_EQ: return res.failure( errors.InvalidSyntaxError( self.current_tok.pos_start, self.current_tok.pos_end, f"Expected =")) res.register_advancement() self.advance() value = res.register(self.atom()) if res.error: return res optional_arg_value_nodes.append(value) if self.current_tok.type != token.T_RPAREN: return res.failure( errors.InvalidSyntaxError(self.current_tok.pos_start, self.current_tok.pos_end, "Expected ',' or ')'")) res.register_advancement() self.advance() return res.success( nodes.CallNode(atom, arg_nodes, optional_arg_name_nodes, optional_arg_value_nodes)) return res.success(atom)