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

The following examples show how to use jdk.nashorn.internal.runtime.regexp.joni.ast.Node. 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 hottub 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 jdk8u_nashorn 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 #3
Source File: Parser.java    From openjdk-jdk8u 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: Analyser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private Node setupLookBehind(final Node node) {
    final AnchorNode an = (AnchorNode)node;
    final int len = getCharLengthTree(an.target);
    switch (returnCode) {
    case 0:
        an.charLength = len;
        break;
    case GET_CHAR_LEN_VARLEN:
        throw new SyntaxException(ERR_INVALID_LOOK_BEHIND_PATTERN);
    case GET_CHAR_LEN_TOP_ALT_VARLEN:
        if (syntax.differentLengthAltLookBehind()) {
            return divideLookBehindAlternatives(node);
        }
        throw new SyntaxException(ERR_INVALID_LOOK_BEHIND_PATTERN);
    default:
        break;
    }
    return node;
}
 
Example #5
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 #6
Source File: ArrayCompiler.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private int compileLengthStringNode(Node node) {
    StringNode sn = (StringNode)node;
    if (sn.length() <= 0) return 0;
    boolean ambig = sn.isAmbig();

    int p, prev;
    p = prev = sn.p;
    int end = sn.end;
    char[] chars = sn.chars;
    p++;

    int slen = 1;
    int rlen = 0;

    while (p < end) {
        slen++;
        p++;
    }
    int r = addCompileStringlength(chars, prev, slen, ambig);
    rlen += r;
    return rlen;
}
 
Example #7
Source File: ArrayCompiler.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static int compileLengthStringNode(final Node node) {
    final StringNode sn = (StringNode)node;
    if (sn.length() <= 0) {
        return 0;
    }
    final boolean ambig = sn.isAmbig();

    int p, prev;
    p = prev = sn.p;
    final int end = sn.end;
    final char[] chars = sn.chars;
    p++;

    int slen = 1;
    int rlen = 0;

    while (p < end) {
        slen++;
        p++;
    }
    final int r = addCompileStringlength(chars, prev, slen, ambig);
    rlen += r;
    return rlen;
}
 
Example #8
Source File: ArrayCompiler.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
private static int compileLengthStringNode(final Node node) {
    final StringNode sn = (StringNode)node;
    if (sn.length() <= 0) {
        return 0;
    }
    final boolean ambig = sn.isAmbig();

    int p, prev;
    p = prev = sn.p;
    final int end = sn.end;
    final char[] chars = sn.chars;
    p++;

    int slen = 1;
    int rlen = 0;

    while (p < end) {
        slen++;
        p++;
    }
    final int r = addCompileStringlength(chars, prev, slen, ambig);
    rlen += r;
    return rlen;
}
 
Example #9
Source File: Analyser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private Node setupLookBehind(Node node) {
    AnchorNode an = (AnchorNode)node;
    int len = getCharLengthTree(an.target);
    switch(returnCode) {
    case 0:
        an.charLength = len;
        break;
    case GET_CHAR_LEN_VARLEN:
        throw new SyntaxException(ERR_INVALID_LOOK_BEHIND_PATTERN);
    case GET_CHAR_LEN_TOP_ALT_VARLEN:
        if (syntax.differentLengthAltLookBehind()) {
            return divideLookBehindAlternatives(node);
        } else {
            throw new SyntaxException(ERR_INVALID_LOOK_BEHIND_PATTERN);
        }
    }
    return node;
}
 
Example #10
Source File: ArrayCompiler.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private int compileLengthStringNode(Node node) {
    StringNode sn = (StringNode)node;
    if (sn.length() <= 0) return 0;
    boolean ambig = sn.isAmbig();

    int p, prev;
    p = prev = sn.p;
    int end = sn.end;
    char[] chars = sn.chars;
    p++;

    int slen = 1;
    int rlen = 0;

    while (p < end) {
        slen++;
        p++;
    }
    int r = addCompileStringlength(chars, prev, slen, ambig);
    rlen += r;
    return rlen;
}
 
Example #11
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
private Node parseExpTkByte(final boolean group) {
    final StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) {
            break;
        }

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example #12
Source File: ArrayCompiler.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static int compileLengthStringNode(final Node node) {
    final StringNode sn = (StringNode)node;
    if (sn.length() <= 0) {
        return 0;
    }
    final boolean ambig = sn.isAmbig();

    int p, prev;
    p = prev = sn.p;
    final int end = sn.end;
    final char[] chars = sn.chars;
    p++;

    int slen = 1;
    int rlen = 0;

    while (p < end) {
        slen++;
        p++;
    }
    final int r = addCompileStringlength(chars, prev, slen, ambig);
    rlen += r;
    return rlen;
}
 
