• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java InterpreterException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



InterpreterException类属于org.spoofax.interpreter.core包,在下文中一共展示了InterpreterException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: matchAnyExplode

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的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;
}
 
开发者ID:metaborg,项目名称:jsglr,代码行数:23,代码来源:java2.java


示例2: call

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override public Optional<ITerm> call(IScopeGraphContext<?> context, ITerm term, List<ITerm> terms)
        throws InterpreterException {
    if (terms.size() != 1) {
        throw new InterpreterException("Need one term argument: analysis");
    }
    final ITermIndex analysis = TermIndex.get(terms.get(0))
            .orElseThrow(() -> new InterpreterException("Not an analysis term."));
    return TermIndex.get(term).flatMap(index -> {
        return context.unit(analysis.getResource()).solution().<ITerm> flatMap(s -> {
            List<ITerm> entries = Lists.newArrayList();
            for (Occurrence ref : s.getScopeGraph().getAllRefs()) {
                if (ref.getIndex().equals(index)) {
                    for (Occurrence decl : Paths.resolutionPathsToDecls(s.getNameResolution().resolve(ref))) {
                        entries.add(TB.newTuple(ref, decl.getName()));
                    }
                }
            }
            if (entries.isEmpty()) {
                return Optional.empty();
            }
            return Optional.of(TB.newList(entries));
        });
    });
}
 
开发者ID:metaborg,项目名称:nabl,代码行数:25,代码来源:SG_get_ast_resolution.java


