postgresql/src/interfaces/ecpg/preproc
Tom Lane c9d5298485 Re-implement pl/pgsql's expression and assignment parsing.
Invent new RawParseModes that allow the core grammar to handle
pl/pgsql expressions and assignments directly, and thereby get rid
of a lot of hackery in pl/pgsql's parser.  This moves a good deal
of knowledge about pl/pgsql into the core code: notably, we have to
invent a CoercionContext that matches pl/pgsql's (rather dubious)
historical behavior for assignment coercions.  That's getting away
from the original idea of pl/pgsql as an arm's-length extension of
the core, but really we crossed that bridge a long time ago.

The main advantage of doing this is that we can now use the core
parser to generate FieldStore and/or SubscriptingRef nodes to handle
assignments to pl/pgsql variables that are records or arrays.  That
fixes a number of cases that had never been implemented in pl/pgsql
assignment, such as nested records and array slicing, and it allows
pl/pgsql assignment to support the datatype-specific subscripting
behaviors introduced in commit c7aba7c14.

There are cosmetic benefits too: when a syntax error occurs in a
pl/pgsql expression, the error report no longer includes the confusing
"SELECT" keyword that used to get prefixed to the expression text.
Also, there seem to be some small speed gains.

Discussion: https://postgr.es/m/4165684.1607707277@sss.pgh.pa.us
2021-01-04 11:52:00 -05:00
..
po Translation updates 2020-05-18 12:49:30 +02:00
.gitignore Replace the data structure used for keyword lookup. 2019-01-06 17:02:57 -05:00
c_keywords.c Make the order of the header file includes consistent in non-backend modules. 2019-10-25 07:41:52 +05:30
c_kwlist.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
check_rules.pl Update copyright for 2021 2021-01-02 13:06:25 -05:00
descriptor.c Rename ecpg's various "extern.h" files to have distinct names. 2018-12-01 16:34:00 -05:00
ecpg.addons Revert "Add DECLARE STATEMENT support to ECPG." 2019-09-20 12:47:37 -04:00
ecpg.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
ecpg.header Fix ecpg crash with bytea and cursor variables. 2020-06-30 18:34:41 +02:00
ecpg.tokens Reduce size of backend scanner's tables. 2020-01-13 15:04:31 -05:00
ecpg.trailer Fix some stray whitespace in parser files 2020-11-11 17:37:18 +01:00
ecpg.type Fix ecpg's mishandling of B'...' and X'...' literals. 2020-11-07 15:03:44 -05:00
ecpg_keywords.c Make the order of the header file includes consistent in non-backend modules. 2019-10-25 07:41:52 +05:30
ecpg_kwlist.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
keywords.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
Makefile Update copyright for 2021 2021-01-02 13:06:25 -05:00
nls.mk Translation updates 2020-05-11 13:14:32 +02:00
output.c Revert "Add DECLARE STATEMENT support to ECPG." 2019-09-20 12:47:37 -04:00
parse.pl Re-implement pl/pgsql's expression and assignment parsing. 2021-01-04 11:52:00 -05:00
parser.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
pgc.l Update copyright for 2021 2021-01-02 13:06:25 -05:00
preproc_extern.h Make the order of the header file includes consistent. 2019-11-25 08:08:57 +05:30
README.parser Move parse2.pl to parse.pl 2011-06-14 07:34:00 +03:00
type.c Refer to bug report address by symbol rather than hardcoding 2020-02-28 13:12:21 +01:00
type.h Revert "Add DECLARE STATEMENT support to ECPG." 2019-09-20 12:47:37 -04:00
variable.c Add bytea datatype to ECPG. 2019-02-18 10:20:31 +01:00

ECPG modifies and extends the core grammar in a way that
1) every token in ECPG is <str> type. New tokens are
   defined in ecpg.tokens, types are defined in ecpg.type
2) most tokens from the core grammar are simply converted
   to literals concatenated together to form the SQL string
   passed to the server, this is done by parse.pl.
3) some rules need side-effects, actions are either added
   or completely overridden (compared to the basic token
   concatenation) for them, these are defined in ecpg.addons,
   the rules for ecpg.addons are explained below.
4) new grammar rules are needed for ECPG metacommands.
   These are in ecpg.trailer.
5) ecpg.header contains common functions, etc. used by
   actions for grammar rules.

In "ecpg.addons", every modified rule follows this pattern:
       ECPG: dumpedtokens postfix
where "dumpedtokens" is simply tokens from core gram.y's
rules concatenated together. e.g. if gram.y has this:
       ruleA: tokenA tokenB tokenC {...}
then "dumpedtokens" is "ruleAtokenAtokenBtokenC".
"postfix" above can be:
a) "block" - the automatic rule created by parse.pl is completely
    overridden, the code block has to be written completely as
    it were in a plain bison grammar
b) "rule" - the automatic rule is extended on, so new syntaxes
    are accepted for "ruleA". E.g.:
      ECPG: ruleAtokenAtokenBtokenC rule
          | tokenD tokenE { action_code; }
          ...
    It will be substituted with:
      ruleA: <original syntax forms and actions up to and including
                    "tokenA tokenB tokenC">
             | tokenD tokenE { action_code; }
             ...
c) "addon" - the automatic action for the rule (SQL syntax constructed
    from the tokens concatenated together) is prepended with a new
    action code part. This code part is written as is's already inside
    the { ... }

Multiple "addon" or "block" lines may appear together with the
new code block if the code block is common for those rules.