Search in sources :

Example 1 with ILanguageComponent

use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.

the class LanguageDiscoveryService method scanComponentsInDirectory.

@Override
public Set<ILanguageComponent> scanComponentsInDirectory(FileObject directory) throws MetaborgException {
    final Collection<IComponentCreationConfigRequest> requests = componentFactory.requestAllInDirectory(directory);
    final Collection<ComponentCreationConfig> configs = componentFactory.createConfigs(requests);
    final Set<ILanguageComponent> components = Sets.newHashSet();
    for (ComponentCreationConfig config : configs) {
        final ILanguageComponent component = languageService.add(config);
        components.add(component);
    }
    return components;
}
Also used : IComponentCreationConfigRequest(org.metaborg.core.language.IComponentCreationConfigRequest) ComponentCreationConfig(org.metaborg.core.language.ComponentCreationConfig) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 2 with ILanguageComponent

use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.

the class DialectService method remove.

@Override
public Iterable<ILanguageImpl> remove(ILanguageImpl base) {
    final Collection<ILanguageImpl> dialects = baseLanguageToDialects.get(base);
    if (dialects.isEmpty()) {
        return dialects;
    }
    logger.debug("Removing {} dialects for base language {}", dialects.size(), base);
    final Collection<ILanguageImpl> removedDialects = Lists.newArrayListWithCapacity(dialects.size());
    for (ILanguageImpl dialect : dialects) {
        final String name = dialect.belongsTo().name();
        nameToDialect.remove(name);
        dialectToBase.remove(dialect);
        baseLanguageToDialects.remove(base, dialect);
        try {
            // Remove dialect after updating maps, exception indicates that dialect has already been removed.
            final ILanguageComponent dialectComponent = Iterables.get(dialect.components(), 0);
            languageService.remove(dialectComponent);
        } catch (IllegalStateException e) {
            final String message = String.format("Error removing dialect %s", name);
            logger.error(message, e);
            continue;
        }
        removedDialects.add(dialect);
    }
    return removedDialects;
}
Also used : ILanguageImpl(org.metaborg.core.language.ILanguageImpl) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 3 with ILanguageComponent

use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.

the class DialectService method remove.

@Override
public ILanguageImpl remove(String name) {
    final ILanguageImpl dialect = nameToDialect.remove(name);
    if (dialect == null) {
        final String message = String.format("Dialect with name %s does not exist", name);
        logger.error(message);
        throw new MetaborgRuntimeException(message);
    }
    logger.debug("Removing dialect {}", name);
    final ILanguageImpl base = dialectToBase.remove(dialect);
    baseLanguageToDialects.remove(base, dialect);
    try {
        // Remove dialect after updating maps, exception indicates that dialect has already been removed.
        final ILanguageComponent dialectComponent = Iterables.get(dialect.components(), 0);
        languageService.remove(dialectComponent);
    } catch (IllegalStateException e) {
        final String message = String.format("Error removing dialect %s", name);
        logger.error(message, e);
    }
    return dialect;
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 4 with ILanguageComponent

use of org.metaborg.core.language.ILanguageComponent in project spoofax by metaborg.

the class CallStrategyPrimitive method call.

@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext currentContext) throws MetaborgException {
    final String languageName = Tools.asJavaString(tvars[0]);
    final String strategyName = Tools.asJavaString(tvars[1]);
    final Iterable<ILanguageComponent> compileDeps = dependencyService.compileDeps(currentContext.project());
    final Iterable<ILanguageImpl> impls = LanguageUtils.toImpls(compileDeps);
    final List<ILanguageImpl> selectedImpls = Lists.newArrayList();
    for (ILanguageImpl impl : impls) {
        if (impl.belongsTo().name().equals(languageName)) {
            selectedImpls.add(impl);
        }
    }
    if (selectedImpls.isEmpty()) {
        final String message = logger.format("Stratego strategy call of '{}' into language '{}' failed, no language implementation found", strategyName, languageName);
        throw new MetaborgException(message);
    } else if (selectedImpls.size() > 1) {
        final String message = logger.format("Stratego strategy call of '{}' into language '{}' failed, multiple language implementations found: {}", strategyName, languageName, Joiner.on(", ").join(selectedImpls));
        throw new MetaborgException(message);
    }
    final ILanguageImpl impl = selectedImpls.get(0);
    final IContext context = contextService.get(currentContext.location(), currentContext.project(), impl);
    return common.invoke(impl, context, current, strategyName);
}
Also used : IContext(org.metaborg.core.context.IContext) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) MetaborgException(org.metaborg.core.MetaborgException) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 5 with ILanguageComponent

use of org.metaborg.core.language.ILanguageComponent 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)

Aggregations

ILanguageComponent (org.metaborg.core.language.ILanguageComponent)40 FileObject (org.apache.commons.vfs2.FileObject)26 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)24 Test (org.junit.Test)12 LanguageIdentifier (org.metaborg.core.language.LanguageIdentifier)11 LanguageVersion (org.metaborg.core.language.LanguageVersion)11 MetaborgTest (org.metaborg.core.test.MetaborgTest)11 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)9 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)9 HybridInterpreter (org.strategoxt.HybridInterpreter)9 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)8 ILanguage (org.metaborg.core.language.ILanguage)7 MetaborgException (org.metaborg.core.MetaborgException)6 IContext (org.metaborg.core.context.IContext)5 Nullable (javax.annotation.Nullable)4 MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)4 ICompletion (org.metaborg.core.completion.ICompletion)4 IStrategoList (org.spoofax.interpreter.terms.IStrategoList)4 IOException (java.io.IOException)3 FileSystemException (org.apache.commons.vfs2.FileSystemException)3