use of org.strategoxt.lang.StrategoException in project spoofax by metaborg.
the class ParseFileStrategy method invoke.
@Override
public IStrategoTerm invoke(Context context, IStrategoTerm current) {
if (!Tools.isTermString(current))
return null;
try {
final String path = Tools.asJavaString(current);
final FileObject resource = resourceService.resolve(path);
if (resource.getType() != FileType.FILE) {
return null;
}
final IdentifiedResource identifiedResource = languageIdentifierService.identifyToResource(resource);
if (identifiedResource == null) {
return null;
}
final String text = sourceTextService.text(resource);
final ISpoofaxInputUnit input = unitService.inputUnit(resource, text, identifiedResource.language, identifiedResource.dialect);
final ISpoofaxParseUnit result = syntaxService.parse(input);
return result.ast();
} catch (ParseException | IOException e) {
throw new StrategoException("Parsing failed unexpectedly", e);
}
}
Aggregations