[antlr-interest] Using ANTLR within eclipse plugin

Nauman recluze at gmail.com
Sun Apr 18 06:03:02 PDT 2010


Hi,

I am trying to use ANTLR and StringTemplate to write an eclipse plugin that
does language transformation. I have a view that takes the text from an
editor and puts the output in another textbox. The problem is that within
the plugin, I don't have access to the template file (EvalPolicy.stg below)
directly. I can get an IFile and read from it but it isn't compatible with
the FileReader and so, I can't pass it to the StringTemplateGroup.

groupFileR = new FileReader(FILEPATH);
StringTemplateGroup templates = new StringTemplateGroup(groupFileR);
// doesn't work because FILEPATH is within a jar etc etc.

I tried reading the whole file in the string and then passing it to the
constructor of StringTemplateGroup but I get the error:

Can't find template policyType.st; group hierarchy is [group EvalPolicy;
showType(type) ::= "something type <type>"
policyType(ptype) ::= <<
<ptype>
>>


Here's what I have in the plugin code

Bundle bundle = Platform.getBundle("ape");
Path path = new Path("src/EvalPolicy.stg");
URL fileURL = FileLocator.find(bundle, path, null);
 InputStream is = null;

try {
is = fileURL.openStream();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}

StringBuilder sb = new StringBuilder();
String line;

try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
is.close();
} catch (IOException e) {
e.printStackTrace();
}

strTemplateGroup = sb.toString();

StringTemplateGroup templates = new StringTemplateGroup(strTemplateGroup);


So, is it possible to create a FileReader through an IFile? If not, how can
I properly pass the string to the overloaded StringTemplateGroup(String)
constructor?

Thanks for the help,

Nauman

PhD Candidate
University of Peshawar
Peshawar, Pakistan

Blog: http://recluze.wordpress.com
Art gallery: http://flickr.com/recluze

Contact number: Use email.


More information about the antlr-interest mailing list