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);
}
}
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;
}
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;
}
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;
}
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 + "/-");
}
}
}
Aggregations