Search in sources :

Example 21 with IStrategoAppl

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

the class AnalysisFacetFromESV method type.

@Nullable
public static String type(IStrategoAppl esv) {
    final IStrategoAppl strategy = ESVReader.findTerm(esv, "SemanticObserver");
    if (strategy == null) {
        return null;
    }
    final IStrategoTerm annotations = strategy.getSubterm(1);
    boolean multifile = false;
    boolean constraint = false;
    for (IStrategoTerm annotation : annotations) {
        multifile |= Tools.hasConstructor((IStrategoAppl) annotation, "MultiFile", 0);
        constraint |= Tools.hasConstructor((IStrategoAppl) annotation, "Constraint", 0);
    }
    if (constraint) {
        return multifile ? ConstraintMultiFileAnalyzer.name : ConstraintSingleFileAnalyzer.name;
    } else if (multifile) {
        return TaskEngineAnalyzer.name;
    }
    return StrategoAnalyzer.name;
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) Nullable(javax.annotation.Nullable)

Example 22 with IStrategoAppl

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

the class AnalysisFacetFromESV method strategyName.

@Nullable
private static String strategyName(IStrategoAppl esv) {
    final IStrategoAppl strategy = ESVReader.findTerm(esv, "SemanticObserver");
    if (strategy == null) {
        return null;
    }
    final String observerFunction = ESVReader.termContents(termAt(strategy, 0));
    return observerFunction;
}
Also used : IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) Nullable(javax.annotation.Nullable)

Example 23 with IStrategoAppl

use of org.spoofax.interpreter.terms.IStrategoAppl in project nabl by metaborg.

the class AnalysisPrimitive method call.

@Override
public Optional<? extends IStrategoTerm> call(IScopeGraphContext<?> context, IStrategoTerm sterm, List<IStrategoTerm> sterms, ITermFactory factory) throws InterpreterException {
    if (sterms.size() < 1) {
        throw new IllegalArgumentException("Expected as first term argument: analysis");
    }
    final IStrategoTerm analysisTerm = sterms.get(0);
    final IScopeGraphUnit analysis;
    final Optional<IScopeGraphUnit> maybeAnalysis = StrategoBlob.match(analysisTerm, IScopeGraphUnit.class);
    if (maybeAnalysis.isPresent()) {
        analysis = maybeAnalysis.get();
    } else if (Tools.isTermAppl(analysisTerm) && Tools.hasConstructor((IStrategoAppl) analysisTerm, "AnalysisToken", 0)) {
        // TODO Remove legacy case after bootstrapping
        analysis = StrategoTermIndices.get(analysisTerm).map(idx -> context.unit(idx.getResource())).orElseThrow(() -> new IllegalArgumentException("Not a valid analysis term."));
    } else {
        throw new IllegalArgumentException("Not a valid analysis term.");
    }
    return call(analysis, sterm, sterms, factory);
}
Also used : NotImplementedException(org.spoofax.terms.util.NotImplementedException) ITerm(mb.nabl2.terms.ITerm) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) StrategoTerms(mb.nabl2.stratego.StrategoTerms) Tools(org.spoofax.interpreter.core.Tools) ITermFactory(org.spoofax.interpreter.terms.ITermFactory) IScopeGraphContext(mb.nabl2.spoofax.analysis.IScopeGraphContext) Collectors(java.util.stream.Collectors) List(java.util.List) StrategoTermIndices(mb.nabl2.stratego.StrategoTermIndices) InterpreterException(org.spoofax.interpreter.core.InterpreterException) ConstraintTerms(mb.nabl2.stratego.ConstraintTerms) StrategoBlob(mb.nabl2.stratego.StrategoBlob) Optional(java.util.Optional) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) IScopeGraphUnit(mb.nabl2.spoofax.analysis.IScopeGraphUnit) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) IScopeGraphUnit(mb.nabl2.spoofax.analysis.IScopeGraphUnit)

Example 24 with IStrategoAppl

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

the class LanguageComponentFactory method request.

