jdk.nashorn.internal.runtime.regexp.joni.ast.ConsAltNode Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.regexp.joni.ast.ConsAltNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #2
Source File: Parser.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private Node parseSubExp(TokenType term) {
    Node node = parseBranch(term);

    if (token.type == term) {
        return node;
    } else if (token.type == TokenType.ALT) {
        ConsAltNode top = ConsAltNode.newAltNode(node, null);
        ConsAltNode t = top;
        while (token.type == TokenType.ALT) {
            fetchToken();
            node = parseBranch(term);

            t.setCdr(ConsAltNode.newAltNode(node, null));
            t = t.cdr;
        }

        if (token.type != term) parseSubExpError(term);
        return top;
    } else {
        parseSubExpError(term);
        return null; //not reached
    }
}
 
Example #3
Source File: Parser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private Node parseSubExp(final TokenType term) {
    Node node = parseBranch(term);

    if (token.type == term) {
        return node;
    } else if (token.type == TokenType.ALT) {
        final ConsAltNode top = ConsAltNode.newAltNode(node, null);
        ConsAltNode t = top;
        while (token.type == TokenType.ALT) {
            fetchToken();
            node = parseBranch(term);

            t.setCdr(ConsAltNode.newAltNode(node, null));
            t = t.cdr;
        }

        if (token.type != term) {
            parseSubExpError(term);
        }
        return top;
    } else {
        parseSubExpError(term);
        return null; //not reached
    }
}
 
Example #4
Source File: Parser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #5
Source File: Parser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseSubExp(final TokenType term) {
    Node node = parseBranch(term);

    if (token.type == term) {
        return node;
    } else if (token.type == TokenType.ALT) {
        final ConsAltNode top = ConsAltNode.newAltNode(node, null);
        ConsAltNode t = top;
        while (token.type == TokenType.ALT) {
            fetchToken();
            node = parseBranch(term);

            t.setCdr(ConsAltNode.newAltNode(node, null));
            t = t.cdr;
        }

        if (token.type != term) {
            parseSubExpError(term);
        }
        return top;
    } else {
        parseSubExpError(term);
        return null; //not reached
    }
}
 
Example #6
Source File: Parser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #7
Source File: Parser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseSubExp(final TokenType term) {
    Node node = parseBranch(term);

    if (token.type == term) {
        return node;
    } else if (token.type == TokenType.ALT) {
        final ConsAltNode top = ConsAltNode.newAltNode(node, null);
        ConsAltNode t = top;
        while (token.type == TokenType.ALT) {
            fetchToken();
            node = parseBranch(term);

            t.setCdr(ConsAltNode.newAltNode(node, null));
            t = t.cdr;
        }

        if (token.type != term) {
            parseSubExpError(term);
        }
        return top;
    } else {
        parseSubExpError(term);
        return null; //not reached
    }
}
 
Example #8
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Node parseBranch(final TokenType term) {
    Node node = parseExp(term);

    if (token.type == TokenType.EOT || token.type == term || token.type == TokenType.ALT) {
        return node;
    }
    final ConsAltNode top = ConsAltNode.newListNode(node, null);
    ConsAltNode t = top;

    while (token.type != TokenType.EOT && token.type != term && token.type != TokenType.ALT) {
        node = parseExp(term);
        if (node.getType() == NodeType.LIST) {
            t.setCdr((ConsAltNode)node);
            while (((ConsAltNode)node).cdr != null ) {
                node = ((ConsAltNode)node).cdr;
            }

            t = ((ConsAltNode)node);
        } else {
            t.setCdr(ConsAltNode.newListNode(node, null));
            t = t.cdr;
        }
    }
    return top;
}
 
Example #9
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseSubExp(final TokenType term) {
    Node node = parseBranch(term);

    if (token.type == term) {
        return node;
    } else if (token.type == TokenType.ALT) {
        final ConsAltNode top = ConsAltNode.newAltNode(node, null);
        ConsAltNode t = top;
        while (token.type == TokenType.ALT) {
            fetchToken();
            node = parseBranch(term);

            t.setCdr(ConsAltNode.newAltNode(node, null));
            t = t.cdr;
        }

        if (token.type != term) {
            parseSubExpError(term);
        }
        return top;
    } else {
        parseSubExpError(term);
        return null; //not reached
    }
}
 
Example #10
Source File: Parser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private Node parseSubExp(final TokenType term) {
    Node node = parseBranch(term);

    if (token.type == term) {
        return node;
    } else if (token.type == TokenType.ALT) {
        final ConsAltNode top = ConsAltNode.newAltNode(node, null);
        ConsAltNode t = top;
        while (token.type == TokenType.ALT) {
            fetchToken();
            node = parseBranch(term);

            t.setCdr(ConsAltNode.newAltNode(node, null));
            t = t.cdr;
        }

        if (token.type != term) {
            parseSubExpError(term);
        }
        return top;
    } else {
        parseSubExpError(term);
        return null; //not reached
    }
}
 
Example #11
Source File: Parser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpRepeat(Node target, boolean group) {
    while (token.type == TokenType.OP_REPEAT || token.type == TokenType.INTERVAL) { // repeat:
        if (target.isInvalidQuantifier()) {
            throw new SyntaxException(ERR_TARGET_OF_REPEAT_OPERATOR_INVALID);
        }

        QuantifierNode qtfr = new QuantifierNode(token.getRepeatLower(),
                                                 token.getRepeatUpper(),
                                                 token.type == TokenType.INTERVAL);

        qtfr.greedy = token.getRepeatGreedy();
        int ret = qtfr.setQuantifier(target, group, env, chars, getBegin(), getEnd());
        Node qn = qtfr;

        if (token.getRepeatPossessive()) {
            EncloseNode en = new EncloseNode(EncloseType.STOP_BACKTRACK); // node_new_enclose
            en.setTarget(qn);
            qn = en;
        }

        if (ret == 0) {
            target = qn;
        } else if (ret == 2) { /* split case: /abc+/ */
            target = ConsAltNode.newListNode(target, null);
            ConsAltNode tmp = ((ConsAltNode)target).setCdr(ConsAltNode.newListNode(qn, null));

            fetchToken();
            return parseExpRepeatForCar(target, tmp, group);
        }
        fetchToken(); // goto re_entry
    }
    return target;
}
 
Example #12
Source File: Analyser.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private Node divideLookBehindAlternatives(Node node) {
    AnchorNode an = (AnchorNode)node;
    int anchorType = an.type;
    Node head = an.target;
    Node np = ((ConsAltNode)head).car;

    swap(node, head);

    Node tmp = node;
    node = head;
    head = tmp;

    ((ConsAltNode)node).setCar(head);
    ((AnchorNode)head).setTarget(np);
    np = node;

    while ((np = ((ConsAltNode)np).cdr) != null) {
        AnchorNode insert = new AnchorNode(anchorType);
        insert.setTarget(((ConsAltNode)np).car);
        ((ConsAltNode)np).setCar(insert);
    }

    if (anchorType == AnchorType.LOOK_BEHIND_NOT) {
        np = node;
        do {
            ((ConsAltNode)np).toListNode(); /* alt -> list */
        } while ((np = ((ConsAltNode)np).cdr) != null);
    }

    return node;
}
 
Example #13
Source File: Parser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpRepeatForCar(final Node top, final ConsAltNode target, final boolean group) {
    while (token.type == TokenType.OP_REPEAT || token.type == TokenType.INTERVAL) { // repeat:
        if (target.car.isInvalidQuantifier()) {
            throw new SyntaxException(ERR_TARGET_OF_REPEAT_OPERATOR_INVALID);
        }

        final QuantifierNode qtfr = new QuantifierNode(token.getRepeatLower(),
                                                 token.getRepeatUpper(),
                                                 token.type == TokenType.INTERVAL);

        qtfr.greedy = token.getRepeatGreedy();
        final int ret = qtfr.setQuantifier(target.car, group, env, chars, getBegin(), getEnd());
        Node qn = qtfr;

        if (token.getRepeatPossessive()) {
            final EncloseNode en = new EncloseNode(EncloseType.STOP_BACKTRACK); // node_new_enclose
            en.setTarget(qn);
            qn = en;
        }

        if (ret == 0) {
            target.setCar(qn);
        } else if (ret == 2) { /* split case: /abc+/ */
            assert false;
        }
        fetchToken(); // goto re_entry
    }
    return top;
}
 
Example #14
Source File: ArrayCompiler.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void compileAltNode(ConsAltNode node) {
    ConsAltNode aln = node;
    int len = 0;

    do {
        len += compileLengthTree(aln.car);
        if (aln.cdr != null) {
            len += OPSize.PUSH + OPSize.JUMP;
        }
    } while ((aln = aln.cdr) != null);

    int pos = codeLength + len;  /* goal position */

    aln = node;
    do {
        len = compileLengthTree(aln.car);
        if (aln.cdr != null) {
            addOpcodeRelAddr(OPCode.PUSH, len + OPSize.JUMP);
        }
        compileTree(aln.car);
        if (aln.cdr != null) {
            len = pos - (codeLength + OPSize.JUMP);
            addOpcodeRelAddr(OPCode.JUMP, len);
        }
    } while ((aln = aln.cdr) != null);
}
 
Example #15
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpRepeatForCar(final Node top, final ConsAltNode target, final boolean group) {
    while (token.type == TokenType.OP_REPEAT || token.type == TokenType.INTERVAL) { // repeat:
        if (target.car.isInvalidQuantifier()) {
            throw new SyntaxException(ERR_TARGET_OF_REPEAT_OPERATOR_INVALID);
        }

        final QuantifierNode qtfr = new QuantifierNode(token.getRepeatLower(),
                                                 token.getRepeatUpper(),
                                                 token.type == TokenType.INTERVAL);

        qtfr.greedy = token.getRepeatGreedy();
        final int ret = qtfr.setQuantifier(target.car, group, env, chars, getBegin(), getEnd());
        Node qn = qtfr;

        if (token.getRepeatPossessive()) {
            final EncloseNode en = new EncloseNode(EncloseType.STOP_BACKTRACK); // node_new_enclose
            en.setTarget(qn);
            qn = en;
        }

        if (ret == 0) {
            target.setCar(qn);
        } else if (ret == 2) { /* split case: /abc+/ */
            assert false;
        }
        fetchToken(); // goto re_entry
    }
    return top;
}
 
Example #16
Source File: Parser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpRepeatForCar(final Node top, final ConsAltNode target, final boolean group) {
    while (token.type == TokenType.OP_REPEAT || token.type == TokenType.INTERVAL) { // repeat:
        if (target.car.isInvalidQuantifier()) {
            throw new SyntaxException(ERR_TARGET_OF_REPEAT_OPERATOR_INVALID);
        }

        final QuantifierNode qtfr = new QuantifierNode(token.getRepeatLower(),
                                                 token.getRepeatUpper(),
                                                 token.type == TokenType.INTERVAL);

        qtfr.greedy = token.getRepeatGreedy();
        final int ret = qtfr.setQuantifier(target.car, group, env, chars, getBegin(), getEnd());
        Node qn = qtfr;

        if (token.getRepeatPossessive()) {
            final EncloseNode en = new EncloseNode(EncloseType.STOP_BACKTRACK); // node_new_enclose
            en.setTarget(qn);
            qn = en;
        }

        if (ret == 0) {
            target.setCar(qn);
        } else if (ret == 2) { /* split case: /abc+/ */
            assert false;
        }
        fetchToken(); // goto re_entry
    }
    return top;
}
 
Example #17
Source File: ArrayCompiler.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void compileAltNode(ConsAltNode node) {
    ConsAltNode aln = node;
    int len = 0;

    do {
        len += compileLengthTree(aln.car);
        if (aln.cdr != null) {
            len += OPSize.PUSH + OPSize.JUMP;
        }
    } while ((aln = aln.cdr) != null);

    int pos = codeLength + len;  /* goal position */

    aln = node;
    do {
        len = compileLengthTree(aln.car);
        if (aln.cdr != null) {
            addOpcodeRelAddr(OPCode.PUSH, len + OPSize.JUMP);
        }
        compileTree(aln.car);
        if (aln.cdr != null) {
            len = pos - (codeLength + OPSize.JUMP);
            addOpcodeRelAddr(OPCode.JUMP, len);
        }
    } while ((aln = aln.cdr) != null);
}
 
Example #18
Source File: Analyser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private Node divideLookBehindAlternatives(final Node nodep) {
    Node node = nodep;
    final AnchorNode an = (AnchorNode)node;
    final int anchorType = an.type;
    Node head = an.target;
    Node np = ((ConsAltNode)head).car;

    swap(node, head);

    final Node tmp = node;
    node = head;
    head = tmp;

    ((ConsAltNode)node).setCar(head);
    ((AnchorNode)head).setTarget(np);
    np = node;

    while ((np = ((ConsAltNode)np).cdr) != null) {
        final AnchorNode insert = new AnchorNode(anchorType);
        insert.setTarget(((ConsAltNode)np).car);
        ((ConsAltNode)np).setCar(insert);
    }

    if (anchorType == AnchorType.LOOK_BEHIND_NOT) {
        np = node;
        do {
            ((ConsAltNode)np).toListNode(); /* alt -> list */
        } while ((np = ((ConsAltNode)np).cdr) != null);
    }

    return node;
}
 
Example #19
Source File: Analyser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private Node divideLookBehindAlternatives(Node node) {
    AnchorNode an = (AnchorNode)node;
    int anchorType = an.type;
    Node head = an.target;
    Node np = ((ConsAltNode)head).car;

    swap(node, head);

    Node tmp = node;
    node = head;
    head = tmp;

    ((ConsAltNode)node).setCar(head);
    ((AnchorNode)head).setTarget(np);
    np = node;

    while ((np = ((ConsAltNode)np).cdr) != null) {
        AnchorNode insert = new AnchorNode(anchorType);
        insert.setTarget(((ConsAltNode)np).car);
        ((ConsAltNode)np).setCar(insert);
    }

    if (anchorType == AnchorType.LOOK_BEHIND_NOT) {
        np = node;
        do {
            ((ConsAltNode)np).toListNode(); /* alt -> list */
        } while ((np = ((ConsAltNode)np).cdr) != null);
    }

    return node;
}
 
Example #20
Source File: Analyser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Node divideLookBehindAlternatives(final Node nodep) {
    Node node = nodep;
    final AnchorNode an = (AnchorNode)node;
    final int anchorType = an.type;
    Node head = an.target;
    Node np = ((ConsAltNode)head).car;

    swap(node, head);

    final Node tmp = node;
    node = head;
    head = tmp;

    ((ConsAltNode)node).setCar(head);
    ((AnchorNode)head).setTarget(np);
    np = node;

    while ((np = ((ConsAltNode)np).cdr) != null) {
        final AnchorNode insert = new AnchorNode(anchorType);
        insert.setTarget(((ConsAltNode)np).car);
        ((ConsAltNode)np).setCar(insert);
    }

    if (anchorType == AnchorType.LOOK_BEHIND_NOT) {
        np = node;
        do {
            ((ConsAltNode)np).toListNode(); /* alt -> list */
        } while ((np = ((ConsAltNode)np).cdr) != null);
    }

    return node;
}
 
Example #21
Source File: ArrayCompiler.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void compileAltNode(final ConsAltNode node) {
    ConsAltNode aln = node;
    int len = 0;

    do {
        len += compileLengthTree(aln.car);
        if (aln.cdr != null) {
            len += OPSize.PUSH + OPSize.JUMP;
        }
    } while ((aln = aln.cdr) != null);

    final int pos = codeLength + len;  /* goal position */

    aln = node;
    do {
        len = compileLengthTree(aln.car);
        if (aln.cdr != null) {
            addOpcodeRelAddr(OPCode.PUSH, len + OPSize.JUMP);
        }
        compileTree(aln.car);
        if (aln.cdr != null) {
            len = pos - (codeLength + OPSize.JUMP);
            addOpcodeRelAddr(OPCode.JUMP, len);
        }
    } while ((aln = aln.cdr) != null);
}
 
Example #22
Source File: ArrayCompiler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void compileAltNode(final ConsAltNode node) {
    ConsAltNode aln = node;
    int len = 0;

    do {
        len += compileLengthTree(aln.car);
        if (aln.cdr != null) {
            len += OPSize.PUSH + OPSize.JUMP;
        }
    } while ((aln = aln.cdr) != null);

    final int pos = codeLength + len;  /* goal position */

    aln = node;
    do {
        len = compileLengthTree(aln.car);
        if (aln.cdr != null) {
            addOpcodeRelAddr(OPCode.PUSH, len + OPSize.JUMP);
        }
        compileTree(aln.car);
        if (aln.cdr != null) {
            len = pos - (codeLength + OPSize.JUMP);
            addOpcodeRelAddr(OPCode.JUMP, len);
        }
    } while ((aln = aln.cdr) != null);
}
 
Example #23
Source File: Analyser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Node divideLookBehindAlternatives(final Node nodep) {
    Node node = nodep;
    final AnchorNode an = (AnchorNode)node;
    final int anchorType = an.type;
    Node head = an.target;
    Node np = ((ConsAltNode)head).car;

    swap(node, head);

    final Node tmp = node;
    node = head;
    head = tmp;

    ((ConsAltNode)node).setCar(head);
    ((AnchorNode)head).setTarget(np);
    np = node;

    while ((np = ((ConsAltNode)np).cdr) != null) {
        final AnchorNode insert = new AnchorNode(anchorType);
        insert.setTarget(((ConsAltNode)np).car);
        ((ConsAltNode)np).setCar(insert);
    }

    if (anchorType == AnchorType.LOOK_BEHIND_NOT) {
        np = node;
        do {
            ((ConsAltNode)np).toListNode(); /* alt -> list */
        } while ((np = ((ConsAltNode)np).cdr) != null);
    }

    return node;
}
 
Example #24
Source File: Analyser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkTypeTree(Node node, int typeMask, int encloseMask, int anchorMask) {
    if ((node.getType2Bit() & typeMask) == 0) return true;

    boolean invalid = false;

    switch(node.getType()) {
    case NodeType.LIST:
    case NodeType.ALT:
        ConsAltNode can = (ConsAltNode)node;
        do {
            invalid = checkTypeTree(can.car, typeMask, encloseMask, anchorMask);
        } while (!invalid && (can = can.cdr) != null);
        break;

    case NodeType.QTFR:
        invalid = checkTypeTree(((QuantifierNode)node).target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ENCLOSE:
        EncloseNode en = (EncloseNode)node;
        if ((en.type & encloseMask) == 0) return true;
        invalid = checkTypeTree(en.target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ANCHOR:
        AnchorNode an = (AnchorNode)node;
        if ((an.type & anchorMask) == 0) return true;

        if (an.target != null) invalid = checkTypeTree(an.target, typeMask, encloseMask, anchorMask);
        break;

    default:
        break;

    } // switch

    return invalid;
}
 
Example #25
Source File: Analyser.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkTypeTree(Node node, int typeMask, int encloseMask, int anchorMask) {
    if ((node.getType2Bit() & typeMask) == 0) return true;

    boolean invalid = false;

    switch(node.getType()) {
    case NodeType.LIST:
    case NodeType.ALT:
        ConsAltNode can = (ConsAltNode)node;
        do {
            invalid = checkTypeTree(can.car, typeMask, encloseMask, anchorMask);
        } while (!invalid && (can = can.cdr) != null);
        break;

    case NodeType.QTFR:
        invalid = checkTypeTree(((QuantifierNode)node).target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ENCLOSE:
        EncloseNode en = (EncloseNode)node;
        if ((en.type & encloseMask) == 0) return true;
        invalid = checkTypeTree(en.target, typeMask, encloseMask, anchorMask);
        break;

    case NodeType.ANCHOR:
        AnchorNode an = (AnchorNode)node;
        if ((an.type & anchorMask) == 0) return true;

        if (an.target != null) invalid = checkTypeTree(an.target, typeMask, encloseMask, anchorMask);
        break;

    default:
        break;

    } // switch

    return invalid;
}
 
Example #26
Source File: ArrayCompiler.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void compileAltNode(final ConsAltNode node) {
    ConsAltNode aln = node;
    int len = 0;

    do {
        len += compileLengthTree(aln.car);
        if (aln.cdr != null) {
            len += OPSize.PUSH + OPSize.JUMP;
        }
    } while ((aln = aln.cdr) != null);

    final int pos = codeLength + len;  /* goal position */

    aln = node;
    do {
        len = compileLengthTree(aln.car);
        if (aln.cdr != null) {
            addOpcodeRelAddr(OPCode.PUSH, len + OPSize.JUMP);
        }
        compileTree(aln.car);
        if (aln.cdr != null) {
            len = pos - (codeLength + OPSize.JUMP);
            addOpcodeRelAddr(OPCode.JUMP, len);
        }
    } while ((aln = aln.cdr) != null);
}
 
Example #27
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpRepeat(final Node targetp, final boolean group) {
    Node target = targetp;
    while (token.type == TokenType.OP_REPEAT || token.type == TokenType.INTERVAL) { // repeat:
        if (target.isInvalidQuantifier()) {
            throw new SyntaxException(ERR_TARGET_OF_REPEAT_OPERATOR_INVALID);
        }

        final QuantifierNode qtfr = new QuantifierNode(token.getRepeatLower(),
                                                 token.getRepeatUpper(),
                                                 token.type == TokenType.INTERVAL);

        qtfr.greedy = token.getRepeatGreedy();
        final int ret = qtfr.setQuantifier(target, group, env, chars, getBegin(), getEnd());
        Node qn = qtfr;

        if (token.getRepeatPossessive()) {
            final EncloseNode en = new EncloseNode(EncloseType.STOP_BACKTRACK); // node_new_enclose
            en.setTarget(qn);
            qn = en;
        }

        if (ret == 0) {
            target = qn;
        } else if (ret == 2) { /* split case: /abc+/ */
            target = ConsAltNode.newListNode(target, null);
            final ConsAltNode tmp = ((ConsAltNode)target).setCdr(ConsAltNode.newListNode(qn, null));

            fetchToken();
            return parseExpRepeatForCar(target, tmp, group);
        }
        fetchToken(); // goto re_entry
    }
    return target;
}
 
Example #28
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpRepeatForCar(final Node top, final ConsAltNode target, final boolean group) {
    while (token.type == TokenType.OP_REPEAT || token.type == TokenType.INTERVAL) { // repeat:
        if (target.car.isInvalidQuantifier()) {
            throw new SyntaxException(ERR_TARGET_OF_REPEAT_OPERATOR_INVALID);
        }

        final QuantifierNode qtfr = new QuantifierNode(token.getRepeatLower(),
                                                 token.getRepeatUpper(),
                                                 token.type == TokenType.INTERVAL);

        qtfr.greedy = token.getRepeatGreedy();
        final int ret = qtfr.setQuantifier(target.car, group, env, chars, getBegin(), getEnd());
        Node qn = qtfr;

        if (token.getRepeatPossessive()) {
            final EncloseNode en = new EncloseNode(EncloseType.STOP_BACKTRACK); // node_new_enclose
            en.setTarget(qn);
            qn = en;
        }

        if (ret == 0) {
            target.setCar(qn);
        } else if (ret == 2) { /* split case: /abc+/ */
            assert false;
        }
        fetchToken(); // goto re_entry
    }
    return top;
}
 
Example #29
Source File: Parser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpRepeatForCar(final Node top, final ConsAltNode target, final boolean group) {
    while (token.type == TokenType.OP_REPEAT || token.type == TokenType.INTERVAL) { // repeat:
        if (target.car.isInvalidQuantifier()) {
            throw new SyntaxException(ERR_TARGET_OF_REPEAT_OPERATOR_INVALID);
        }

        final QuantifierNode qtfr = new QuantifierNode(token.getRepeatLower(),
                                                 token.getRepeatUpper(),
                                                 token.type == TokenType.INTERVAL);

        qtfr.greedy = token.getRepeatGreedy();
        final int ret = qtfr.setQuantifier(target.car, group, env, chars, getBegin(), getEnd());
        Node qn = qtfr;

        if (token.getRepeatPossessive()) {
            final EncloseNode en = new EncloseNode(EncloseType.STOP_BACKTRACK); // node_new_enclose
            en.setTarget(qn);
            qn = en;
        }

        if (ret == 0) {
            target.setCar(qn);
        } else if (ret == 2) { /* split case: /abc+/ */
            assert false;
        }
        fetchToken(); // goto re_entry
    }
    return top;
}
 
Example #30
Source File: ArrayCompiler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void compileAltNode(final ConsAltNode node) {
    ConsAltNode aln = node;
    int len = 0;

    do {
        len += compileLengthTree(aln.car);
        if (aln.cdr != null) {
            len += OPSize.PUSH + OPSize.JUMP;
        }
    } while ((aln = aln.cdr) != null);

    final int pos = codeLength + len;  /* goal position */

    aln = node;
    do {
        len = compileLengthTree(aln.car);
        if (aln.cdr != null) {
            addOpcodeRelAddr(OPCode.PUSH, len + OPSize.JUMP);
        }
        compileTree(aln.car);
        if (aln.cdr != null) {
            len = pos - (codeLength + OPSize.JUMP);
            addOpcodeRelAddr(OPCode.JUMP, len);
        }
    } while ((aln = aln.cdr) != null);
}