当前位置: 首页>>代码示例>>Java>>正文


Java Tools.isTermAppl方法代码示例

本文整理汇总了Java中org.spoofax.interpreter.core.Tools.isTermAppl方法的典型用法代码示例。如果您正苦于以下问题:Java Tools.isTermAppl方法的具体用法?Java Tools.isTermAppl怎么用?Java Tools.isTermAppl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spoofax.interpreter.core.Tools的用法示例。


在下文中一共展示了Tools.isTermAppl方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: eval

import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public IConstruct eval(final IContext env) throws InterpreterException {

	if (DebugUtil.isDebugging()) {
		debug("CallDynamic.eval() - ", env.current());
	}

	if (Tools.isTermAppl(sref) && Tools.isVar((IStrategoAppl) sref, env)) {
		IStrategoTerm actualSRef = env.lookupVar(Tools.javaStringAt(
				(IStrategoAppl) sref, 0));
		if (Tools.isTermString(actualSRef)) {
			String sname = Tools.asJavaString(actualSRef);
			Strategy callt = new CallT(sname, svars, tvars);
			callt.getHook().push(this.getHook().pop());
			return callt.eval(env);
		}
	}
	throw new InterpreterException(
			"Invocation target is invalid (cannot be evaluated): " + sref);

}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:22,代码来源:CallDynamic.java

示例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 + "'");
    }
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:21,代码来源:Match.java

示例3: call

import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
        throws InterpreterException {
    
    IStrategoTerm input = tvars[0];
    
    if(!Tools.isTermAppl(input) && !isTermTuple(input))
        return false;
    
    Strategy c = svars[0];
    int arity = input.getSubtermCount();
    IStrategoTerm[] result = new IStrategoTerm[arity];
    IStrategoTerm[] applArgs = input.getAllSubterms();
    for(int i = 0; i < arity; i++) {
        env.setCurrent(applArgs[i]);
        if(!c.evaluate(env))
            return false;
        result[i] = env.current();
    }
    env.setCurrent(env.getFactory().makeList(result));
    return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:23,代码来源:SSL_get_appl_arguments_map.java

示例4: 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;
}
 
开发者ID:metaborg,项目名称:jsglr,代码行数:21,代码来源:TreeEditDistance.java

示例5: ruleListTerm

import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private static IStrategoList ruleListTerm(IStrategoTerm topSpecTerm) {
	IStrategoList sections = Tools.listAt(topSpecTerm, 1);
	for (IStrategoTerm section : sections) {
		if (Tools.isTermAppl(section) && Tools.hasConstructor((IStrategoAppl) section, "Rules", 1)) {
			return Tools.listAt(section, 0);
		}
	}
	throw new InterpreterException("Malformed specification: could not find Rules section");
}
 
开发者ID:metaborg,项目名称:dynsem,代码行数:10,代码来源:RuleRegistry.java

示例6: boolFromTerm

import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
public static boolean boolFromTerm(IStrategoTerm term) {
	if (Tools.isTermAppl(term)) {
		IStrategoAppl tAppl = (IStrategoAppl) term;
		if (Tools.hasConstructor(tAppl, "___DS_False___", 0)) {
			return false;
		} else if (Tools.hasConstructor(tAppl, "___DS_True___", 0)) {
			return true;
		}
	}
	throw new MalformedASTException("Malformed boolean: " + term);
}
 
开发者ID:metaborg,项目名称:dynsem,代码行数:12,代码来源:TermUtils.java

示例7: match

import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
public static Optional<TermIndex> match(IStrategoTerm term) {
    if (!(Tools.isTermAppl(term) && Tools.hasConstructor((IStrategoAppl) term, OP, ARITY))) {
        return Optional.empty();
    }
    IStrategoTerm resourceTerm = term.getSubterm(0);
    IStrategoTerm idTerm = term.getSubterm(1);
    if (!(Tools.isTermString(resourceTerm) && Tools.isTermInt(idTerm))) {
        return Optional.empty();
    }
    return Optional.of(ImmutableTermIndex.of(Tools.asJavaString(resourceTerm), Tools.asJavaInt(idTerm)));
}
 
