Search in sources :

Example 76 with AstNode

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

the class Parser method doLoop.

private DoLoop doLoop() throws IOException {
    if (currentToken != Token.DO)
        codeBug();
    consumeToken();
    int pos = ts.tokenBeg, end;
    DoLoop pn = new DoLoop(pos);
    pn.setLineno(ts.lineno);
    enterLoop(pn);
    try {
        AstNode body = statement();
        mustMatchToken(Token.WHILE, "msg.no.while.do");
        pn.setWhilePosition(ts.tokenBeg - pos);
        ConditionData data = condition();
        pn.setCondition(data.condition);
        pn.setParens(data.lp - pos, data.rp - pos);
        end = getNodeEnd(body);
        pn.setBody(body);
    } finally {
        exitLoop();
    }
    // world, see bug 238945
    if (matchToken(Token.SEMI)) {
        end = ts.tokenEnd;
    }
    pn.setLength(end - pos);
    return pn;
}
Also used : DoLoop(org.mozilla.javascript.ast.DoLoop) AstNode(org.mozilla.javascript.ast.AstNode)

Example 77 with AstNode

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

the class Parser method defaultXmlNamespace.

private AstNode defaultXmlNamespace() throws IOException {
    if (currentToken != Token.DEFAULT)
        codeBug();
    consumeToken();
    mustHaveXML();
    setRequiresActivation();
    int lineno = ts.lineno, pos = ts.tokenBeg;
    if (!(matchToken(Token.NAME) && "xml".equals(ts.getString()))) {
        reportError("msg.bad.namespace");
    }
    if (!(matchToken(Token.NAME) && "namespace".equals(ts.getString()))) {
        reportError("msg.bad.namespace");
    }
    if (!matchToken(Token.ASSIGN)) {
        reportError("msg.bad.namespace");
    }
    AstNode e = expr();
    UnaryExpression dxmln = new UnaryExpression(pos, getNodeEnd(e) - pos);
    dxmln.setOperator(Token.DEFAULTNAMESPACE);
    dxmln.setOperand(e);
    dxmln.setLineno(lineno);
    ExpressionStatement es = new ExpressionStatement(dxmln, true);
    return es;
}
Also used : ExpressionStatement(org.mozilla.javascript.ast.ExpressionStatement) UnaryExpression(org.mozilla.javascript.ast.UnaryExpression) AstNode(org.mozilla.javascript.ast.AstNode)

Example 78 with AstNode

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

the class Parser method bitXorExpr.

private AstNode bitXorExpr() throws IOException {
    AstNode pn = bitAndExpr();
    while (matchToken(Token.BITXOR)) {
        int opPos = ts.tokenBeg;
        pn = new InfixExpression(Token.BITXOR, pn, bitAndExpr(), opPos);
    }
    return pn;
}
Also used : InfixExpression(org.mozilla.javascript.ast.InfixExpression) AstNode(org.mozilla.javascript.ast.AstNode)

Example 79 with AstNode

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

the class Parser method statement.

private AstNode statement() throws IOException {
    int pos = ts.tokenBeg;
    try {
        AstNode pn = statementHelper();
        if (pn != null) {
            if (compilerEnv.isStrictMode() && !pn.hasSideEffects()) {
                int beg = pn.getPosition();
                beg = Math.max(beg, lineBeginningFor(beg));
                addStrictWarning(pn instanceof EmptyStatement ? "msg.extra.trailing.semi" : "msg.no.side.effects", "", beg, nodeEnd(pn) - beg);
            }
            return pn;
        }
    } catch (ParserException e) {
    // an ErrorNode was added to the ErrorReporter
    }
    // error:  skip ahead to a probable statement boundary
    guessingStatementEnd: for (; ; ) {
        int tt = peekTokenOrEOL();
        consumeToken();
        switch(tt) {
            case Token.ERROR:
            case Token.EOF:
            case Token.EOL:
            case Token.SEMI:
                break guessingStatementEnd;
        }
    }
    // something different here.
    return new EmptyStatement(pos, ts.tokenBeg - pos);
}
Also used : EmptyStatement(org.mozilla.javascript.ast.EmptyStatement) AstNode(org.mozilla.javascript.ast.AstNode)

Example 80 with AstNode

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

the class Parser method destructuringObject.

boolean destructuringObject(ObjectLiteral node, int variableType, String tempName, Node parent, List<String> destructuringNames) {
    boolean empty = true;
    int setOp = variableType == Token.CONST ? Token.SETCONST : Token.SETNAME;
    for (ObjectProperty prop : node.getElements()) {
        int lineno = 0;
        // tokenStream isn't set.  Deal with it.
        if (ts != null) {
            lineno = ts.lineno;
        }
        AstNode id = prop.getLeft();
        Node rightElem = null;
        if (id instanceof Name) {
            Node s = Node.newString(((Name) id).getIdentifier());
            rightElem = new Node(Token.GETPROP, createName(tempName), s);
        } else if (id instanceof StringLiteral) {
            Node s = Node.newString(((StringLiteral) id).getValue());
            rightElem = new Node(Token.GETPROP, createName(tempName), s);
        } else if (id instanceof NumberLiteral) {
            Node s = createNumber((int) ((NumberLiteral) id).getNumber());
            rightElem = new Node(Token.GETELEM, createName(tempName), s);
        } else {
            throw codeBug();
        }
        rightElem.setLineno(lineno);
        AstNode value = prop.getRight();
        if (value.getType() == Token.NAME) {
            String name = ((Name) value).getIdentifier();
            parent.addChildToBack(new Node(setOp, createName(Token.BINDNAME, name, null), rightElem));
            if (variableType != -1) {
                defineSymbol(variableType, name, true);
                destructuringNames.add(name);
            }
        } else {
            parent.addChildToBack(destructuringAssignmentHelper(variableType, value, rightElem, currentScriptOrFn.getNextTempName()));
        }
        empty = false;
    }
    return empty;
}
Also used : ObjectProperty(org.mozilla.javascript.ast.ObjectProperty) StringLiteral(org.mozilla.javascript.ast.StringLiteral) ScriptNode(org.mozilla.javascript.ast.ScriptNode) AstNode(org.mozilla.javascript.ast.AstNode) LetNode(org.mozilla.javascript.ast.LetNode) ErrorNode(org.mozilla.javascript.ast.ErrorNode) FunctionNode(org.mozilla.javascript.ast.FunctionNode) XmlString(org.mozilla.javascript.ast.XmlString) AstNode(org.mozilla.javascript.ast.AstNode) NumberLiteral(org.mozilla.javascript.ast.NumberLiteral) Name(org.mozilla.javascript.ast.Name)

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