mridoni / gixsql

GixSQL is an ESQL preprocessor and a series of runtime libraries to enable GnuCOBOL to access PostgreSQL, ODBC, MySQL, Oracle and SQLite databases.
GNU General Public License v3.0
16 stars 8 forks source link

gixpp: add conditional compilation #11

Open GitMensch opened 2 years ago

GitMensch commented 2 years ago

The samples already include samples of conditional compilation in ISO2002 format, but those are just skipped completely for now. Additional there's the Micro Focus format to handle.

Actually doing the conditional compilation is important for "partial" construct, as those must lead the parser to fail currently. Example:

       01 L-DYNBUFFER.
          05 FILLER
      $IF USE-GNUCOBOL = 1
                              OCCURS UNBOUNDED
      $ELSE
                              OCCURS 0 TO MAX-BLOB-SIZE TIMES
      $END
                              DEPENDING ON L-DYNBUFFER-LEN
                              PIC X.

With the current "ignore the directives" approach this leads to bad COBOL (two OCCURS).

Note: nothing that needs to be done "soon", just an issue to keep in mind when working on the parser, maybe with mridoni/gixsql#20.

mridoni commented 2 years ago

You are right, of course, and one way around it could be restructuring the parser and add a "pre-preprocessing" phase (there are already hooks for this, libgixpp actually is structured as sort of a pipeline).

One more idea I am working on (this is more for the IDE, actually) is using GnuCOBOL's scanner/parser in cobc as a library, obviously extending it to support EXEC SQL (or generic EXEC ) statements : the code generation in the backend would have to be rewritten to get its input data from GnuCOBOL's AST, but a lot more information would be available.

The main problem, from the experiments I have performed so far, is that it is difficult to this cleanly: the scanner/parser is obviously tightly connected (and rightly so) with the other parts of cobc, and you have to bring along a lot of libcob anyway. I'll keep investigating anyway to see if anything comes from it.

GitMensch commented 2 years ago

For the IDE and for cobc the following would be reasonable (it may also be done to gixsql but in this case this would be fixed to "newest GnuCOBOL version only - no older versions, no other compilers" which I'd recommend against), too:

the preprocessor can leave #error directives in or outputs errors/warnings on its own.

If you would like to work on this in GnuCOBOL then I'd luckily create a feature-branch for you. (even then gixsql could have a 'stand alone' variant which doesn't require cobc - but then also don't support conditional compilation)

mridoni commented 2 years ago

If you would like to work on this in GnuCOBOL then I'd luckily create a feature-branch for you. (even then gixsql could have a 'stand alone' variant which doesn't require cobc - but then also don't support conditional compilation)

This would be interesting and I'll take it into serious consideration but obviously it it will take some time before we get there.