Search in sources :

Example 11 with IStrategoTerm

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

the class ResolverService method resolve.

@Override
public Resolution resolve(int offset, ISpoofaxAnalyzeUnit result) throws MetaborgException {
    if (!result.valid() || !result.hasAst()) {
        return null;
    }
    final FileObject source = result.source();
    final IContext context = result.context();
    final IProject project = context.project();
    final ILanguageImpl language = context.language();
    final FacetContribution<ResolverFacet> facetContrib = facet(language);
    final ResolverFacet facet = facetContrib.facet;
    final String strategy = facet.strategyName;
    try {
        final ITermFactory termFactory = termFactoryService.get(facetContrib.contributor, project, true);
        final HybridInterpreter interpreter = strategoRuntimeService.runtime(facetContrib.contributor, context, true);
        final Iterable<IStrategoTerm> inRegion = tracingService.fragments(result, new SourceRegion(offset));
        final TermWithRegion tuple;
        try (IClosableLock lock = context.read()) {
            tuple = common.outputs(termFactory, interpreter, source, source, result.ast(), inRegion, strategy);
        }
        return resolve(tuple);
    } catch (MetaborgException e) {
        throw new MetaborgException("Reference resolution failed", e);
    }
}
Also used : IContext(org.metaborg.core.context.IContext) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) MetaborgException(org.metaborg.core.MetaborgException) HybridInterpreter(org.strategoxt.HybridInterpreter) ISourceRegion(org.metaborg.core.source.ISourceRegion) SourceRegion(org.metaborg.core.source.SourceRegion) IProject(org.metaborg.core.project.IProject) TermWithRegion(org.metaborg.spoofax.core.tracing.TracingCommon.TermWithRegion) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) FileObject(org.apache.commons.vfs2.FileObject) IClosableLock(org.metaborg.util.concurrent.IClosableLock) ITermFactory(org.spoofax.interpreter.terms.ITermFactory)

Example 12 with IStrategoTerm

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

the class JSGLR1FileParseTableProvider method parseTable.

@Override
public ParseTable parseTable() throws IOException {
    if (parseTable != null) {
        return parseTable;
    }
    resource.refresh();
    if (!resource.exists()) {
        throw new IOException("Could not load parse table from " + resource + ", file does not exist");
    }
    try (final InputStream stream = resource.getContent().getInputStream()) {
        final TermReader termReader = new TermReader(termFactory);
        IStrategoTerm parseTableTerm = termReader.parseFromStream(stream);
        FileObject persistedTable = resource.getParent().resolveFile("table.bin");
        if (persistedTable.exists()) {
            parseTable = new ParseTable(parseTableTerm, termFactory, persistedTable);
        } else {
            parseTable = new ParseTable(parseTableTerm, termFactory);
        }
    } catch (Exception e) {
        throw new IOException("Could not load parse table from " + resource, e);
    }
    return parseTable;
}
Also used : ParseTable(org.spoofax.jsglr.client.ParseTable) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) InputStream(java.io.InputStream) IOException(java.io.IOException) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) TermReader(org.spoofax.terms.io.binary.TermReader)

Example 13 with IStrategoTerm

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

the class JSGLR1IncrementalParseTableProvider method parseTable.

@Override
public ParseTable parseTable() throws IOException {
    if (parseTable != null) {
        return parseTable;
    }
    resource.refresh();
    if (!resource.exists()) {
        throw new IOException("Could not load parse table from " + resource + ", file does not exist");
    }
    try (final InputStream stream = resource.getContent().getInputStream()) {
        final TermReader termReader = new TermReader(termFactory);
        final IStrategoTerm parseTableTerm = termReader.parseFromStream(stream);
        FileObject persistedTable = resource.getParent().resolveFile("table.bin");
        if (persistedTable.exists()) {
            if (referenceTable != null) {
                parseTable = new ParseTable(parseTableTerm, termFactory, persistedTable, referenceTable);
            } else {
                parseTable = new ParseTable(parseTableTerm, termFactory, persistedTable);
            }
        } else {
            parseTable = new ParseTable(parseTableTerm, termFactory);
        }
    } catch (Exception e) {
        throw new IOException("Could not load parse table from " + resource, e);
    }
    return parseTable;
}
Also used : ParseTable(org.spoofax.jsglr.client.ParseTable) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) InputStream(java.io.InputStream) IOException(java.io.IOException) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) TermReader(org.spoofax.terms.io.binary.TermReader)

Example 14 with IStrategoTerm

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

the class JSGLR2FileParseTableProvider method parseTable.

@Override
public IParseTable parseTable() throws IOException {
    if (parseTable != null) {
        return parseTable;
    }
    resource.refresh();
    if (!resource.exists()) {
        throw new IOException("Could not load parse table from " + resource + ", file does not exist");
    }
    try (final InputStream stream = resource.getContent().getInputStream()) {
        final TermReader termReader = new TermReader(termFactory);
        IStrategoTerm parseTableTerm = termReader.parseFromStream(stream);
        FileObject persistedTable = resource.getParent().resolveFile("table.bin");
        if (!persistedTable.exists()) {
            parseTable = new ParseTableReader(new CharacterClassFactory(true, true), new ActionsFactory(true), new StateFactory()).read(parseTableTerm);
        } else {
            parseTable = new ParseTableReader(new CharacterClassFactory(true, true), new ActionsFactory(true), new StateFactory()).read(parseTableTerm, persistedTable);
        }
    } catch (Exception e) {
        throw new IOException("Could not load parse table from " + resource, e);
    }
    return parseTable;
}
Also used : ParseTableReader(org.spoofax.jsglr2.parsetable.ParseTableReader) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) StateFactory(org.spoofax.jsglr2.states.StateFactory) CharacterClassFactory(org.metaborg.characterclasses.CharacterClassFactory) InputStream(java.io.InputStream) IOException(java.io.IOException) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) TermReader(org.spoofax.terms.io.binary.TermReader) ActionsFactory(org.spoofax.jsglr2.actions.ActionsFactory)

Example 15 with IStrategoTerm

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

the class Typesmart method extractImports.

private void extractImports(IStrategoTerm importDecls, List<String> imports) {
    for (IStrategoTerm importDecl : importDecls) {
        String importName = ((IStrategoString) importDecl.getSubterm(0)).stringValue();
        String importDeclName = ((IStrategoAppl) importDecl).getName();
        if (importDeclName.equals("Import")) {
            imports.add(importName);
        } else {
            // wildcard import
            imports.add(importName + "/-");
        }
    }
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) IStrategoString(org.spoofax.interpreter.terms.IStrategoString)

Aggregations

IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)82 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)31 FileObject (org.apache.commons.vfs2.FileObject)27 IStrategoAppl (org.spoofax.interpreter.terms.IStrategoAppl)25 MetaborgException (org.metaborg.core.MetaborgException)19 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)17 HybridInterpreter (org.strategoxt.HybridInterpreter)17 IStrategoList (org.spoofax.interpreter.terms.IStrategoList)16 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)15 Nullable (javax.annotation.Nullable)14 ISourceRegion (org.metaborg.core.source.ISourceRegion)12 ICompletion (org.metaborg.core.completion.ICompletion)11 IStrategoTuple (org.spoofax.interpreter.terms.IStrategoTuple)10 IOException (java.io.IOException)9 IProject (org.metaborg.core.project.IProject)9 IMessage (org.metaborg.core.messages.IMessage)8 IToken (org.spoofax.jsglr.client.imploder.IToken)8 IContext (org.metaborg.core.context.IContext)7 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)7 ListImploderAttachment (org.spoofax.jsglr.client.imploder.ListImploderAttachment)7