[antlr-interest] StringTemplate questions

Barnes, Jeff JB0284 at att.com
Thu Nov 8 05:58:22 PST 2007


I think you may want to try something like this:

ArrayList keyNameList = new ArrayList( Arrays.asList( keyNames ) );
templateObject.setLeft( leftTableName );
templateObject.setRight( rightTableName );
templateObject.setKeyNames( ( String[] ) keyNameList.toArray( new String[ 0 ] ) );

Then your template would look like this, perhaps:

selectStmt ::= <<
SELECT * FROM $templateObject.left$$if( templateObject.keyNames )$ WHERE $templateObject.keyNames | keyName {
$keyName$ NOT IN ( SELECT $keyName$ FROM $templateObject.right$ )
}; separator="\n"$$endif$
>>

I haven't tested this template, so the usual caveats apply.

Best regards,
Jeff
________________________________________
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of G R
Sent: Thursday, November 08, 2007 8:33 AM
To: antlr-interest Interest
Subject: [antlr-interest] StringTemplate questions

Hi,

I'm trying to use ST to translate relational algebra into SQL, and I'm stuck with a template :
"minus(left, right, keys)" where left, and right are just text, and keys is a list of string (I want it to be a list of String). 

So first question is how in Java do I build a ST list of string ?

Then, using my 3 attributes (left, right and keys), I'd like to generate the following code :

SELECT * FROM <left>
WHERE key1 NOT IN (SELECT key1 FROM <right>) 
AND  key2 NOT IN (SELECT key2 FROM <right>)
...
AND  keyN NOT IN (SELECT keyN FROM <right>)

where key1, key2, ... keyN are the element of my list.

How can i do this ? Can i use an attribute within the separator of a list ? 

Thanks for any help.

G.R


More information about the antlr-interest mailing list