private IComponentCreationConfigRequest request(FileObject root) throws MetaborgException {
    final Collection<String> errors = Lists.newLinkedList();
    final Collection<Throwable> exceptions = Lists.newLinkedList();
    final ConfigRequest<ILanguageComponentConfig> configRequest = componentConfigService.get(root);
    if (!configRequest.valid()) {
        for (IMessage message : configRequest.errors()) {
            errors.add(message.message());
            final Throwable exception = message.exception();
            if (exception != null) {
                exceptions.add(exception);
            }
        }
    }
    final ILanguageComponentConfig config = configRequest.config();
    if (config == null) {
        final String message = logger.format("Cannot retrieve language component configuration at {}", root);
        errors.add(message);
        return new ComponentFactoryRequest(root, errors, exceptions);
    }
    final IStrategoAppl esvTerm;
    try {
        final FileObject esvFile = root.resolveFile("target/metaborg/editor.esv.af");
        if (!esvFile.exists()) {
            esvTerm = null;
        } else {
            esvTerm = esvTerm(root, esvFile);
        }
    } catch (ParseError | IOException | MetaborgException e) {
        exceptions.add(e);
        return new ComponentFactoryRequest(root, errors, exceptions);
    }
    SyntaxFacet syntaxFacet = null;
    StrategoRuntimeFacet strategoRuntimeFacet = null;
    if (esvTerm != null) {
        try {
            syntaxFacet = SyntaxFacetFromESV.create(esvTerm, root);
            if (syntaxFacet != null) {
                Iterables.addAll(errors, syntaxFacet.available());
            }
        } catch (FileSystemException e) {
            exceptions.add(e);
        }
        try {
            strategoRuntimeFacet = StrategoRuntimeFacetFromESV.create(esvTerm, root);
            if (strategoRuntimeFacet != null) {
                Iterables.addAll(errors, strategoRuntimeFacet.available(resourceService));
            }
        } catch (IOException e) {
            exceptions.add(e);
        }
    }
    final ComponentFactoryRequest request;
    if (errors.isEmpty() && exceptions.isEmpty()) {
        request = new ComponentFactoryRequest(root, config, esvTerm, syntaxFacet, strategoRuntimeFacet);
    } else {
        request = new ComponentFactoryRequest(root, errors, exceptions);
    }
    return request;
}
Also used : SyntaxFacet(org.metaborg.spoofax.core.syntax.SyntaxFacet) IMessage(org.metaborg.core.messages.IMessage) MetaborgException(org.metaborg.core.MetaborgException) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) IOException(java.io.IOException) FileSystemException(org.apache.commons.vfs2.FileSystemException) ParseError(org.spoofax.terms.ParseError) FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponentConfig(org.metaborg.core.config.ILanguageComponentConfig) StrategoRuntimeFacet(org.metaborg.spoofax.core.stratego.StrategoRuntimeFacet)

Example 25 with IStrategoAppl

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

the class ShellFacetFromESV method create.

@Nullable
public static ShellFacet create(IStrategoAppl esv) {
    IStrategoAppl shellTerm = ESVReader.findTerm(esv, "Shell");
    if (shellTerm == null) {
        return null;
    }
    String commandPrefix = commandPrefix(shellTerm);
    String evaluationMethod = evaluationMethod(shellTerm);
    String shellStartSymbol = shellStartSymbol(shellTerm);
    return new ShellFacet(commandPrefix, evaluationMethod, shellStartSymbol);
}
Also used : IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) Nullable(javax.annotation.Nullable)

Aggregations

IStrategoAppl (org.spoofax.interpreter.terms.IStrategoAppl)42 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)26 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)21 ICompletion (org.metaborg.core.completion.ICompletion)13 Nullable (javax.annotation.Nullable)12 IStrategoList (org.spoofax.interpreter.terms.IStrategoList)9 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)8 ListImploderAttachment (org.spoofax.jsglr.client.imploder.ListImploderAttachment)8 Completion (org.metaborg.core.completion.Completion)7 ITokens (org.spoofax.jsglr.client.imploder.ITokens)7 ImploderAttachment (org.spoofax.jsglr.client.imploder.ImploderAttachment)7 StrategoTerm (org.spoofax.terms.StrategoTerm)7 HybridInterpreter (org.strategoxt.HybridInterpreter)7 FileObject (org.apache.commons.vfs2.FileObject)6 MetaborgException (org.metaborg.core.MetaborgException)6 IStrategoTuple (org.spoofax.interpreter.terms.IStrategoTuple)6 CompletionKind (org.metaborg.core.completion.CompletionKind)5 StrategoAppl (org.spoofax.terms.StrategoAppl)5 IToken (org.spoofax.jsglr.client.imploder.IToken)4 ISourceRegion (org.metaborg.core.source.ISourceRegion)3