[antlr-interest] Template best practice type question.

craig at palantir.co.za craig at palantir.co.za
Mon Sep 14 02:12:42 PDT 2009


Hi,

I have a tree grammar that is walking a parsed tree and outputting SQL
statements using templates.

At particular points in the tree I need to generate join clauses and where
clauses. The template looks something like this.

sql(tables, paths) ::= <<
<tables>
WHERE
<paths>
>>

or(l, r) ::= <<
<l>
OR
<r>
>>

and(l, r) ::= <<
<l>
AND
<r>
>>

comparison(path, lv, rv, op) ::= <<
<path> {<lv>} <op> {<rv>}
>>

paths generates nested OR/AND sections.
My problem is that tables and paths are essentially the same thing. The
templates need to generate a set of JOIN clauses for the tables part, and the
set of OR/AND where conditions for the paths part. Only these are exactly the
same thing.

There seems to be no general way of saying "generate the template once in mode
'a', and then again in mode 'b'". I hope I am not being too vague. I have the
OR/AND clauses generating perfectly and am in the process of hacking the table
names into a list to generate that part of the template. I feel there must be a
better way.

Thanks
Regards
Craig.

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.




More information about the antlr-interest mailing list