[stringtemplate-interest] how can I retrieve attribute names from a string template???

stefan stefan at amiq.ro
Tue May 31 07:12:38 PDT 2005


Hello,

       I have next template :
group main;
header(mdea, file) ::= <<
// Medea : $medea$
// File : $file$
>>
            and I would like to extract the attributes names and use them to 
interogate a map.  In this case would be : { medea, file}.
            How can I do that?
          
           I tried to use the following methods with the results : 
 - getAttributes() : it returns a map with one key : "attributes"
 - getChunks()    : it returns some ASTExpr which I can not use
 - getFormArguments() : it returns a map with three elements :
                   ' {attributes=attributes, file=file, mdea=mdea} '

          The most promising seems to be getFormAttributes().
       
Stefan.

PS:
--------------------------------------------------------------------------------------------------
                               CODE FOR TEST 
--------------------------------------------------------------------------------------------------
import java.util.*;
import java.io.*;
import java.net.*;

import org.antlr.stringtemplate.*;

public class Main {

   public static void main(String[] args){
      try {
         StringTemplate.setLintMode(true);
         System.out.println("---1 ");
         StringTemplateGroup allGroup = new StringTemplateGroup(new 
FileReader("./main.st"));
         System.out.println("---Group =  " + allGroup.toString());
         StringTemplate _st = allGroup.getInstanceOf("header");
         // if next line is missing, getAttributes() throws an error          
            (NullPointerException)
         System.out.println("---3 " + _st.toString());
         Map _map = _st.getAttributes();
         System.out.println("--- Attributes key set : " + _map.keySet());
         System.out.println("--- Attributes value set : " + _map.values());
         System.out.println("---Form Arguments = " + _st.getFormArguments());
         System.out.println("---Chunks = " + _st.getChunks());
      }catch (Exception e){
         System.out.println(e.toString());
      }
   }
}


More information about the stringtemplate-interest mailing list