pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix lexing of standard multi-character operators in edge cases.
5+ messages / 1 participants
[nested] [flat]

* pgsql: Fix lexing of standard multi-character operators in edge cases.
@ 2018-08-23 20:48  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Andrew Gierth @ 2018-08-23 20:48 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix lexing of standard multi-character operators in edge cases.

Commits c6b3c939b (which fixed the precedence of >=, <=, <> operators)
and 865f14a2d (which added support for the standard => notation for
named arguments) created a class of lexer tokens which look like
multi-character operators but which have their own token IDs distinct
from Op. However, longest-match rules meant that following any of
these tokens with another operator character, as in (1<>-1), would
cause them to be incorrectly returned as Op.

The error here isn't immediately obvious, because the parser would
usually still find the correct operator via the Op token, but there
were more subtle problems:

1. If immediately followed by a comment or +-, >= <= <> would be given
   the old precedence of Op rather than the correct new precedence;

2. If followed by a comment, != would be returned as Op rather than as
   NOT_EQUAL, causing it not to be found at all;

3. If followed by a comment or +-, the => token for named arguments
   would be lexed as Op, causing the argument to be mis-parsed as a
   simple expression, usually causing an error.

Fix by explicitly checking for the operators in the {operator} code
block in addition to all the existing special cases there.

Backpatch to 9.5 where the problem was introduced.

Analysis and patch by me; review by Tom Lane.
Discussion: https://postgr.es/m/87va851ppl.fsf@news-spur.riddles.org.uk

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5b4555f90c08dd0d31572b22f5b2affdc4304b69

Modified Files
--------------
src/backend/parser/scan.l                     | 28 ++++++++++
src/fe_utils/psqlscan.l                       |  9 ++++
src/interfaces/ecpg/preproc/pgc.l             | 28 ++++++++++
src/test/regress/expected/create_operator.out | 74 +++++++++++++++++++++++++++
src/test/regress/expected/polymorphism.out    | 36 +++++++++++++
src/test/regress/sql/create_operator.sql      | 31 +++++++++++
src/test/regress/sql/polymorphism.sql         | 15 ++++++
7 files changed, 221 insertions(+)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix lexing of standard multi-character operators in edge cases.
@ 2018-08-23 20:48  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Andrew Gierth @ 2018-08-23 20:48 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix lexing of standard multi-character operators in edge cases.

Commits c6b3c939b (which fixed the precedence of >=, <=, <> operators)
and 865f14a2d (which added support for the standard => notation for
named arguments) created a class of lexer tokens which look like
multi-character operators but which have their own token IDs distinct
from Op. However, longest-match rules meant that following any of
these tokens with another operator character, as in (1<>-1), would
cause them to be incorrectly returned as Op.

The error here isn't immediately obvious, because the parser would
usually still find the correct operator via the Op token, but there
were more subtle problems:

1. If immediately followed by a comment or +-, >= <= <> would be given
   the old precedence of Op rather than the correct new precedence;

2. If followed by a comment, != would be returned as Op rather than as
   NOT_EQUAL, causing it not to be found at all;

3. If followed by a comment or +-, the => token for named arguments
   would be lexed as Op, causing the argument to be mis-parsed as a
   simple expression, usually causing an error.

Fix by explicitly checking for the operators in the {operator} code
block in addition to all the existing special cases there.

Backpatch to 9.5 where the problem was introduced.

Analysis and patch by me; review by Tom Lane.
Discussion: https://postgr.es/m/87va851ppl.fsf@news-spur.riddles.org.uk

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a40631a920accbcca1a49a909d380308d95b4674

Modified Files
--------------
src/backend/parser/scan.l                     | 28 ++++++++++
src/fe_utils/psqlscan.l                       |  9 ++++
src/interfaces/ecpg/preproc/pgc.l             | 28 ++++++++++
src/test/regress/expected/create_operator.out | 74 +++++++++++++++++++++++++++
src/test/regress/expected/polymorphism.out    | 36 +++++++++++++
src/test/regress/sql/create_operator.sql      | 31 +++++++++++
src/test/regress/sql/polymorphism.sql         | 15 ++++++
7 files changed, 221 insertions(+)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix lexing of standard multi-character operators in edge cases.
@ 2018-08-23 20:48  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Andrew Gierth @ 2018-08-23 20:48 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix lexing of standard multi-character operators in edge cases.

Commits c6b3c939b (which fixed the precedence of >=, <=, <> operators)
and 865f14a2d (which added support for the standard => notation for
named arguments) created a class of lexer tokens which look like
multi-character operators but which have their own token IDs distinct
from Op. However, longest-match rules meant that following any of
these tokens with another operator character, as in (1<>-1), would
cause them to be incorrectly returned as Op.

The error here isn't immediately obvious, because the parser would
usually still find the correct operator via the Op token, but there
were more subtle problems:

1. If immediately followed by a comment or +-, >= <= <> would be given
   the old precedence of Op rather than the correct new precedence;

2. If followed by a comment, != would be returned as Op rather than as
   NOT_EQUAL, causing it not to be found at all;

3. If followed by a comment or +-, the => token for named arguments
   would be lexed as Op, causing the argument to be mis-parsed as a
   simple expression, usually causing an error.

Fix by explicitly checking for the operators in the {operator} code
block in addition to all the existing special cases there.

Backpatch to 9.5 where the problem was introduced.

Analysis and patch by me; review by Tom Lane.
Discussion: https://postgr.es/m/87va851ppl.fsf@news-spur.riddles.org.uk

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5ec70a9286211b4734795419a292128165ca433e