Example #13
Source File: Analyser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Node setupLookBehind(final Node node) {
    final AnchorNode an = (AnchorNode)node;
    final int len = getCharLengthTree(an.target);
    switch (returnCode) {
    case 0:
        an.charLength = len;
        break;
    case GET_CHAR_LEN_VARLEN:
        throw new SyntaxException(ERR_INVALID_LOOK_BEHIND_PATTERN);
    case GET_CHAR_LEN_TOP_ALT_VARLEN:
        if (syntax.differentLengthAltLookBehind()) {
            return divideLookBehindAlternatives(node);
        }
        throw new SyntaxException(ERR_INVALID_LOOK_BEHIND_PATTERN);
    default:
        break;
    }
    return node;
}
 
Example #14
Source File: ScanEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public int addMemEntry() {
    if (numMem++ == 0) {
        memNodes = new Node[SCANENV_MEMNODES_SIZE];
    } else if (numMem >= memNodes.length) {
        final Node[]tmp = new Node[memNodes.length << 1];
        System.arraycopy(memNodes, 0, tmp, 0, memNodes.length);
        memNodes = tmp;
    }

    return numMem;
}
 
Example #15
Source File: Parser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpTkRawByte(final boolean group) {
    // tk_raw_byte:

    // important: we don't use 0xff mask here neither in the compiler
    // (in the template string) so we won't have to mask target
    // strings when comparing against them in the matcher
    final StringNode node = new StringNode((char)token.getC());
    node.setRaw();

    fetchToken();
    node.clearRaw();
    // !goto string_end;!
    return parseExpRepeat(node, group);
}
 
Example #16
Source File: Analyser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void swap(final Node a, final Node b) {
    a.swap(b);

    if (root == b) {
        root = a;
    } else if (root == a) {
        root = b;
    }
}
 
Example #17
Source File: ScanEnvironment.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void setMemNode(final int num, final Node node) {
    if (numMem >= num) {
        memNodes[num] = node;
    } else {
        throw new InternalException(ErrorMessages.ERR_PARSER_BUG);
    }
}
 
Example #18
Source File: ScanEnvironment.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
public void setMemNode(int num, Node node) {
    if (numMem >= num) {
        memNodes[num] = node;
    } else {
        throw new InternalException(ErrorMessages.ERR_PARSER_BUG);
    }
}
 
Example #19
Source File: ScanEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public int addMemEntry() {
    if (numMem++ == 0) {
        memNodes = new Node[SCANENV_MEMNODES_SIZE];
    } else if (numMem >= memNodes.length) {
        Node[]tmp = new Node[memNodes.length << 1];
        System.arraycopy(memNodes, 0, tmp, 0, memNodes.length);
        memNodes = tmp;
    }

    return numMem;
}
 
Example #20
Source File: Analyser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void swap(final Node a, final Node b) {
    a.swap(b);

    if (root == b) {
        root = a;
    } else if (root == a) {
        root = b;
    }
}
 
Example #21
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpTkRawByte(final boolean group) {
    // tk_raw_byte:

    // important: we don't use 0xff mask here neither in the compiler
    // (in the template string) so we won't have to mask target
    // strings when comparing against them in the matcher
    final StringNode node = new StringNode((char)token.getC());
    node.setRaw();

    fetchToken();
    node.clearRaw();
    // !goto string_end;!
    return parseExpRepeat(node, group);
}
 
Example #22
Source File: Parser.java    From jdk8u60 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 #23
Source File: ScanEnvironment.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
public int addMemEntry() {
    if (numMem >= Config.MAX_CAPTURE_GROUP_NUM) {
        throw new InternalException(ErrorMessages.ERR_TOO_MANY_CAPTURE_GROUPS);
    }
    if (numMem++ == 0) {
        memNodes = new Node[SCANENV_MEMNODES_SIZE];
    } else if (numMem >= memNodes.length) {
        final Node[]tmp = new Node[memNodes.length << 1];
        System.arraycopy(memNodes, 0, tmp, 0, memNodes.length);
        memNodes = tmp;
    }

    return numMem;
}
 
Example #24
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpTkByte(boolean group) {
    StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) break;

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example #25
Source File: ScanEnvironment.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public int addMemEntry() {
    if (numMem >= Config.MAX_CAPTURE_GROUP_NUM) {
        throw new InternalException(ErrorMessages.ERR_TOO_MANY_CAPTURE_GROUPS);
    }
    if (numMem++ == 0) {
        memNodes = new Node[SCANENV_MEMNODES_SIZE];
    } else if (numMem >= memNodes.length) {
        final Node[]tmp = new Node[memNodes.length << 1];
        System.arraycopy(memNodes, 0, tmp, 0, memNodes.length);
        memNodes = tmp;
    }

    return numMem;
}
 
Example #26
Source File: Analyser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void swap(final Node a, final Node b) {
    a.swap(b);

    if (root == b) {
        root = a;
    } else if (root == a) {
        root = b;
    }
}
 
Example #27
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 #28
Source File: Parser.java    From openjdk-jdk9 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 #29
Source File: Analyser.java    From jdk8u60 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 #30
Source File: Analyser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void swap(Node a, Node b) {
    a.swap(b);

    if (root == b) {
        root = a;
    } else if (root == a) {
        root = b;
    }
}