flex: where's THIS been all this time?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: flex: where's THIS been all this time?
Date: 2016-03-18 23:28:13
Message-ID: 16217.1458343693@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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 read before any system
* include files, else things tend to break on platforms that have
* multiple infrastructures for stdio.h and 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_ of the 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


Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Karlsson 2016-03-18 23:46:26 Re: POC, WIP: OR-clause support for indexes
Previous Message Artur Zakirov 2016-03-18 22:18:37 Re: Fuzzy substring searching with the pg_trgm extension