Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdMIU-0003Ic-0Q for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Jul 2018 21:05:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fdMIS-0008Bv-Ba for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Jul 2018 21:05:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdMIS-0008Bn-5X for pgsql-bugs@lists.postgresql.org; Wed, 11 Jul 2018 21:05:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdMIP-00089D-1U for pgsql-bugs@lists.postgresql.org; Wed, 11 Jul 2018 21:05:11 +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 w6BL55RX018385; Wed, 11 Jul 2018 17:05:06 -0400 From: Tom Lane To: Andrew Gierth cc: ladayaroslav@yandex.ru, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15273: Lexer bug with UESCAPE In-reply-to: <87bmbekq90.fsf@news-spur.riddles.org.uk> References: <153124291307.1408.15617588871690313363@wrigleys.postgresql.org> <23850.1531252251@sss.pgh.pa.us> <87bmbekq90.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Wed, 11 Jul 2018 13:03:41 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18383.1531343105.1@sss.pgh.pa.us> Date: Wed, 11 Jul 2018 17:05:05 -0400 Message-ID: <18384.1531343105@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> Also, I'm going to push back on the claim that allowing comments > Tom> there is required by the SQL spec. > These are the rules that (as far as I can see) apply to that case: > 5.2 and > 7) Any may be followed by a . Right, but that only gets the result you claim if you suppose that a consists of more than one . I don't think so, because the start of the section states ::= | ::= | | | | | | | | and then reading down, we have ::= [ ] U [ ... ] [ { [ ... ] }... ] There isn't anything here that equates with any sub-part of a . Unless you want to argue that and can be derived from , but if you take that path you're left to explain why whitespace at the start of the literal contents is data and not a . Of course, there's certainly an argument to be made that the intent is that the U&'...' part be one token and then UESCAPE and the escape string are two more, but the SQL committee just can't specify their way out of a paper bag. We knew that already. Anyway, as I said before, I can't see that we would want to fix this by extending the existing implementation --- you'd need a bunch more exclusive lexer states which would be a pain in the rear, and possibly a performance problem too. I do wonder though why Peter did it like that. You could imagine returning three tokens to the grammar and letting the grammar merge them, which'd make the lexer aspect of this far simpler and perhaps not complicate the grammar too much. Another thing I noticed about the existing implementation is that it's very unfriendly if you write an invalid escape specifier: postgres=# select U&'foo' uescape 'bar'; ERROR: syntax error at or near "'bar'" LINE 1: select U&'foo' uescape 'bar'; ^ It'd be much nicer to say something along the line of "Unicode escape specifier must be a single character", but shoehorning that into the lexer-based implementation would be a giant pain. I'm not excited enough about any of this to spend more time on it, but maybe somebody else is. regards, tom lane