Search in sources :

Example 1 with IStrategoString

use of org.spoofax.interpreter.terms.IStrategoString in project spoofax by metaborg.

the class StrategoCommon method locationTerm.

@Override
public IStrategoString locationTerm(FileObject location) {
    final ITermFactory termFactory = termFactoryService.getGeneric();
    final String locationURI = location.getName().getURI();
    final IStrategoString locationTerm = termFactory.makeString(locationURI);
    return locationTerm;
}
Also used : IStrategoString(org.spoofax.interpreter.terms.IStrategoString) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) ITermFactory(org.spoofax.interpreter.terms.ITermFactory)

Example 2 with IStrategoString

use of org.spoofax.interpreter.terms.IStrategoString in project spoofax by metaborg.

the class StrategoCommon method prettyPrint.

@Override
public IStrategoString prettyPrint(IStrategoTerm term) {
    final Context context = strategoRuntimeService.genericRuntime().getCompiledContext();
    final ITermFactory termFactory = termFactoryService.getGeneric();
    org.strategoxt.stratego_aterm.Main.init(context);
    term = aterm_escape_strings_0_0.instance.invoke(context, term);
    term = pp_aterm_box_0_0.instance.invoke(context, term);
    term = box2text_string_0_1.instance.invoke(context, term, termFactory.makeInt(120));
    return (IStrategoString) term;
}
Also used : Context(org.strategoxt.lang.Context) IContext(org.metaborg.core.context.IContext) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) ITermFactory(org.spoofax.interpreter.terms.ITermFactory)

Example 3 with IStrategoString

use of org.spoofax.interpreter.terms.IStrategoString in project spoofax by metaborg.

the class LanguageComponentsPrimitive method call.

@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException, IOException {
    IStrategoList list = factory.makeList();
    for (ILanguageComponent component : context.language().components()) {
        final LanguageIdentifier id = component.id();
        final IStrategoString groupIdTerm = factory.makeString(id.groupId);
        final IStrategoString idTerm = factory.makeString(id.id);
        final IStrategoString versionTerm = factory.makeString(id.version.toString());
        final IStrategoString locationTerm = factory.makeString(component.location().getName().getURI());
        final IStrategoTuple tuple = factory.makeTuple(groupIdTerm, idTerm, versionTerm, locationTerm);
        list = factory.makeListCons(tuple, list);
    }
    return list;
}
Also used : LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) IStrategoTuple(org.spoofax.interpreter.terms.IStrategoTuple) IStrategoList(org.spoofax.interpreter.terms.IStrategoList) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 4 with IStrategoString

use of org.spoofax.interpreter.terms.IStrategoString in project spoofax by metaborg.

the class LanguageImplementationPrimitive method call.

@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException, IOException {
    final ILanguageImpl langImpl = context.language();
    final LanguageIdentifier langId = langImpl.id();
    final IStrategoString groupIdTerm = factory.makeString(langId.groupId);
    final IStrategoString idTerm = factory.makeString(langId.id);
    final IStrategoString versionTerm = factory.makeString(langId.version.toString());
    return factory.makeTuple(groupIdTerm, idTerm, versionTerm);
}
Also used : LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) IStrategoString(org.spoofax.interpreter.terms.IStrategoString)

Example 5 with IStrategoString

use of org.spoofax.interpreter.terms.IStrategoString in project spoofax by metaborg.

the class LocalPathPrimitive method call.

@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) {
    if (!(current instanceof IStrategoString)) {
        return null;
    }
    final IStrategoString currentStr = (IStrategoString) current;
    final String path = currentStr.stringValue();
    final FileObject resource = resourceService.resolve(path);
    final File localPath = resourceService.localPath(resource);
    if (localPath == null) {
        return null;
    }
    return factory.makeString(localPath.getPath());
}
Also used : IStrategoString(org.spoofax.interpreter.terms.IStrategoString) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File)

Aggregations

IStrategoString (org.spoofax.interpreter.terms.IStrategoString)29 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)16 IStrategoAppl (org.spoofax.interpreter.terms.IStrategoAppl)11 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)11 FileObject (org.apache.commons.vfs2.FileObject)10 IStrategoTuple (org.spoofax.interpreter.terms.IStrategoTuple)10 MetaborgException (org.metaborg.core.MetaborgException)7 HybridInterpreter (org.strategoxt.HybridInterpreter)7 ICompletion (org.metaborg.core.completion.ICompletion)6 IStrategoList (org.spoofax.interpreter.terms.IStrategoList)6 StrategoAppl (org.spoofax.terms.StrategoAppl)5 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)4 LanguageIdentifier (org.metaborg.core.language.LanguageIdentifier)4 Nullable (javax.annotation.Nullable)3 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)3 IStrategoInt (org.spoofax.interpreter.terms.IStrategoInt)3 File (java.io.File)2 IOException (java.io.IOException)2 AnalysisException (org.metaborg.core.analysis.AnalysisException)2 ConfigException (org.metaborg.core.config.ConfigException)2