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