Search in sources :

Example 21 with ILanguageComponent

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

the class ActionService method actionContributions.

@Override
public Collection<TransformActionContrib> actionContributions(ILanguageImpl language, ITransformGoal goal) {
    final Iterable<FacetContribution<ActionFacet>> facetsContributions = language.facetContributions(ActionFacet.class);
    final Collection<TransformActionContrib> actionContributions = Lists.newLinkedList();
    for (FacetContribution<ActionFacet> facetContribution : facetsContributions) {
        final ActionFacet facet = facetContribution.facet;
        final ILanguageComponent component = facetContribution.contributor;
        for (ITransformAction action : facet.actions(goal)) {
            actionContributions.add(new TransformActionContrib(action, component));
        }
    }
    return actionContributions;
}
Also used : TransformActionContrib(org.metaborg.core.action.TransformActionContrib) FacetContribution(org.metaborg.core.language.FacetContribution) ITransformAction(org.metaborg.core.action.ITransformAction) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 22 with ILanguageComponent

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

the class LanguageDiscoveryService method create.

private ILanguageComponent create(IComponentCreationConfigRequest request) throws MetaborgException {
    final ComponentCreationConfig config = componentFactory.createConfig(request);
    final ILanguageComponent component = languageService.add(config);
    return component;
}
Also used : ComponentCreationConfig(org.metaborg.core.language.ComponentCreationConfig) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 23 with ILanguageComponent

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

the class DialectService method createDialect.

private ILanguageImpl createDialect(String name, FileObject location, ILanguageImpl base, IFacet syntaxFacet, boolean replaceIdentification, boolean appendDialectName) {
    final LanguageIdentifier baseId = base.id();
    final String dialectId;
    if (appendDialectName) {
        dialectId = baseId.id + "-Dialect-" + name;
    } else {
        dialectId = baseId.id;
    }
    final LanguageIdentifier id = new LanguageIdentifier(baseId.groupId, dialectId, baseId.version);
    // HACK: use config of first component.
    final ILanguageComponentConfig config = Iterables.get(base.components(), 0).config();
    final ComponentCreationConfig creationConfig = languageService.create(id, location, Iterables2.singleton(new LanguageContributionIdentifier(id, name)), config);
    for (IFacet facet : base.facets()) {
        if (facet instanceof IdentificationFacet && replaceIdentification) {
            creationConfig.addFacet(new IdentificationFacet(new MetaFileIdentifier((IdentificationFacet) facet)));
        } else if (facet instanceof SyntaxFacet || facet instanceof ResourceExtensionFacet) {
        // Ignore
        } else {
            creationConfig.addFacet(facet);
        }
    }
    creationConfig.addFacet(syntaxFacet);
    final ILanguageComponent dialectComponent = languageService.add(creationConfig);
    final ILanguageImpl dialect = Iterables.get(dialectComponent.contributesTo(), 0);
    return dialect;
}
Also used : SyntaxFacet(org.metaborg.spoofax.core.syntax.SyntaxFacet) LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) IdentificationFacet(org.metaborg.core.language.IdentificationFacet) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) IFacet(org.metaborg.core.language.IFacet) ResourceExtensionFacet(org.metaborg.core.language.ResourceExtensionFacet) ComponentCreationConfig(org.metaborg.core.language.ComponentCreationConfig) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) ILanguageComponentConfig(org.metaborg.core.config.ILanguageComponentConfig) LanguageContributionIdentifier(org.metaborg.core.language.LanguageContributionIdentifier)

Example 24 with ILanguageComponent

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

the class OutlineService method outline.

@Override
public IOutline outline(ISpoofaxAnalyzeUnit result) throws MetaborgException {
    if (!result.valid() || !result.hasAst()) {
        return null;
    }
    final FileObject source = result.source();
    final IContext context = result.context();
    final ILanguageImpl language = context.language();
    final FacetContribution<OutlineFacet> facetContrib = facet(language);
    final OutlineFacet facet = facetContrib.facet;
    final ILanguageComponent contributor = facetContrib.contributor;
    final String strategy = facet.strategyName;
    try {
        final HybridInterpreter interpreter = strategoRuntimeService.runtime(contributor, context, true);
        final IStrategoTerm input = common.builderInputTerm(result.ast(), source, context.location());
        final IStrategoTerm outlineTerm = common.invoke(interpreter, input, strategy);
        if (outlineTerm == null) {
            return null;
        }
        final IOutline outline = toOutline(outlineTerm, facet.expandTo, contributor.location());
        return outline;
    } catch (MetaborgException e) {
        throw new MetaborgException("Creating outline failed", e);
    }
}
Also used : IContext(org.metaborg.core.context.IContext) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) IOutline(org.metaborg.core.outline.IOutline) MetaborgException(org.metaborg.core.MetaborgException) HybridInterpreter(org.strategoxt.HybridInterpreter) FileObject(org.apache.commons.vfs2.FileObject) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 25 with ILanguageComponent

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

the class OutlineService method outline.

@Override
public IOutline outline(ISpoofaxParseUnit result) throws MetaborgException {
    if (!result.valid()) {
        return null;
    }
    final FileObject source = result.source();
    final IProject project = projectService.get(source);
    final ILanguageImpl langImpl = result.input().langImpl();
    @Nullable IContext context;
    if (project == null) {
        context = null;
    } else {
        try {
            context = contextService.get(source, project, langImpl);
        } catch (ContextException | MetaborgRuntimeException e) {
            // Failed to get a context, ignore and use the source file to get a stratego runtime later.
            context = null;
        }
    }
    final FacetContribution<OutlineFacet> facetContrib = facet(langImpl);
    final OutlineFacet facet = facetContrib.facet;
    final ILanguageComponent contributor = facetContrib.contributor;
    final String strategy = facet.strategyName;
    try {
        final HybridInterpreter interpreter;
        if (context == null) {
            interpreter = strategoRuntimeService.runtime(contributor, source, true);
        } else {
            interpreter = strategoRuntimeService.runtime(contributor, context, true);
        }
        final IStrategoTerm input = common.builderInputTerm(result.ast(), source, source);
        final IStrategoTerm outlineTerm = common.invoke(interpreter, input, strategy);
        if (outlineTerm == null) {
            return null;
        }
        final IOutline outline = toOutline(outlineTerm, facet.expandTo, contributor.location());
        return outline;
    } catch (MetaborgException e) {
        throw new MetaborgException("Creating outline failed", e);
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) IContext(org.metaborg.core.context.IContext) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) IOutline(org.metaborg.core.outline.IOutline) MetaborgException(org.metaborg.core.MetaborgException) HybridInterpreter(org.strategoxt.HybridInterpreter) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) IProject(org.metaborg.core.project.IProject) ContextException(org.metaborg.core.context.ContextException) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) Nullable(javax.annotation.Nullable)

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