For years upon years, we have endured the ugly hack of compiling
flex-generated lexers as part of some other .c file, because of
the problem explained thus in, eg, psql/mainloop.c:
/** psqlscan.c is #include'd here instead of being compiled on its own.* This is because we need postgres_fe.h to be
readbefore any system* include files, else things tend to break on platforms that have* multiple infrastructures for
stdio.hand so on. flex is absolutely* uncooperative about that, so we can't compile psqlscan.c on its own.*/
#include "psqlscan.c"
Perhaps that was true when written, but I just happened across this
bit in the flex manual:
A `%top' block is similar to a `%{' ... `%}' block, except that the code in a `%top' block is relocated to the _top_
ofthe generated file, before any flex definitions.
I've confirmed that this works as stated back to flex 2.5.33, which
is the oldest version we support. So we could compile lexers on their
own with a simple %top inclusion of postgres.h or postgres-fe.h,
as appropriate.
While I'm not quite sufficiently excited to run around and fix all our .l
files like this today, I'm definitely planning to do it for psql's lexer,
since I'm messing with that right now, and I don't much like
Horiguchi-san's solution to the problem.
regards, tom lane