Modernize plpgsql's handling of parse locations, making it look a lot more
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 9 Nov 2009 00:26:55 +0000 (00:26 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 9 Nov 2009 00:26:55 +0000 (00:26 +0000)
commit39bd3fd1db6f3aa3764d4a1bebcd71c4e9c00281
treea4a2c77350e2fe224ce8ec4f1c60ba910c938e35
parentfb60af4127c006cb2e945fc1ee461264988ca753
Modernize plpgsql's handling of parse locations, making it look a lot more
like the core parser's code.  In particular, track locations at the character
rather than line level during parsing, allowing many more parse-time error
conditions to be reported with precise error pointers rather than just
"near line N".

Also, exploit the fact that we no longer need to substitute $N for variable
references by making extracted SQL queries and expressions be exact copies
of subranges of the function text, rather than having random whitespace
changes within them.  This makes it possible to directly map parse error
positions from the core parser onto positions in the function text, which
lets us report them without the previous kluge of showing the intermediate
internal-query form.  (Later it might be good to do that for core
parse-analysis errors too, but this patch is just touching plpgsql's
lexer/parser, not what happens at runtime.)

In passing, make plpgsql's lexer use palloc not malloc.

These changes make plpgsql's parse-time error reports noticeably nicer
(as illustrated by the regression test changes), and will also simplify
the planned removal of plpgsql's separate lexer by reducing the impedance
mismatch between what it does and what the core lexer does.
src/pl/plpgsql/src/gram.y
src/pl/plpgsql/src/pl_comp.c
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/plpgsql.h
src/pl/plpgsql/src/scan.l
src/test/regress/expected/plpgsql.out