示例3: closeRandomAccessFile

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override public boolean closeRandomAccessFile(int fd) throws InterpreterException {
    if(fd == CONST_STDOUT || fd == CONST_STDERR || fd == CONST_STDIN) {
        return true;
    }

    final ResourceHandle handle = openFiles.remove(fd);
    if(handle == null)
        return true; // already closed: be forgiving

    try {
        if(handle.writer != null)
            handle.writer.close();
        if(handle.outputStream != null)
            handle.outputStream.close();
        handle.resource.getContent().close();
    } catch(IOException e) {
        throw new RuntimeException("Could not close resource", e);
    }
    return true;
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:21,代码来源:ResourceAgent.java


示例4: call

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override public Optional<ITerm> call(IScopeGraphContext<?> context, ITerm term, List<ITerm> terms)
        throws InterpreterException {
    if (terms.size() != 1) {
        throw new InterpreterException("Need one term argument: analysis");
    }
    final ITermIndex analysis = TermIndex.get(terms.get(0))
            .orElseThrow(() -> new InterpreterException("Not an analysis term."));
    return TermIndex.get(term).flatMap(index -> {
        return context.unit(analysis.getResource()).solution().flatMap(s -> {
            if(s.getMessages().getErrors().isEmpty()) {
                return Optional.empty();
            } else {
                return Optional.of(term);
            }
        });
    });
}
 
开发者ID:metaborg,项目名称:nabl,代码行数:18,代码来源:SG_analysis_has_errors.java


示例5: buildOp

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
private IStrategoTerm buildOp(String ctr, IContext env, IStrategoAppl t, ITermFactory factory) 
throws  InterpreterException {
    
    IStrategoList children = (IStrategoList) t.getSubterm(1);

    IStrategoConstructor ctor = factory.makeConstructor(ctr, children.size());
    IStrategoTerm[] kids = new IStrategoTerm[children.size()];

    for (int i = children.size() -1 ; i >= 0; i--) {
        IStrategoTerm kid = buildTerm(env, (IStrategoAppl) children.getSubterm(i));
        if (kid == null) {
            return null;
        }
        kids[i] = kid;
    }

    return factory.makeAppl(ctor, kids);
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:19,代码来源:Build.java


示例6: call

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] sargs, IStrategoTerm[] targs) throws InterpreterException {

    if(!(Tools.isTermInt(targs[0])))
        return false;
    if(!(Tools.isTermInt(targs[1])))
        return false;

    int initialSize = ((IStrategoInt)targs[0]).intValue();
    int maxLoad = ((IStrategoInt)targs[1]).intValue();

    IStrategoTerm result = new StrategoSet(initialSize, maxLoad);
    env.setCurrent(result);
    
    return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:17,代码来源:SSL_indexedSet_create.java


示例7: call

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
        throws InterpreterException {
    
   if (tvars[0].getTermType() != IStrategoTerm.STRING)
       return false;

   SSLLibrary library = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
   IStrategoString filename = (IStrategoString) tvars[0];
   File file = library.getIOAgent().openFile(filename.stringValue());

   if (!file.exists())
       return false;
   
   // TODO: Return filemode as an int?
   env.setCurrent(env.getFactory().makeTuple(filename, env.getFactory().makeInt(0)));
   
   return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:20,代码来源:SSL_filemode.java


示例8: getTermArguments

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
private IStrategoTerm getTermArguments(IContext env, IStrategoTerm t) throws InterpreterException {

        switch(t.getTermType()) {
        case IStrategoTerm.INT:
        case IStrategoTerm.REAL:
            return env.getFactory().makeList();
        case IStrategoTerm.APPL:
            IStrategoAppl a = (IStrategoAppl)t;
            if (Tools.isNil(a, env) || Tools.isCons(a, env))
                return t;
            else
                return env.getFactory().makeList(a.getAllSubterms());
        case IStrategoTerm.LIST: 
            return t;
        case IStrategoTerm.STRING:
            return env.getFactory().makeList();
        case IStrategoTerm.TUPLE:
            IStrategoTuple tup = (IStrategoTuple) t;
            IStrategoTerm[] args = new IStrategoTerm[tup.getSubtermCount()];
            for(int i = 0; i < args.length; i++) 
                args[i] = tup.get(i);
            return env.getFactory().makeList(args); 
        }
            
        throw new InterpreterException("Unknown term '" + t + "'");
    }
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:27,代码来源:Match.java


示例9: call

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
        throws InterpreterException {
    
    IStrategoTerm time = tvars[0];
    int timeValue; 
    
    if (time.getTermType() == IStrategoTerm.REAL)
        timeValue = (int) ((IStrategoReal) time).realValue();
    else if (time.getTermType() == IStrategoTerm.INT)
        timeValue = ((IStrategoInt) time).intValue();
    else
        return false;
    
    env.setCurrent(env.getFactory().makeReal(timeValue / (double) SSL_times.TICKS_PER_SECOND));
    return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:18,代码来源:SSL_TicksToSeconds.java


示例10: call

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
/**
 * Returns times for self and children:
 * (utime, stime, cutime, cstime)
 */
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
        throws InterpreterException {
    
    ITermFactory factory = env.getFactory();
    
    int utime = (int) (getUserTime() * TICKS_PER_SECOND / 1000000000);
    int stime = (int) (getSystemTime() * TICKS_PER_SECOND / 1000000000);
    
    IStrategoTerm utimeTerm = factory.makeInt(utime);
    IStrategoTerm stimeTerm = factory.makeInt(stime);
    IStrategoTerm ctimeTerm = factory.makeInt(0);
    
    env.setCurrent(factory.makeTuple(utimeTerm, stimeTerm, ctimeTerm, ctimeTerm));
    
    return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:22,代码来源:SSL_times.java


示例11: call

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override public Optional<ITerm> call(IScopeGraphContext<?> context, ITerm term, List<ITerm> terms)
    throws InterpreterException {
    if (terms.size() != 1) {
        throw new InterpreterException("Need one term argument: analysis");
    }
    final ITermIndex analysis = TermIndex.get(terms.get(0))
            .orElseThrow(() -> new InterpreterException("Not an analysis term."));
    return Occurrence.matcher().match(term).<ITerm>flatMap(ref -> {
        return context.unit(analysis.getResource()).solution().flatMap(s -> {
            final Set<IResolutionPath<Scope, Label, Occurrence>> paths = s.getNameResolution().resolve(ref);
            List<ITerm> pathTerms = Lists.newArrayListWithExpectedSize(paths.size());
            for(IResolutionPath<Scope, Label, Occurrence> path : paths) {
                pathTerms.add(TB.newTuple(path.getDeclaration(), Paths.toTerm(path)));
            }
            ITerm result = TB.newList(pathTerms);
            return Optional.of(result);
        });
    });
}
 
开发者ID:metaborg,项目名称:nabl,代码行数:20,代码来源:SG_get_ref_resolution.java


示例12: call

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
        throws InterpreterException {
    
    if(!Tools.isTermString(tvars[0]))
        return false;
    
    SSLLibrary or = (SSLLibrary) env.getOperatorRegistry(SSLLibrary.REGISTRY_NAME);
    
    String dir = Tools.javaString(tvars[0]);
    
    String[] entries = or.getIOAgent().readdir(dir);
    if(entries == null)
        return false;
    
    ITermFactory fac = env.getFactory();
    IStrategoTerm[] ts = new IStrategoTerm[entries.length];
    for(int i = 0; i< entries.length; i++)
        ts[i] = fac.makeString(entries[i]);
    
    env.setCurrent(fac.makeList(ts));
    return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:24,代码来源:SSL_readdir.java


示例13: register

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
protected synchronized static SDF register(String language, InputStream parseTable) throws IOException, InvalidParseTableException, InterpreterException {
    org.spoofax.jsglr.Tools.setOutput(java.io.File.createTempFile("jsglr", "log").getAbsolutePath());
    
    ParseTable table = Environment.loadParseTable(parseTable);
    SDF result = new SDF(table);
    allSDF.put(language, result);		
    
    if (imploder == null) {
        imploder = Environment.createInterpreter();
    }

    return result;
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:14,代码来源:SDF.java


示例14: register

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
/**
 * Register a new Stratego program.
 */
private static synchronized StrategoProgram register(String programName, InputStream program) throws InterpreterException, IOException {
    Interpreter interpreter = Environment.createInterpreter();
    interpreter.load(program);

    StrategoProgram result = new StrategoProgram(interpreter);
    allPrograms.put(programName, result);
    
    return result;
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:13,代码来源:StrategoProgram.java


示例15: invoke

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
public synchronized IStrategoTerm invoke(String strategy, IStrategoTerm term) {
    interpreter.setCurrent(term);
    
    try {
        boolean success = interpreter.invoke(strategy);
        if (!success) return Environment.getTermFactory().makeString("Evaluation failed");
    } catch (InterpreterException e) {
        throw new RuntimeException(e);
    }
    
    // TODO: Better handling of failure
    
    return interpreter.current();
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:15,代码来源:StrategoProgram.java


示例16: call

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override public Optional<ITerm> call(IScopeGraphContext<?> context, ITerm term, List<ITerm> terms)
    throws InterpreterException {
    if(terms.size() != 1) {
        throw new InterpreterException("Need one term argument: analysis");
    }
    return TermIndex.get(terms.get(0)).flatMap(index -> {
        return Scope.matcher().match(term).<ITerm>flatMap(scope -> {
            return context.unit(index.getResource()).solution().<ITerm>map(s -> {
                return TB.newList(s.getScopeGraph().getRefs().inverse().get(scope));
            });
        });
    });
}
 
开发者ID:metaborg,项目名称:nabl,代码行数:14,代码来源:SG_get_scope_refs.java


示例17: invoke

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override public @Nullable IStrategoTerm invoke(HybridInterpreter runtime, IStrategoTerm input, String strategy)
    throws MetaborgException {
    runtime.setCurrent(input);
    try {
        boolean success = runtime.invoke(strategy);
        if(!success) {
            return null;
        }
        return runtime.current();
    } catch(InterpreterException e) {
        throw handleException(e, runtime, strategy);
    }
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:14,代码来源:StrategoCommon.java


示例18: loadCtrees

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
private static void loadCtrees(HybridInterpreter runtime, Iterable<FileObject> ctrees) throws MetaborgException {
    try {
        for(FileObject file : ctrees) {
            logger.trace("Loading ctree {}", file.getName());
            runtime.load(new BufferedInputStream(file.getContent().getInputStream()));
        }
    } catch(IOException | InterpreterException e) {
        throw new MetaborgException("Failed to load ctree", e);
    }
}
 
开发者ID:metaborg,项目名称:spoofax,代码行数:11,代码来源:StrategoRuntimeService.java


示例19: call

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars)
		throws InterpreterException {
	if(!Tools.isTermString(tvars[0]))
		return false;
	
	JFFLibrary lib = JFFLibrary.instance(env);
	
	final String typeName = Tools.asJavaString(tvars[0]);
	
	if("int".equals(typeName)) {
		env.setCurrent(lib.wrapObject(Integer.TYPE));
	} else if("float".equals(typeName)) {
		env.setCurrent(lib.wrapObject(Float.TYPE));
	} else if("double".equals(typeName)) {
		env.setCurrent(lib.wrapObject(Double.TYPE));
	} else if("char".equals(typeName)) {
		env.setCurrent(lib.wrapObject(Character.TYPE));
	} else if("byte".equals(typeName)) {
		env.setCurrent(lib.wrapObject(Byte.TYPE));
	} else if("long".equals(typeName)) {
		env.setCurrent(lib.wrapObject(Long.TYPE));
	} else if("short".equals(typeName)) {
		env.setCurrent(lib.wrapObject(Short.TYPE));
	} else {
		return false;
	}
		
	return true;
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:31,代码来源:JFF_find_primitive_type.java


示例20: eval

import org.spoofax.interpreter.core.InterpreterException; //导入依赖的package包/类
public IConstruct eval(IContext env) throws InterpreterException {
    if (DebugUtil.isDebugging()) {
        debug("GuardedLChoice.eval() - ", env.current());
    }

    return eval(env, 0);
}
 
开发者ID:metaborg,项目名称:mb-exec,代码行数:8,代码来源:GuardedLChoice.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Opcodes类代码示例发布时间:2022-05-23
下一篇:
Java Node类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap