本文整理汇总了Java中org.spoofax.interpreter.core.Tools.isTermTuple方法的典型用法代码示例。如果您正苦于以下问题:Java Tools.isTermTuple方法的具体用法?Java Tools.isTermTuple怎么用?Java Tools.isTermTuple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spoofax.interpreter.core.Tools
的用法示例。
在下文中一共展示了Tools.isTermTuple方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTermConstructor
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private IStrategoTerm getTermConstructor(IContext env, IStrategoTerm t) throws InterpreterException {
if (Tools.isTermInt(t) || Tools.isTermReal(t)) {
return t;
} else if (Tools.isTermString(t)) {
return env.getFactory().makeString("\"" + ((IStrategoString)t).stringValue() + "\"");
} else if (Tools.isTermAppl(t)) {
IStrategoAppl a = (IStrategoAppl)t;
if (Tools.isCons(a, env) || Tools.isNil(a, env))
return env.getFactory().makeAppl(env.getStrategoSignature().getNil());
else
return env.getFactory().makeString(((IStrategoAppl)t).getConstructor().getName());
} else if (Tools.isTermList(t)) {
return env.getFactory().makeList();
} else if (Tools.isTermTuple(t)) {
return env.getFactory().makeString("");
}
throw new InterpreterException("Unknown term '" + t + "'");
}
示例2: collectRelabeledTerms
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private ArrayList<IStrategoTerm> collectRelabeledTerms(IStrategoTerm trm) {
ArrayList<IStrategoTerm> relabeledTerms = new ArrayList<IStrategoTerm>();
if(Tools.isTermAppl(trm) || Tools.isTermList(trm) || Tools.isTermTuple(trm)){
IStrategoTerm partnerOfTrm = TermMatchAttachment.getMatchedTerm(trm);
if(partnerOfTrm != null && !HelperFunctions.haveSameSignature(trm, partnerOfTrm) && Tools.isTermAppl(trm) && Tools.isTermAppl(partnerOfTrm)){
List<IStrategoTerm> tupleElems = new ArrayList<IStrategoTerm>();
tupleElems.add(trm);
tupleElems.add(((StrategoAppl)partnerOfTrm).getConstructor());
IStrategoTerm relabeling = termFactory.createTuple(null, null, null, tupleElems);
//relabeledTerms.add(relabeling);
relabeledTerms.add(trm);
System.err.println(trm);
System.err.println(partnerOfTrm);
}
}
for (int i = 0; i < trm.getSubtermCount(); i++) {
relabeledTerms.addAll(collectRelabeledTerms(trm.getSubterm(i)));
}
return relabeledTerms;
}
示例3: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public final boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) {
final IStrategoTerm location = tvars[0];
if(!Tools.isTermTuple(location) && location.getSubtermCount() != 4)
return false;
final String filename = Tools.asJavaString(location.getSubterm(0));
final int line = Tools.asJavaInt(location.getSubterm(1));
final int column = Tools.asJavaInt(location.getSubterm(2));
final int startOffset = Tools.asJavaInt(location.getSubterm(3));
final int endOffset = Tools.asJavaInt(location.getSubterm(4));
final ImploderAttachment attachment =
ImploderAttachment.createCompactPositionAttachment(filename, line, column, startOffset, endOffset);
env.current().putAttachment(attachment);
return true;
}
示例4: sourceFromTerm
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private void sourceFromTerm(IIndex index, IStrategoTerm term) throws IOException {
if(!Tools.isTermTuple(term)) {
throw new IOException("Cannot read index; partition term is not a tuple");
}
final IStrategoTerm source = term.getSubterm(0);
final IStrategoTerm entryList = term.getSubterm(1);
final Collection<IndexEntry> entries = Lists.newArrayListWithCapacity(entryList.getSubtermCount());
for(IStrategoTerm entryTerm : term.getSubterm(1)) {
entries.add(entryFactory.fromTerm(entryTerm));
}
index.addAll(source, entries);
}
示例5: haveSameSignature
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
/**
* True iff one of these conditions hold:
* 1. both are Appl with same constructor name and same number of subterms
* 2. both are lists
* 3. both are tuples
* @param t1
* @param t2
* @return
*/
public static boolean haveSameSignature(IStrategoTerm t1, IStrategoTerm t2){
if(t1 == null || t2 == null)
return false;
if(t1.getTermType() == StrategoTerm.APPL && t2.getTermType() == StrategoTerm.APPL){
boolean sameConstructorName = haveSameConstructorName(t1, t2);
return sameConstructorName && t1.getSubtermCount() == t2.getSubtermCount();
}
if (Tools.isTermList(t1) && Tools.isTermList(t2))
return true;
if (Tools.isTermTuple(t1) && Tools.isTermTuple(t2))
return true;
else
return false;
}
示例6: isSameTermType
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
public static boolean isSameTermType(IStrategoTerm t1, IStrategoTerm t2) {
return
(Tools.isTermAppl(t1) && Tools.isTermAppl(t2))
|| (Tools.isTermInt(t1) && Tools.isTermInt(t2))
|| (Tools.isTermList(t1) && Tools.isTermList(t2))
|| (Tools.isTermReal(t1) && Tools.isTermReal(t2))
|| (Tools.isTermString(t1) && Tools.isTermString(t2))
|| (Tools.isTermTuple(t1) && Tools.isTermTuple(t2));
}
示例7: isEmptyAST
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private boolean isEmptyAST(IStrategoTerm ast) {
return Tools.isTermTuple(ast) && ast.getSubtermCount() == 0;
}
示例8: haveTupleOrListType
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
public static boolean haveTupleOrListType(IStrategoTerm trm1, IStrategoTerm trm2) {
return (Tools.isTermList(trm1) && Tools.isTermList(trm2)) || (Tools.isTermTuple(trm1) && Tools.isTermTuple(trm2));
}