use of org.metaborg.core.resource.ResourceService in project spoofax by metaborg.
the class GetContextualGrammarPrimitive method call.
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
org.metaborg.core.context.IContext context = (org.metaborg.core.context.IContext) env.contextObject();
String path = ((IStrategoString) tvars[0]).stringValue();
ResourceService rs = context.injector().getInstance(ResourceService.class);
FileObject fo = rs.resolve(path + "/target/metaborg/ctxgrammar.aterm");
InputStream inputStream;
String text = "";
try {
inputStream = fo.getContent().getInputStream();
text = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());
} catch (IOException e) {
e.printStackTrace();
}
final ITermFactory tf = env.getFactory();
env.setCurrent(tf.parseFromString(text));
return true;
}
Aggregations