Modified Files
--------------
src/backend/parser/scan.l                     | 28 ++++++++++
src/fe_utils/psqlscan.l                       |  9 ++++
src/interfaces/ecpg/preproc/pgc.l             | 28 ++++++++++
src/test/regress/expected/create_operator.out | 74 +++++++++++++++++++++++++++
src/test/regress/expected/polymorphism.out    | 36 +++++++++++++
src/test/regress/sql/create_operator.sql      | 31 +++++++++++
src/test/regress/sql/polymorphism.sql         | 15 ++++++
7 files changed, 221 insertions(+)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix lexing of standard multi-character operators in edge cases.
@ 2018-08-23 20:48  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Andrew Gierth @ 2018-08-23 20:48 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix lexing of standard multi-character operators in edge cases.

Commits c6b3c939b (which fixed the precedence of >=, <=, <> operators)
and 865f14a2d (which added support for the standard => notation for
named arguments) created a class of lexer tokens which look like
multi-character operators but which have their own token IDs distinct
from Op. However, longest-match rules meant that following any of
these tokens with another operator character, as in (1<>-1), would
cause them to be incorrectly returned as Op.

The error here isn't immediately obvious, because the parser would
usually still find the correct operator via the Op token, but there
were more subtle problems:

1. If immediately followed by a comment or +-, >= <= <> would be given
   the old precedence of Op rather than the correct new precedence;

2. If followed by a comment, != would be returned as Op rather than as
   NOT_EQUAL, causing it not to be found at all;

3. If followed by a comment or +-, the => token for named arguments
   would be lexed as Op, causing the argument to be mis-parsed as a
   simple expression, usually causing an error.

Fix by explicitly checking for the operators in the {operator} code
block in addition to all the existing special cases there.

Backpatch to 9.5 where the problem was introduced.

Analysis and patch by me; review by Tom Lane.
Discussion: https://postgr.es/m/87va851ppl.fsf@news-spur.riddles.org.uk

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/af988d13012f899631d41ab5120e36d8069b1444

Modified Files
--------------
src/backend/parser/scan.l                     | 28 ++++++++++
src/bin/psql/psqlscan.l                       |  9 ++++
src/interfaces/ecpg/preproc/pgc.l             | 28 ++++++++++
src/test/regress/expected/create_operator.out | 74 +++++++++++++++++++++++++++
src/test/regress/expected/polymorphism.out    | 36 +++++++++++++
src/test/regress/sql/create_operator.sql      | 31 +++++++++++
src/test/regress/sql/polymorphism.sql         | 15 ++++++
7 files changed, 221 insertions(+)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix lexing of standard multi-character operators in edge cases.
@ 2018-08-23 20:48  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Andrew Gierth @ 2018-08-23 20:48 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix lexing of standard multi-character operators in edge cases.

Commits c6b3c939b (which fixed the precedence of >=, <=, <> operators)
and 865f14a2d (which added support for the standard => notation for
named arguments) created a class of lexer tokens which look like
multi-character operators but which have their own token IDs distinct
from Op. However, longest-match rules meant that following any of
these tokens with another operator character, as in (1<>-1), would
cause them to be incorrectly returned as Op.

The error here isn't immediately obvious, because the parser would
usually still find the correct operator via the Op token, but there
were more subtle problems:

1. If immediately followed by a comment or +-, >= <= <> would be given
   the old precedence of Op rather than the correct new precedence;

2. If followed by a comment, != would be returned as Op rather than as
   NOT_EQUAL, causing it not to be found at all;

3. If followed by a comment or +-, the => token for named arguments
   would be lexed as Op, causing the argument to be mis-parsed as a
   simple expression, usually causing an error.

Fix by explicitly checking for the operators in the {operator} code
block in addition to all the existing special cases there.

Backpatch to 9.5 where the problem was introduced.

Analysis and patch by me; review by Tom Lane.
Discussion: https://postgr.es/m/87va851ppl.fsf@news-spur.riddles.org.uk

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d64fad6669926c95f1a2e49ebec58ed4412be1a0

Modified Files
--------------
src/backend/parser/scan.l                     | 28 ++++++++++
src/fe_utils/psqlscan.l                       |  9 ++++
src/interfaces/ecpg/preproc/pgc.l             | 28 ++++++++++
src/test/regress/expected/create_operator.out | 74 +++++++++++++++++++++++++++
src/test/regress/expected/polymorphism.out    | 36 +++++++++++++
src/test/regress/sql/create_operator.sql      | 31 +++++++++++
src/test/regress/sql/polymorphism.sql         | 15 ++++++
7 files changed, 221 insertions(+)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2018-08-23 20:48 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-08-23 20:48 pgsql: Fix lexing of standard multi-character operators in edge cases. Andrew Gierth <rhodiumtoad@postgresql.org>
2018-08-23 20:48 pgsql: Fix lexing of standard multi-character operators in edge cases. Andrew Gierth <rhodiumtoad@postgresql.org>
2018-08-23 20:48 pgsql: Fix lexing of standard multi-character operators in edge cases. Andrew Gierth <rhodiumtoad@postgresql.org>
2018-08-23 20:48 pgsql: Fix lexing of standard multi-character operators in edge cases. Andrew Gierth <rhodiumtoad@postgresql.org>
2018-08-23 20:48 pgsql: Fix lexing of standard multi-character operators in edge cases. Andrew Gierth <rhodiumtoad@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox