本文整理汇总了Java中org.spoofax.interpreter.core.Tools.isTermList方法的典型用法代码示例。如果您正苦于以下问题:Java Tools.isTermList方法的具体用法?Java Tools.isTermList怎么用?Java Tools.isTermList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spoofax.interpreter.core.Tools
的用法示例。
在下文中一共展示了Tools.isTermList方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doBuildExplode
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private IStrategoTerm doBuildExplode(ITermFactory factory, IStrategoTerm actualCtor, IStrategoTerm actualArgs) throws InterpreterException {
if (!(Tools.isTermList(actualArgs))) {
throw new InterpreterException("Not a list: " + actualArgs);
}
String n = ((IStrategoString)actualCtor).stringValue();
IStrategoTerm[] realArgs = ((IStrategoList)actualArgs).getAllSubterms();
if (n.equals(""))
return factory.makeTuple(realArgs);
boolean quoted = false;
if (n.length() > 1 && n.charAt(0) == '"') {
n = n.substring(1, n.length() - 1);
quoted = true;
}
if(quoted && realArgs.length == 0) {
return factory.makeString(n);
}
IStrategoConstructor afun = factory.makeConstructor(n, realArgs.length);
return factory.makeAppl(afun, realArgs);
}
示例2: 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 + "'");
}
示例3: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermList(tvars[1]))
return false;
CallT s = (CallT) svars[0];
Strategy[] sv = new Strategy[0];
IStrategoTerm[] tv = { tvars[0] };
env.setCurrent(tv[0]);
for (IStrategoList list = (IStrategoList) tvars[1]; !list.isEmpty(); list = list.tail()) {
env.setCurrent(list.head());
if(!s.evaluateWithArgs(env, sv, tv))
return false;
tv[0] = env.current();
}
return true;
}
示例4: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermList(tvars[0]))
return false;
CallT s = (CallT) svars[0];
Strategy[] sv = new Strategy[0];
IStrategoTerm[] tv = new IStrategoTerm[0];
IStrategoTerm saved = env.current();
for (IStrategoList list = (IStrategoList) tvars[0]; !list.isEmpty(); list = list.tail()) {
env.setCurrent(list.head());
if(!s.evaluateWithArgs(env, sv, tv))
return false;
}
env.setCurrent(saved);
return true;
}
示例5: 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;
}
示例6: indexFromTerm
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
/**
* Populates an index from a term representation of an index created with
* {@link #indexToTerm(IIndex, ITermFactory, boolean)}.
*
* @param index
* The index to populate.
* @param term
* A term representation of an index.
* @throws Exception
*/
public IIndex indexFromTerm(IIndex index, IStrategoTerm term) throws IOException {
if(!Tools.isTermList(term)) {
throw new IOException("Cannot read index; root term is not a list");
}
for(IStrategoTerm sourceTerm : term) {
sourceFromTerm(index, sourceTerm);
}
return index;
}
示例7: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
IStrategoTerm t = targs[0];
if(!Tools.isTermList(t))
return false;
String result = call((IStrategoList) t);
env.setCurrent(env.getFactory().makeString(result));
return true;
}
示例8: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if(!Tools.isTermList(tvars[0]))
return false;
IStrategoList l = (IStrategoList)tvars[0];
env.setCurrent(env.getFactory().makeInt(l.getSubtermCount()));
return true;
}
示例9: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!Tools.isTermString(targs[0])) {
return false;
}
if(!(Tools.isTermList(targs[1]))) {
return false;
}
final SSLLibrary op = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
final IOAgent agent = op.getIOAgent();
final String path = Tools.javaString(targs[0]);
final int permissions = permissions_from_term((IStrategoList) targs[1]);
if((permissions & R_OK) != 0) {
if(!agent.readable(path)) {
return false;
}
} else if((permissions & W_OK) != 0) {
if(!agent.writable(path)) {
return false;
}
} else if((permissions & X_OK) != 0) {
// FIXME: We cannot know this in Java < 1.6
return false;
} else if(permissions == F_OK) {
if(!agent.exists(path)) {
return false;
}
}
env.setCurrent(targs[0]);
return true;
}
示例10: call
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {
if(!Tools.isTermList(targs[0]))
return false;
String result = call((IStrategoList) targs[0]);
if (result == null)
return false;
env.setCurrent(env.getFactory().makeString(result));
return true;
}
示例11: 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;
}
示例12: 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));
}
示例13: buildExplode
import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private IStrategoTerm buildExplode(IContext env, IStrategoAppl t) throws InterpreterException {
if (DebugUtil.isDebugging()) {
debug("buildExplode() : ", t);
}
ITermFactory factory = env.getFactory();
IStrategoAppl ctor = Tools.applAt(t, 0);
IStrategoAppl args = Tools.applAt(t, 1);
if (DebugUtil.isDebugging()) {
debug(" ctor : ", ctor);
}
if (DebugUtil.isDebugging()) {
debug(" args : ", args);
}
IStrategoTerm actualCtor = buildTerm(env, ctor);
IStrategoTerm actualArgs = buildTerm(env, args);
if(actualCtor == null || actualArgs == null)
return null;
if (DebugUtil.isDebugging()) {
debug(" actualCtor : ", actualCtor);
}
if (DebugUtil.isDebugging()) {
debug(" actualArgs : ", actualArgs);
}
if (Tools.isTermInt(actualCtor) || Tools.isTermReal(actualCtor)) {
return actualCtor;
}
else if (Tools.isTermString(actualCtor)) {
return doBuildExplode(factory, actualCtor, actualArgs);
}
else if (Tools.isTermList(actualCtor)) {
return actualArgs;
}
// According to STR-626 non-string constructor term implosion should fail not crash
return null;
}
示例14: 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));
}