Search in sources :

Example 1 with ResourceService

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;
}
Also used : IContext(org.spoofax.interpreter.core.IContext) InputStream(java.io.InputStream) ResourceService(org.metaborg.core.resource.ResourceService) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) IOException(java.io.IOException) FileObject(org.apache.commons.vfs2.FileObject) ITermFactory(org.spoofax.interpreter.terms.ITermFactory)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 FileObject (org.apache.commons.vfs2.FileObject)1 ResourceService (org.metaborg.core.resource.ResourceService)1 IContext (org.spoofax.interpreter.core.IContext)1 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)1 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)1