How to implement a macro processor?

32 views
Skip to first unread message

Jochen Wiedmann

unread,
Mar 19, 2015, 3:21:30 AM3/19/15
to antlr-di...@googlegroups.com

Hi,

I am preparing to write a lot of SQL files, which are to be processed by an application. Depending on the database, there are slight differences. So, the worst case would be to have varios versions of all files, depending on the database vendor.

My current idea to simplify that process (and the future maintenance of those files) would be not to read those files directly, but to have some kind of macro processor (think C preprocessor) in front, so that my input files could look like

  $if mysql
  $idtype() := BIGINT NOT NULL PRIMARY KEY $:
  $varchar(length) := VARCHAR(${length}) $:
  $blobtype() := MEDIUM BLOB $:
  $else if oracle
  $idtype() := BIGINT NOT NULL PRIMARY KEY $:
  $varchar(length) := VARCHAR(${length}) $:
  $blobtype() := BLOB $:
  ...
  $endif

  CREATE TABLE foo (id ${idtype}, name varchar(64), contract ${blobtype})

Now, to my questions:

1.) Is anybody aware of something similar that already exists, and could be reused?
2.) Any recommendations on how to design the language so that the creation of an AntLR grammar is easy?
3.) Would it be possible to integrate support for something like #include <filename> into a a TokenStream?

Thanks,

Jochen

Jim Idle

unread,
Mar 19, 2015, 3:54:16 AM3/19/15
to antlr-di...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jochen Wiedmann

unread,
Mar 19, 2015, 4:26:01 AM3/19/15
to antlr-di...@googlegroups.com


On Thursday, March 19, 2015 at 8:54:16 AM UTC+1, Jim Idle wrote:

Just noticed: I am a coward. :-)
Reply all
Reply to author
Forward
0 new messages