Search in sources :

Example 26 with AstNode

use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.

the class Parser method xmlElemRef.

/**
 * Parse the [expr] portion of an xml element reference, e.g.
 * @[expr], @*::[expr], or ns::[expr].
 */
private XmlElemRef xmlElemRef(int atPos, Name namespace, int colonPos) throws IOException {
    int lb = ts.tokenBeg, rb = -1, pos = atPos != -1 ? atPos : lb;
    AstNode expr = expr();
    int end = getNodeEnd(expr);
    if (mustMatchToken(Token.RB, "msg.no.bracket.index")) {
        rb = ts.tokenBeg;
        end = ts.tokenEnd;
    }
    XmlElemRef ref = new XmlElemRef(pos, end - pos);
    ref.setNamespace(namespace);
    ref.setColonPos(colonPos);
    ref.setAtPos(atPos);
    ref.setExpression(expr);
    ref.setBrackets(lb, rb);
    return ref;
}
Also used : XmlElemRef(org.mozilla.javascript.ast.XmlElemRef) AstNode(org.mozilla.javascript.ast.AstNode)

Example 27 with AstNode

use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.

the class Parser method andExpr.

private AstNode andExpr() throws IOException {
    AstNode pn = bitOrExpr();
    if (matchToken(Token.AND)) {
        int opPos = ts.tokenBeg;
        pn = new InfixExpression(Token.AND, pn, andExpr(), opPos);
    }
    return pn;
}
Also used : InfixExpression(org.mozilla.javascript.ast.InfixExpression) AstNode(org.mozilla.javascript.ast.AstNode)

Example 28 with AstNode

use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.

the class Parser method tryStatement.

private TryStatement tryStatement() throws IOException {
    if (currentToken != Token.TRY)
        codeBug();
    consumeToken();
    // Pull out JSDoc info and reset it before recursing.
    Comment jsdocNode = getAndResetJsDoc();
    int tryPos = ts.tokenBeg, lineno = ts.lineno, finallyPos = -1;
    if (peekToken() != Token.LC) {
        reportError("msg.no.brace.try");
    }
    AstNode tryBlock = statement();
    int tryEnd = getNodeEnd(tryBlock);
    List<CatchClause> clauses = null;
    boolean sawDefaultCatch = false;
    int peek = peekToken();
    if (peek == Token.CATCH) {
        while (matchToken(Token.CATCH)) {
            int catchLineNum = ts.lineno;
            if (sawDefaultCatch) {
                reportError("msg.catch.unreachable");
            }
            int catchPos = ts.tokenBeg, lp = -1, rp = -1, guardPos = -1;
            if (mustMatchToken(Token.LP, "msg.no.paren.catch"))
                lp = ts.tokenBeg;
            mustMatchToken(Token.NAME, "msg.bad.catchcond");
            Name varName = createNameNode();
            Comment jsdocNodeForName = getAndResetJsDoc();
            if (jsdocNodeForName != null) {
                varName.setJsDocNode(jsdocNodeForName);
            }
            String varNameString = varName.getIdentifier();
            if (inUseStrictDirective) {
                if ("eval".equals(varNameString) || "arguments".equals(varNameString)) {
                    reportError("msg.bad.id.strict", varNameString);
                }
            }
            AstNode catchCond = null;
            if (matchToken(Token.IF)) {
                guardPos = ts.tokenBeg;
                catchCond = expr();
            } else {
                sawDefaultCatch = true;
            }
            if (mustMatchToken(Token.RP, "msg.bad.catchcond"))
                rp = ts.tokenBeg;
            mustMatchToken(Token.LC, "msg.no.brace.catchblock");
            Block catchBlock = (Block) statements();
            tryEnd = getNodeEnd(catchBlock);
            CatchClause catchNode = new CatchClause(catchPos);
            catchNode.setVarName(varName);
            catchNode.setCatchCondition(catchCond);
            catchNode.setBody(catchBlock);
            if (guardPos != -1) {
                catchNode.setIfPosition(guardPos - catchPos);
            }
            catchNode.setParens(lp, rp);
            catchNode.setLineno(catchLineNum);
            if (mustMatchToken(Token.RC, "msg.no.brace.after.body"))
                tryEnd = ts.tokenEnd;
            catchNode.setLength(tryEnd - catchPos);
            if (clauses == null)
                clauses = new ArrayList<CatchClause>();
            clauses.add(catchNode);
        }
    } else if (peek != Token.FINALLY) {
        mustMatchToken(Token.FINALLY, "msg.try.no.catchfinally");
    }
    AstNode finallyBlock = null;
    if (matchToken(Token.FINALLY)) {
        finallyPos = ts.tokenBeg;
        finallyBlock = statement();
        tryEnd = getNodeEnd(finallyBlock);
    }
    TryStatement pn = new TryStatement(tryPos, tryEnd - tryPos);
    pn.setTryBlock(tryBlock);
    pn.setCatchClauses(clauses);
    pn.setFinallyBlock(finallyBlock);
    if (finallyPos != -1) {
        pn.setFinallyPosition(finallyPos - tryPos);
    }
    pn.setLineno(lineno);
    if (jsdocNode != null) {
        pn.setJsDocNode(jsdocNode);
    }
    return pn;
}
Also used : Comment(org.mozilla.javascript.ast.Comment) TryStatement(org.mozilla.javascript.ast.TryStatement) ArrayList(java.util.ArrayList) Block(org.mozilla.javascript.ast.Block) CatchClause(org.mozilla.javascript.ast.CatchClause) XmlString(org.mozilla.javascript.ast.XmlString) AstNode(org.mozilla.javascript.ast.AstNode) Name(org.mozilla.javascript.ast.Name)

