Search in sources :

Example 1 with RegExpLiteral

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

the class Parser method primaryExpr.

private AstNode primaryExpr() throws IOException {
    int ttFlagged = peekFlaggedToken();
    int tt = ttFlagged & CLEAR_TI_MASK;
    switch(tt) {
        case Token.FUNCTION:
            consumeToken();
            return function(FunctionNode.FUNCTION_EXPRESSION);
        case Token.LB:
            consumeToken();
            return arrayLiteral();
        case Token.LC:
            consumeToken();
            return objectLiteral();
        case Token.LET:
            consumeToken();
            return let(false, ts.tokenBeg);
        case Token.LP:
            consumeToken();
            return parenExpr();
        case Token.XMLATTR:
            consumeToken();
            mustHaveXML();
            return attributeAccess();
        case Token.NAME:
            consumeToken();
            return name(ttFlagged, tt);
        case Token.NUMBER:
            {
                consumeToken();
                String s = ts.getString();
                if (this.inUseStrictDirective && ts.isNumberOldOctal()) {
                    reportError("msg.no.old.octal.strict");
                }
                if (ts.isNumberBinary()) {
                    s = "0b" + s;
                }
                if (ts.isNumberOldOctal()) {
                    s = "0" + s;
                }
                if (ts.isNumberOctal()) {
                    s = "0o" + s;
                }
                if (ts.isNumberHex()) {
                    s = "0x" + s;
                }
                return new NumberLiteral(ts.tokenBeg, s, ts.getNumber());
            }
        case Token.STRING:
            consumeToken();
            return createStringLiteral();
        case Token.DIV:
        case Token.ASSIGN_DIV:
            consumeToken();
            // Got / or /= which in this context means a regexp
            ts.readRegExp(tt);
            int pos = ts.tokenBeg, end = ts.tokenEnd;
            RegExpLiteral re = new RegExpLiteral(pos, end - pos);
            re.setValue(ts.getString());
            re.setFlags(ts.readAndClearRegExpFlags());
            return re;
        case Token.NULL:
        case Token.THIS:
        case Token.FALSE:
        case Token.TRUE:
            consumeToken();
            pos = ts.tokenBeg;
            end = ts.tokenEnd;
            return new KeywordLiteral(pos, end - pos, tt);
        case Token.RESERVED:
            consumeToken();
            reportError("msg.reserved.id");
            break;
        case Token.ERROR:
            consumeToken();
            // the scanner or one of its subroutines reported the error.
            break;
        case Token.EOF:
            consumeToken();
            reportError("msg.unexpected.eof");
            break;
        default:
            consumeToken();
            reportError("msg.syntax");
            break;
    }
    // should only be reachable in IDE/error-recovery mode
    consumeToken();
    return makeErrorNode();
}
Also used : KeywordLiteral(org.mozilla.javascript.ast.KeywordLiteral) RegExpLiteral(org.mozilla.javascript.ast.RegExpLiteral) XmlString(org.mozilla.javascript.ast.XmlString) NumberLiteral(org.mozilla.javascript.ast.NumberLiteral)

Aggregations

KeywordLiteral (org.mozilla.javascript.ast.KeywordLiteral)1 NumberLiteral (org.mozilla.javascript.ast.NumberLiteral)1 RegExpLiteral (org.mozilla.javascript.ast.RegExpLiteral)1 XmlString (org.mozilla.javascript.ast.XmlString)1