De-reserve most statement-introducing keywords in plpgsql

Enterprise / PostgreSQL - Tom Lane [sss.pgh.pa.us] - 25 November 2014 14:02 UTC

Add a bit of context sensitivity to plpgsql_yylex() so that it can recognize when the word it is looking at is the first word of a new statement, and if so whether it is the target of an assignment statement. When we are at start of statement and it's not an assignment, we can prefer recognizing unreserved keywords over recognizing variable names, thereby allowing most statements' initial keywords to be demoted from reserved to unreserved status. This is rather useful already (there are 15 such words that get demoted here), and what's more to the point is that future patches proposing to add new plpgsql statements can avoid objections about having to add new reserved words.

The keywords BEGIN, DECLARE, FOR, FOREACH, LOOP, WHILE need to remain reserved because they can be preceded by block labels, and the logic added here doesn't understand about block labels. In principle we could probably fix that, but it would take more than one token of lookback and the benefit doesn't seem worth extra complexity.

Also note I didn't de-reserve EXECUTE, because it is used in more places than just statement start. It's possible it could be de-reserved with more work, but that would be an independent fix.

In passing, also de-reserve COLLATE and DEFAULT, which shouldn't have been reserved in the first place since they only need to be recognized within DECLARE sections.

bb1b8f6 De-reserve most statement-introducing keywords in plpgsql.
src/pl/plpgsql/src/pl_gram.y | 16 ++++
src/pl/plpgsql/src/pl_scanner.c | 144 ++++++++++++++++++++++++---------
src/test/regress/expected/plpgsql.out | 14 ++++
src/test/regress/sql/plpgsql.sql | 11 +++
4 files changed, 147 insertions(+), 38 deletions(-)

Upstream: git.postgresql.org


  • Share