• Tom Lane's avatar
    De-reserve most statement-introducing keywords in plpgsql. · bb1b8f69
    Tom Lane authored
    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.
    bb1b8f69
plpgsql.sql 106 KB