use of org.spoofax.interpreter.terms.ITermFactory 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);
}
use of org.spoofax.interpreter.terms.ITermFactory in project metalib by softlang.
the class java_strategy_0_0 method invoke.
@Override
public IStrategoTerm invoke(Context context, IStrategoTerm current) {
context.getIOAgent().printError("Input for java-strategy: " + current);
ITermFactory factory = context.getFactory();
return factory.makeString("Regards from java-strategy");
}
use of org.spoofax.interpreter.terms.ITermFactory in project spoofax by metaborg.
the class StrategoCommon method resourceTerm.
@Override
public IStrategoString resourceTerm(FileObject resource, FileObject location) {
final ITermFactory termFactory = termFactoryService.getGeneric();
String resourceURI = ResourceUtils.relativeName(resource.getName(), location.getName(), false);
final IStrategoString resourceTerm = termFactory.makeString(resourceURI);
return resourceTerm;
}
use of org.spoofax.interpreter.terms.ITermFactory in project spoofax by metaborg.
the class StrategoCommon method builderInputTerm.
@Override
public IStrategoTerm builderInputTerm(IStrategoTerm ast, FileObject resource, FileObject location) {
final ITermFactory termFactory = termFactoryService.getGeneric();
// TODO: support selected node
final IStrategoTerm node = ast;
// TODO: support position
final IStrategoTerm position = termFactory.makeList();
final String locationURI = location.getName().getURI();
final IStrategoString locationTerm = termFactory.makeString(locationURI);
String resourceURI = ResourceUtils.relativeName(resource.getName(), location.getName(), false);
final IStrategoString resourceTerm = termFactory.makeString(resourceURI);
return termFactory.makeTuple(node, position, ast, resourceTerm, locationTerm);
}
use of org.spoofax.interpreter.terms.ITermFactory in project spoofax by metaborg.
the class StrategoRuntimeService method clone.
private HybridInterpreter clone(HybridInterpreter prototype, FileObject workingLocation, ILanguageComponent component, @Nullable IProject project, boolean typesmart) {
// TODO: this seems to copy operator registries, but they should be recreated to isolate interpreters?
final HybridInterpreter runtime = new HybridInterpreter(prototype);
final ResourceAgent agent = new ResourceAgent(resourceService);
agent.setAbsoluteWorkingDir(workingLocation);
agent.setAbsoluteDefinitionDir(component.location());
runtime.setIOAgent(agent);
runtime.getCompiledContext().getExceptionHandler().setEnabled(false);
// Add primitive libraries again, to make sure that our libraries override any default ones.
for (IOperatorRegistry library : strategoLibraries) {
runtime.getCompiledContext().addOperatorRegistry(library);
}
final ITermFactory termFactory = termFactoryService.get(component, project, typesmart);
runtime.getContext().setFactory(termFactory);
runtime.getCompiledContext().setFactory(termFactory);
runtime.init();
return runtime;
}
Aggregations