Example 29 with AstNode

use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.

the class Parser method ifStatement.

private IfStatement ifStatement() throws IOException {
    if (currentToken != Token.IF)
        codeBug();
    consumeToken();
    int pos = ts.tokenBeg, lineno = ts.lineno, elsePos = -1;
    ConditionData data = condition();
    AstNode ifTrue = statement(), ifFalse = null;
    if (matchToken(Token.ELSE)) {
        elsePos = ts.tokenBeg - pos;
        ifFalse = statement();
    }
    int end = getNodeEnd(ifFalse != null ? ifFalse : ifTrue);
    IfStatement pn = new IfStatement(pos, end - pos);
    pn.setCondition(data.condition);
    pn.setParens(data.lp - pos, data.rp - pos);
    pn.setThenPart(ifTrue);
    pn.setElsePart(ifFalse);
    pn.setElsePosition(elsePos);
    pn.setLineno(lineno);
    return pn;
}
Also used : IfStatement(org.mozilla.javascript.ast.IfStatement) AstNode(org.mozilla.javascript.ast.AstNode)

Example 30 with AstNode

use of org.mozilla.javascript.ast.AstNode in project HL4A by HL4A.

the class Parser method parenExpr.

private AstNode parenExpr() throws IOException {
    boolean wasInForInit = inForInit;
    inForInit = false;
    try {
        Comment jsdocNode = getAndResetJsDoc();
        int lineno = ts.lineno;
        int begin = ts.tokenBeg;
        AstNode e = (peekToken() == Token.RP ? new EmptyExpression(begin) : expr());
        if (peekToken() == Token.FOR) {
            return generatorExpression(e, begin);
        }
        ParenthesizedExpression pn = new ParenthesizedExpression(e);
        if (jsdocNode == null) {
            jsdocNode = getAndResetJsDoc();
        }
        if (jsdocNode != null) {
            pn.setJsDocNode(jsdocNode);
        }
        mustMatchToken(Token.RP, "msg.no.paren");
        if (e.getType() == Token.EMPTY && peekToken() != Token.ARROW) {
            reportError("msg.syntax");
            return makeErrorNode();
        }
        pn.setLength(ts.tokenEnd - pn.getPosition());
        pn.setLineno(lineno);
        return pn;
    } finally {
        inForInit = wasInForInit;
    }
}
Also used : ParenthesizedExpression(org.mozilla.javascript.ast.ParenthesizedExpression) Comment(org.mozilla.javascript.ast.Comment) AstNode(org.mozilla.javascript.ast.AstNode) EmptyExpression(org.mozilla.javascript.ast.EmptyExpression)

Aggregations

AstNode (org.mozilla.javascript.ast.AstNode)80 FunctionNode (org.mozilla.javascript.ast.FunctionNode)22 LetNode (org.mozilla.javascript.ast.LetNode)22 ScriptNode (org.mozilla.javascript.ast.ScriptNode)19 XmlString (org.mozilla.javascript.ast.XmlString)15 InfixExpression (org.mozilla.javascript.ast.InfixExpression)13 EmptyExpression (org.mozilla.javascript.ast.EmptyExpression)9 Comment (org.mozilla.javascript.ast.Comment)8 Name (org.mozilla.javascript.ast.Name)8 ArrayList (java.util.ArrayList)6 Block (org.mozilla.javascript.ast.Block)5 ExpressionStatement (org.mozilla.javascript.ast.ExpressionStatement)5 VariableDeclaration (org.mozilla.javascript.ast.VariableDeclaration)5 ArrayComprehensionLoop (org.mozilla.javascript.ast.ArrayComprehensionLoop)4 ErrorNode (org.mozilla.javascript.ast.ErrorNode)4 GeneratorExpressionLoop (org.mozilla.javascript.ast.GeneratorExpressionLoop)4 DoLoop (org.mozilla.javascript.ast.DoLoop)3 Scope (org.mozilla.javascript.ast.Scope)3 VariableInitializer (org.mozilla.javascript.ast.VariableInitializer)3 IOException (java.io.IOException)2