use of org.spoofax.terms.typesmart.types.TTuple in project spoofax by metaborg.
the class Typesmart method extractSortType.
private SortType extractSortType(IStrategoTerm sort) {
String kind = ((IStrategoAppl) sort).getName();
if (kind.equals("SortList") || kind.equals("SortListTl") || kind.equals("SortVar")) {
logger.error("Unsupported Stratego signature: " + sort);
return TAny.instance;
} else if (kind.equals("SortTuple")) {
IStrategoTerm[] kids = sort.getSubterm(0).getAllSubterms();
SortType[] sorts = new SortType[kids.length];
for (int i = 0; i < kids.length; i++) {
sorts[i] = extractSortType(kids[i]);
}
return new TTuple(sorts);
}
if (sort.getSubterm(0).getTermType() != IStrategoTerm.STRING) {
throw new IllegalArgumentException("Found type in unexpected format " + sort);
}
String sortName = ((IStrategoString) sort.getSubterm(0)).stringValue();
if (kind.equals("SortNoArgs") && sortName.equals(SortType.LEXICAL_SORT)) {
return TLexical.instance;
} else if (kind.equals("SortNoArgs") && sortName.equals(SortType.ANY_SORT)) {
return TAny.instance;
} else if (kind.equals("SortNoArgs")) {
return new TSort(sortName);
} else if (kind.equals("Sort") && sortName.equals("List")) {
SortType t = extractSortType(sort.getSubterm(1).getSubterm(0));
return t == null ? null : new TList(t);
} else if (kind.equals("Sort") && sortName.equals("Option")) {
SortType t = extractSortType(sort.getSubterm(1).getSubterm(0));
return t == null ? null : new TOption(t);
} else if (kind.equals("SortVar")) {
return null;
} else {
throw new IllegalArgumentException("Found type in unexpected format " + sort);
}
}
Aggregations