Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cge24-0000SR-KV for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Feb 2017 21:01:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cge23-0007PZ-5C for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Feb 2017 21:01:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cge22-0007PM-Cd; Wed, 22 Feb 2017 21:01:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cge20-0006UF-9h; Wed, 22 Feb 2017 21:01:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v1ML0oqW016857; Wed, 22 Feb 2017 16:00:50 -0500 From: Tom Lane To: Corey Huinker cc: Fabien COELHO , Greg Stark , Erik Rijkers , Robert Haas , Daniel Verite , Jim Nasby , PostgreSQL , pgsql-hackers-owner@postgresql.org Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless) In-reply-to: References: <24063.1486671184@sss.pgh.pa.us> <5095.1486674948@sss.pgh.pa.us> <4fb8635d88c7dc907d069e15fdd1ab94@xs4all.nl> <28640.1487108678@sss.pgh.pa.us> Comments: In-reply-to Corey Huinker message dated "Wed, 22 Feb 2017 10:20:33 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16855.1487797250.1@sss.pgh.pa.us> Date: Wed, 22 Feb 2017 16:00:50 -0500 Message-ID: <16856.1487797250@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Corey Huinker writes: >> but if you think that it should be somewhere else, please advise Corey >> about where to put it. > Just a reminder that I'm standing by for advice. Sorry, I'd lost track of this thread. > The issue at hand is whether the if-state should be a part of the > PsqlScanState, or if it should be a separate state variable owned by > MainLoop() and passed to HandleSlashCommands(), ... or some other solution. My reaction to putting it in PsqlScanState is pretty much "over my dead body". That's just trashing any pretense of an arms-length separation between psql and the lexer proper. We only recently got done sweating blood to create that separation, why would we toss it away already? If you're concerned about the notational overhead of passing two arguments rather than one, my druthers would be to invent a new struct type, perhaps named along the lines of PsqlFileState or PsqlInputState, and pass that around. One of its fields would be a PsqlScanState pointer, the rest would be for if-state and whatever else we think we need in per-input-file state. However, that way is doubling down on the assumption that the if-state is exactly one-to-one with input file levels, isn't it? We might be better off to just live with the separate arguments to preserve some flexibility in that regard. The v12 patch doesn't look that awful in terms of what it's adding to argument lists. One thing I'm wondering is why the "active_branch" bool is in "pset" and not in the conditional stack. That seems, at best, pretty grotty. _psqlSettings is meant for reasonably persistent state. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers