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


Java ArrayComprehensionLoop类代码示例

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


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

示例1: print

import org.mozilla.javascript.ast.ArrayComprehensionLoop; //导入依赖的package包/类
private void print(ArrayComprehension node) throws IOException {
    writer.append("[");
    for (ArrayComprehensionLoop loop : node.getLoops()) {
        writer.append("for").ws().append("(");
        print(loop.getIterator());
        writer.append(" of ");
        print(loop.getIteratedObject());
        writer.append(')');
    }
    if (node.getFilter() != null) {
        writer.append("if").ws().append("(");
        print(node.getFilter());
        writer.append(")");
    }
    print(node.getResult());
    writer.append(']');
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:18,代码来源:AstWriter.java

示例2: arrayComprehension

import org.mozilla.javascript.ast.ArrayComprehensionLoop; //导入依赖的package包/类
/**
 * Parse a JavaScript 1.7 Array comprehension.
 * @param result the first expression after the opening left-bracket
 * @param pos start of LB token that begins the array comprehension
 * @return the array comprehension or an error node
 */
private AstNode arrayComprehension(AstNode result, int pos)
    throws IOException
{
    List<ArrayComprehensionLoop> loops =
            new ArrayList<ArrayComprehensionLoop>();
    while (peekToken() == Token.FOR) {
        loops.add(arrayComprehensionLoop());
    }
    int ifPos = -1;
    ConditionData data = null;
    if (peekToken() == Token.IF) {
        consumeToken();
        ifPos = ts.tokenBeg - pos;
        data = condition();
    }
    mustMatchToken(Token.RB, "msg.no.bracket.arg");
    ArrayComprehension pn = new ArrayComprehension(pos, ts.tokenEnd - pos);
    pn.setResult(result);
    pn.setLoops(loops);
    if (data != null) {
        pn.setIfPosition(ifPos);
        pn.setFilter(data.condition);
        pn.setFilterLp(data.lp - pos);
        pn.setFilterRp(data.rp - pos);
    }
    return pn;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:34,代码来源:Parser.java

示例3: arrayComprehensionLoop

import org.mozilla.javascript.ast.ArrayComprehensionLoop; //导入依赖的package包/类
private ArrayComprehensionLoop arrayComprehensionLoop()
    throws IOException
{
    if (nextToken() != Token.FOR) codeBug();
    int pos = ts.tokenBeg;
    int eachPos = -1, lp = -1, rp = -1, inPos = -1;
    boolean isForIn = false, isForOf = false;
    ArrayComprehensionLoop pn = new ArrayComprehensionLoop(pos);

    pushScope(pn);
    try {
        if (matchToken(Token.NAME)) {
            if (ts.getString().equals("each")) {
                eachPos = ts.tokenBeg - pos;
            } else {
                reportError("msg.no.paren.for");
            }
        }
        if (mustMatchToken(Token.LP, "msg.no.paren.for")) {
            lp = ts.tokenBeg - pos;
        }

        AstNode iter = null;
        switch (peekToken()) {
          case Token.LB:
          case Token.LC:
              // handle destructuring assignment
              iter = destructuringPrimaryExpr();
              markDestructuring(iter);
              break;
          case Token.NAME:
              consumeToken();
              iter = createNameNode();
              break;
          default:
              reportError("msg.bad.var");
        }

        // Define as a let since we want the scope of the variable to
        // be restricted to the array comprehension
        if (iter.getType() == Token.NAME) {
            defineSymbol(Token.LET, ts.getString(), true);
        }

        switch (nextToken()) {
        case Token.IN:
            inPos = ts.tokenBeg - pos;
            isForIn = true;
            break;
        case Token.NAME:
            if ("of".equals(ts.getString())) {
                if (eachPos != -1) {
                    reportError("msg.invalid.for.each");
                }
                inPos = ts.tokenBeg - pos;
                isForOf = true;
                break;
            }
            // fallthru
        default:
            reportError("msg.in.after.for.name");
        }
        AstNode obj = expr();
        if (mustMatchToken(Token.RP, "msg.no.paren.for.ctrl"))
            rp = ts.tokenBeg - pos;

        pn.setLength(ts.tokenEnd - pos);
        pn.setIterator(iter);
        pn.setIteratedObject(obj);
        pn.setInPosition(inPos);
        pn.setEachPosition(eachPos);
        pn.setIsForEach(eachPos != -1);
        pn.setParens(lp, rp);
        pn.setIsForOf(isForOf);
        return pn;
    } finally {
        popScope();
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:80,代码来源:Parser.java


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