开发者ID:metaborg,项目名称:nabl,代码行数:12,代码来源:StrategoTermIndices.java

示例8: movedSubterms

import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private ArrayList<IStrategoTerm> movedSubterms(IStrategoTerm trm, IStrategoTerm partnerOfTrm) {
	List<IStrategoTerm> subterms = Arrays.asList(trm.getAllSubterms());
	List<IStrategoTerm> subtermsOfPartner = Arrays.asList(partnerOfTrm.getAllSubterms());
	if(Tools.isTermAppl(trm) && Tools.isTermAppl(partnerOfTrm) && HelperFunctions.haveSameSignature(trm, partnerOfTrm))
		return movedApplElements(subterms, subtermsOfPartner);
	else 
		return movedListElements(subterms, subtermsOfPartner);
}
 
开发者ID:metaborg,项目名称:jsglr,代码行数:9,代码来源:TreeEditDistance.java

示例9: 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));
}
 
开发者ID:metaborg,项目名称:jsglr,代码行数:10,代码来源:HelperFunctions.java

示例10: isURI

import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
private boolean isURI(IStrategoTerm term) {
	if(!Tools.isTermAppl(term))
		return false;
	final IStrategoAppl appl = (IStrategoAppl) term;
	return appl.getConstructor().equals(uriConstructor);
}
 
开发者ID:metaborg,项目名称:mb-rep,代码行数:7,代码来源:IndexParentKeyFactory.java

示例11: call

import org.spoofax.interpreter.core.Tools; //导入方法依赖的package包/类
@Override public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
    final SSLLibrary op = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
    final IOAgent agent = op.getIOAgent();

    if(isSameFile(tvars, agent)) {
        return true;
    }

    try {
        final InputStream in;
        final boolean closeIn;
        if(Tools.isTermString(tvars[0])) {
            in = agent.openInputStream(Tools.javaString(tvars[0]));
            closeIn = true;
        } else if(Tools.isTermAppl(tvars[0]) && Tools.hasConstructor((IStrategoAppl) tvars[0], "stdin")) {
            in = agent.internalGetInputStream(IOAgent.CONST_STDIN);
            closeIn = false;
        } else {
            return false;
        }

        final OutputStream out;
        final boolean closeOut;
        if(Tools.isTermString(tvars[1])) {
            out = agent.openFileOutputStream(Tools.javaString(tvars[1]));
            closeOut = true;
        } else if(Tools.isTermAppl(tvars[1]) && Tools.hasConstructor((IStrategoAppl) tvars[1], "stdout")) {
            out = agent.internalGetOutputStream(IOAgent.CONST_STDOUT);
            closeOut = false;
        } else if(Tools.isTermAppl(tvars[1]) && Tools.hasConstructor((IStrategoAppl) tvars[1], "stderr")) {
            out = agent.internalGetOutputStream(IOAgent.CONST_STDERR);
            closeOut = false;
        } else {
            return false;
        }

        try {
            if(in instanceof FileInputStream && out instanceof FileOutputStream) {
                final FileChannel inChannel = ((FileInputStream) in).getChannel();
                final FileChannel outChannel = ((FileOutputStream) out).getChannel();
                inChannel.transferTo(0, inChannel.size(), outChannel);
            } else {
                IOUtils.copy(in, out);
            }
        } finally {
            if(closeOut) {
                out.close();
            }
            if(closeIn) {
                in.close();
            }
        }
    } catch(IOException e) {
        agent.printError(
            "SSL_copy: Could not copy file (" + e.getMessage() + "-" + "attempted to copy to " + tvars[1]);
        return false;
    }

    return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:61,代码来源:SSL_copy.java


注:本文中的org.spoofax.interpreter.core.Tools.isTermAppl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。