本文整理汇总了Java中org.spoofax.interpreter.core.Tools类的典型用法代码示例。如果您正苦于以下问题:Java Tools类的具体用法?Java Tools怎么用?Java Tools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Tools类属于org.spoofax.interpreter.core包,在下文中一共展示了Tools类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Override
public IStrategoTerm invoke(Context context, IStrategoTerm usedWordTerm, IStrategoTerm schemeNameTerm) {
if (usedWordTerm instanceof IStrategoString) {
if (schemeNameTerm instanceof IStrategoString) {
final String schemeName = Tools.asJavaString(schemeNameTerm);
final String usedWord = Tools.asJavaString(usedWordTerm);
final String regex = schemeName + "(_.+|[0-9]+'*|'+[0-9]*)";
if (usedWord.matches(regex)) {
return usedWordTerm;
}
}
}
return null;
}
示例2: invoke
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Override
public IStrategoTerm invoke(Context context, IStrategoTerm current) {
if (!(current instanceof IStrategoString)) {
return null;
}
final IContext mbContext = (IContext) context.contextObject();
final Injector injector = mbContext.injector();
final IResourceService resources = injector.getInstance(IResourceService.class);
final FileObject fileObj = resources.resolve(Tools.asJavaString(current));
try {
fileObj.setExecutable(true, false);
} catch (FileSystemException e1) {
return null;
}
return current;
}
示例3: create
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
public static LiteralMatchPattern create(IStrategoAppl t, FrameDescriptor fd) {
SourceSection source = SourceUtils.dynsemSourceSectionFromATerm(t);
if (Tools.hasConstructor(t, "True", 0)) {
return TrueLiteralTermMatchPatternNodeGen.create(source);
}
if (Tools.hasConstructor(t, "False", 0)) {
return FalseLiteralTermMatchPatternNodeGen.create(source);
}
if (Tools.hasConstructor(t, "Int", 1)) {
return IntLiteralTermMatchPatternNodeGen.create(Integer.parseInt(Tools.stringAt(t, 0).stringValue()),
source);
}
if (Tools.hasConstructor(t, "String", 1)) {
return StringLiteralTermMatchPatternNodeGen.create(Tools.stringAt(t, 0).stringValue(), source);
}
throw new NotImplementedException("Unsupported literal: " + t);
}
示例4: create
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
public static Premise create(IStrategoAppl t, FrameDescriptor fd) {
CompilerAsserts.neverPartOfCompilation();
if (Tools.hasConstructor(t, "CaseMatch", 2)) {
return CaseMatchPremise.create(t, fd);
}
IStrategoAppl premT = Tools.applAt(t, 0);
if (Tools.hasConstructor(premT, "Relation", 3)) {
return RelationPremise.create(premT, fd);
}
if (Tools.hasConstructor(premT, "RecRelation", 3)) {
return RecursiveRelationPremise.create(premT, fd);
}
if (Tools.hasConstructor(premT, "Match", 2)) {
return MatchPremise.create(premT, fd);
}
if (Tools.hasConstructor(premT, "TermEq", 2)) {
return TermEqPremise.create(premT, fd);
}
if (Tools.hasConstructor(premT, "Fails", 1)) {
return FailsPremise.create(premT, fd);
}
throw new NotImplementedException("Unsupported premise: " + t);
}
示例5: call
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Override protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars,
ITermFactory factory, IContext context) {
if(!(current instanceof IStrategoString)) {
return null;
}
String path = Tools.asJavaString(current);
IStrategoTerm basePathTerm = tvars[0];
if(!(basePathTerm instanceof IStrategoString)) {
return null;
}
String basePath = Tools.asJavaString(basePathTerm);
final FileObject base = resourceService.resolve(basePath);
final FileObject abs = resourceService.resolve(base, path);
return factory.makeString(abs.getName().getURI());
}
示例6: call
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
throws InterpreterException {
if (!Tools.isTermString(tvars[0]))
return false;
try {
Class<?> c = Class.forName(Tools.asJavaString(tvars[0]));
JFFLibrary lib = JFFLibrary.instance(env);
env.setCurrent(lib.wrapObject(c));
} catch (ClassNotFoundException e) {
return false;
}
return true;
}
示例7: buildOp
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
private IStrategoTerm buildOp(IContext env, IStrategoAppl t, ITermFactory factory)
throws InterpreterException {
// FIXME memoize constructors
String ctr = Tools.javaStringAt(t, 0);
IStrategoList children = (IStrategoList) t.getSubterm(1);
if(ctr.length() == 0) {
return buildTuple(env, t);
} else if(children.getSubtermCount() == 0 && ctr.equals("Nil")) {
return buildNil(env);
} else if(children.getSubtermCount() == 2 && ctr.equals("Cons")) {
return buildCons(env, t, factory);
} else {
return buildOp(ctr, env, t, factory);
}
}
示例8: 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);
}
示例9: termContents
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Nullable
public static String termContents(IStrategoTerm t) {
if(t == null)
return null;
String result;
if(t.getTermType() == STRING) {
result = asJavaString(t);
} else if(t.getSubtermCount() == 1 && "Values".equals(tryGetName(t))) {
return concatTermStrings(Tools.listAt(t, 0));
} else if(t.getTermType() == APPL && t.getSubtermCount() == 1 && termAt(t, 0).getTermType() == STRING) {
result = asJavaString(termAt(t, 0));
} else if(t.getTermType() == APPL && t.getSubtermCount() == 1) {
return termContents(termAt(t, 0));
} else {
return null;
}
if(result.startsWith("\"") && result.endsWith("\"") && result.length() > 1)
result = result.substring(1, result.length() - 1).replace("\\\\", "\"");
return result;
}
示例10: matchAnyExplode
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
private Results matchAnyExplode(IContext env, IStrategoTerm t,
IStrategoAppl p) throws InterpreterException {
if(DebugUtil.isDebugging()) {
DebugUtil.debug(" pattern is Explode");
}
IStrategoAppl opPattern = Tools.applAt(p, 0);
IStrategoAppl argsPattern = Tools.applAt(p, 1);
IStrategoTerm op = getTermConstructor(env, t);
IStrategoTerm args = getTermArguments(env, t);
Results opResult = match(env, op, opPattern);
Results argsResult = match(env, args, argsPattern);
if (opResult == null || argsResult == null)
return null;
opResult.addAll(argsResult);
return opResult;
}
示例11: 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 + "'");
}
示例12: type
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
public static @Nullable String type(IStrategoAppl esv) {
final IStrategoAppl strategy = ESVReader.findTerm(esv, "SemanticObserver");
if(strategy == null) {
return null;
}
final IStrategoTerm annotations = strategy.getSubterm(1);
boolean multifile = false;
boolean constraint = false;
for(IStrategoTerm annotation : annotations) {
multifile |= Tools.hasConstructor((IStrategoAppl) annotation, "MultiFile", 0);
constraint |= Tools.hasConstructor((IStrategoAppl) annotation, "Constraint", 0);
}
if(constraint) {
return multifile ? ConstraintMultiFileAnalyzer.name : ConstraintSingleFileAnalyzer.name;
} else if(multifile) {
return TaskEngineAnalyzer.name;
}
return StrategoAnalyzer.name;
}
示例13: call
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
double a, b;
if(Tools.isTermReal(tvars[0])) {
a = ((IStrategoReal) tvars[0]).realValue();
} else if (Tools.isTermInt(tvars[0])) {
a = ((IStrategoInt) tvars[0]).intValue();
} else {
return false;
}
if(Tools.isTermReal(tvars[1])) {
b = ((IStrategoReal) tvars[1]).realValue();
} else if (Tools.isTermInt(tvars[1])) {
b = ((IStrategoInt) tvars[1]).intValue();
} else {
return false;
}
env.setCurrent(env.getFactory().makeReal(a + b));
return true;
}
示例14: 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;
}
示例15: call
import org.spoofax.interpreter.core.Tools; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] targs)
throws InterpreterException {
if(!Tools.isTermInt(targs[0]))
return false;
SSLLibrary or = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
OutputStream out = or.getIOAgent().internalGetOutputStream(Tools.asJavaInt(targs[0]));
BufferedOutputStream bout = new BufferedOutputStream(out);
if(out == null)
return false;
try {
SAFWriter.writeTermToSAFStream(targs[1], bout);
bout.close();
} catch(IOException e) {
throw new InterpreterException(e);
}
env.setCurrent(targs[0]);
return true;
}