jdk.nashorn.internal.runtime.regexp.joni.ScanEnvironment Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.regexp.joni.ScanEnvironment. 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: BackRefNode.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public BackRefNode(final int backRef, final ScanEnvironment env) {
    this.backRef = backRef;

    if (backRef <= env.numMem && env.memNodes[backRef] == null) {
        setRecursion(); /* /...(\1).../ */
    }
}
 
Example #2
Source File: BackRefNode.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public BackRefNode(final int backRef, final ScanEnvironment env) {
    this.backRef = backRef;

    if (backRef <= env.numMem && env.memNodes[backRef] == null) {
        setRecursion(); /* /...(\1).../ */
    }
}
 
Example #3
Source File: CClassNode.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void nextStateClass(final CCStateArg arg, final ScanEnvironment env) {
    if (arg.state == CCSTATE.RANGE) {
        throw new SyntaxException(ErrorMessages.ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE);
    }

    if (arg.state == CCSTATE.VALUE && arg.type != CCVALTYPE.CLASS) {
        if (arg.type == CCVALTYPE.SB) {
            bs.set(arg.vs);
        } else if (arg.type == CCVALTYPE.CODE_POINT) {
            addCodeRange(env, arg.vs, arg.vs);
        }
    }
    arg.state = CCSTATE.VALUE;
    arg.type = CCVALTYPE.CLASS;
}
 
Example #4
Source File: CClassNode.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void nextStateClass(final CCStateArg arg, final ScanEnvironment env) {
    if (arg.state == CCSTATE.RANGE) {
        throw new SyntaxException(ErrorMessages.ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE);
    }

    if (arg.state == CCSTATE.VALUE && arg.type != CCVALTYPE.CLASS) {
        if (arg.type == CCVALTYPE.SB) {
            bs.set(arg.vs);
        } else if (arg.type == CCVALTYPE.CODE_POINT) {
            addCodeRange(env, arg.vs, arg.vs);
        }
    }
    arg.state = CCSTATE.VALUE;
    arg.type = CCVALTYPE.CLASS;
}
 
Example #5
Source File: BackRefNode.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public BackRefNode(final int backRef, final ScanEnvironment env) {
    this.backRef = backRef;

    if (backRef <= env.numMem && env.memNodes[backRef] == null) {
        setRecursion(); /* /...(\1).../ */
    }
}
 
Example #6
Source File: BackRefNode.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public BackRefNode(int backRef, ScanEnvironment env) {
    this.backRef = backRef;

    if (backRef <= env.numMem && env.memNodes[backRef] == null) {
        setRecursion(); /* /...(\1).../ */
    }
}
 
Example #7
Source File: CClassNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void nextStateClass(final CCStateArg arg, final ScanEnvironment env) {
    if (arg.state == CCSTATE.RANGE) {
        throw new SyntaxException(ErrorMessages.ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE);
    }

    if (arg.state == CCSTATE.VALUE && arg.type != CCVALTYPE.CLASS) {
        if (arg.type == CCVALTYPE.SB) {
            bs.set(arg.vs);
        } else if (arg.type == CCVALTYPE.CODE_POINT) {
            addCodeRange(env, arg.vs, arg.vs);
        }
    }
    arg.state = CCSTATE.VALUE;
    arg.type = CCVALTYPE.CLASS;
}
 
Example #8
Source File: BackRefNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public BackRefNode(final int backRef, final ScanEnvironment env) {
    this.backRef = backRef;

    if (backRef <= env.numMem && env.memNodes[backRef] == null) {
        setRecursion(); /* /...(\1).../ */
    }
}
 
Example #9
Source File: BackRefNode.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public BackRefNode(int backRef, ScanEnvironment env) {
    this.backRef = backRef;

    if (backRef <= env.numMem && env.memNodes[backRef] == null) {
        setRecursion(); /* /...(\1).../ */
    }
}
 
Example #10
Source File: CClassNode.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void nextStateClass(final CCStateArg arg, final ScanEnvironment env) {
    if (arg.state == CCSTATE.RANGE) {
        throw new SyntaxException(ErrorMessages.ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE);
    }

    if (arg.state == CCSTATE.VALUE && arg.type != CCVALTYPE.CLASS) {
        if (arg.type == CCVALTYPE.SB) {
            bs.set(arg.vs);
        } else if (arg.type == CCVALTYPE.CODE_POINT) {
            addCodeRange(env, arg.vs, arg.vs);
        }
    }
    arg.state = CCSTATE.VALUE;
    arg.type = CCVALTYPE.CLASS;
}
 
Example #11
Source File: BackRefNode.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
public BackRefNode(final int backRef, final ScanEnvironment env) {
    this.backRef = backRef;

    if (backRef <= env.numMem && env.memNodes[backRef] == null) {
        setRecursion(); /* /...(\1).../ */
    }
}
 
Example #12
Source File: BackRefNode.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public BackRefNode(final int backRef, final ScanEnvironment env) {
    this.backRef = backRef;

    if (backRef <= env.numMem && env.memNodes[backRef] == null) {
        setRecursion(); /* /...(\1).../ */
    }
}
 
Example #13
Source File: CClassNode.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
public void nextStateClass(final CCStateArg arg, final ScanEnvironment env) {
    if (arg.state == CCSTATE.RANGE) {
        throw new SyntaxException(ErrorMessages.ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE);
    }

    if (arg.state == CCSTATE.VALUE && arg.type != CCVALTYPE.CLASS) {
        if (arg.type == CCVALTYPE.SB) {
            bs.set(arg.vs);
        } else if (arg.type == CCVALTYPE.CODE_POINT) {
            addCodeRange(env, arg.vs, arg.vs);
        }
    }
    arg.state = CCSTATE.VALUE;
    arg.type = CCVALTYPE.CLASS;
}
 
Example #14
Source File: CClassNode.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void nextStateClass(final CCStateArg arg, final ScanEnvironment env) {
    if (arg.state == CCSTATE.RANGE) {
        throw new SyntaxException(ErrorMessages.ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE);
    }

    if (arg.state == CCSTATE.VALUE && arg.type != CCVALTYPE.CLASS) {
        if (arg.type == CCVALTYPE.SB) {
            bs.set(arg.vs);
        } else if (arg.type == CCVALTYPE.CODE_POINT) {
            addCodeRange(env, arg.vs, arg.vs);
        }
    }
    arg.state = CCSTATE.VALUE;
    arg.type = CCVALTYPE.CLASS;
}
 
Example #15
Source File: BackRefNode.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public BackRefNode(final int backRef, final ScanEnvironment env) {
    this.backRef = backRef;

    if (backRef <= env.numMem && env.memNodes[backRef] == null) {
        setRecursion(); /* /...(\1).../ */
    }
}
 
Example #16
Source File: BackRefNode.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
public BackRefNode(int backRef, ScanEnvironment env) {
    this.backRef = backRef;

    if (backRef <= env.numMem && env.memNodes[backRef] == null) {
        setRecursion(); /* /...(\1).../ */
    }
}
 
Example #17
Source File: CClassNode.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void nextStateClass(final CCStateArg arg, final ScanEnvironment env) {
    if (arg.state == CCSTATE.RANGE) {
        throw new SyntaxException(ErrorMessages.ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE);
    }

    if (arg.state == CCSTATE.VALUE && arg.type != CCVALTYPE.CLASS) {
        if (arg.type == CCVALTYPE.SB) {
            bs.set(arg.vs);
        } else if (arg.type == CCVALTYPE.CODE_POINT) {
            addCodeRange(env, arg.vs, arg.vs);
        }
    }
    arg.state = CCSTATE.VALUE;
    arg.type = CCVALTYPE.CLASS;
}
 
Example #18
Source File: CClassNode.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
public void addCodeRange(final ScanEnvironment env, final int from, final int to) {
    mbuf = CodeRangeBuffer.addCodeRange(mbuf, env, from, to);
}
 
Example #19
Source File: QuantifierNode.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(Node tgt, boolean group, ScanEnvironment env, char[] chars, int p, int end) {
    if (lower == 1 && upper == 1) return 1;

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        QuantifierNode qnt = (QuantifierNode)tgt;
        int nestQNum = popularNum();
        int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #20
Source File: QuantifierNode.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(Node tgt, boolean group, ScanEnvironment env, char[] chars, int p, int end) {
    if (lower == 1 && upper == 1) return 1;

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        QuantifierNode qnt = (QuantifierNode)tgt;
        int nestQNum = popularNum();
        int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #21
Source File: CClassNode.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
public void nextStateValue(final CCStateArg arg, final ScanEnvironment env) {

        switch(arg.state) {
        case VALUE:
            if (arg.type == CCVALTYPE.SB) {
                if (arg.vs > 0xff) {
                    throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE);
                }
                bs.set(arg.vs);
            } else if (arg.type == CCVALTYPE.CODE_POINT) {
                addCodeRange(env, arg.vs, arg.vs);
            }
            break;

        case RANGE:
            if (arg.inType == arg.type) {
                if (arg.inType == CCVALTYPE.SB) {
                    if (arg.vs > 0xff || arg.v > 0xff) {
                        throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE);
                    }

                    if (arg.vs > arg.v) {
                        if (env.syntax.allowEmptyRangeInCC()) {
                            // goto ccs_range_end
                            arg.state = CCSTATE.COMPLETE;
                            break;
                        }
                        throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS);
                    }
                    bs.setRange(arg.vs, arg.v);
                } else {
                    addCodeRange(env, arg.vs, arg.v);
                }
            } else {
                if (arg.vs > arg.v) {
                    if (env.syntax.allowEmptyRangeInCC()) {
                        // goto ccs_range_end
                        arg.state = CCSTATE.COMPLETE;
                        break;
                    }
                    throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS);
                }
                bs.setRange(arg.vs, arg.v < 0xff ? arg.v : 0xff);
                addCodeRange(env, arg.vs, arg.v);
            }
            // ccs_range_end:
            arg.state = CCSTATE.COMPLETE;
            break;

        case COMPLETE:
        case START:
            arg.state = CCSTATE.VALUE;
            break;

        default:
            break;

        } // switch

        arg.vsIsRaw = arg.vIsRaw;
        arg.vs = arg.v;
        arg.type = arg.inType;
    }
 
Example #22
Source File: QuantifierNode.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(final Node tgt, final boolean group, final ScanEnvironment env, final char[] chars, final int p, final int end) {
    if (lower == 1 && upper == 1) {
        return 1;
    }

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            final StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                final StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        final QuantifierNode qnt = (QuantifierNode)tgt;
        final int nestQNum = popularNum();
        final int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #23
Source File: QuantifierNode.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(final Node tgt, final boolean group, final ScanEnvironment env, final char[] chars, final int p, final int end) {
    if (lower == 1 && upper == 1) {
        return 1;
    }

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            final StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                final StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        final QuantifierNode qnt = (QuantifierNode)tgt;
        final int nestQNum = popularNum();
        final int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #24
Source File: CClassNode.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void nextStateValue(final CCStateArg arg, final ScanEnvironment env) {

        switch(arg.state) {
        case VALUE:
            if (arg.type == CCVALTYPE.SB) {
                if (arg.vs > 0xff) {
                    throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE);
                }
                bs.set(arg.vs);
            } else if (arg.type == CCVALTYPE.CODE_POINT) {
                addCodeRange(env, arg.vs, arg.vs);
            }
            break;

        case RANGE:
            if (arg.inType == arg.type) {
                if (arg.inType == CCVALTYPE.SB) {
                    if (arg.vs > 0xff || arg.v > 0xff) {
                        throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE);
                    }

                    if (arg.vs > arg.v) {
                        if (env.syntax.allowEmptyRangeInCC()) {
                            // goto ccs_range_end
                            arg.state = CCSTATE.COMPLETE;
                            break;
                        }
                        throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS);
                    }
                    bs.setRange(arg.vs, arg.v);
                } else {
                    addCodeRange(env, arg.vs, arg.v);
                }
            } else {
                if (arg.vs > arg.v) {
                    if (env.syntax.allowEmptyRangeInCC()) {
                        // goto ccs_range_end
                        arg.state = CCSTATE.COMPLETE;
                        break;
                    }
                    throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS);
                }
                bs.setRange(arg.vs, arg.v < 0xff ? arg.v : 0xff);
                addCodeRange(env, arg.vs, arg.v);
            }
            // ccs_range_end:
            arg.state = CCSTATE.COMPLETE;
            break;

        case COMPLETE:
        case START:
            arg.state = CCSTATE.VALUE;
            break;

        default:
            break;

        } // switch

        arg.vsIsRaw = arg.vIsRaw;
        arg.vs = arg.v;
        arg.type = arg.inType;
    }
 
Example #25
Source File: CClassNode.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void addCodeRange(final ScanEnvironment env, final int from, final int to) {
    mbuf = CodeRangeBuffer.addCodeRange(mbuf, env, from, to);
}
 
Example #26
Source File: QuantifierNode.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(Node tgt, boolean group, ScanEnvironment env, char[] chars, int p, int end) {
    if (lower == 1 && upper == 1) return 1;

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        QuantifierNode qnt = (QuantifierNode)tgt;
        int nestQNum = popularNum();
        int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #27
Source File: QuantifierNode.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(final Node tgt, final boolean group, final ScanEnvironment env, final char[] chars, final int p, final int end) {
    if (lower == 1 && upper == 1) {
        return 1;
    }

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            final StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                final StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        final QuantifierNode qnt = (QuantifierNode)tgt;
        final int nestQNum = popularNum();
        final int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}
 
Example #28
Source File: CClassNode.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void nextStateValue(final CCStateArg arg, final ScanEnvironment env) {

        switch(arg.state) {
        case VALUE:
            if (arg.type == CCVALTYPE.SB) {
                if (arg.vs > 0xff) {
                    throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE);
                }
                bs.set(arg.vs);
            } else if (arg.type == CCVALTYPE.CODE_POINT) {
                addCodeRange(env, arg.vs, arg.vs);
            }
            break;

        case RANGE:
            if (arg.inType == arg.type) {
                if (arg.inType == CCVALTYPE.SB) {
                    if (arg.vs > 0xff || arg.v > 0xff) {
                        throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE);
                    }

                    if (arg.vs > arg.v) {
                        if (env.syntax.allowEmptyRangeInCC()) {
                            // goto ccs_range_end
                            arg.state = CCSTATE.COMPLETE;
                            break;
                        }
                        throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS);
                    }
                    bs.setRange(arg.vs, arg.v);
                } else {
                    addCodeRange(env, arg.vs, arg.v);
                }
            } else {
                if (arg.vs > arg.v) {
                    if (env.syntax.allowEmptyRangeInCC()) {
                        // goto ccs_range_end
                        arg.state = CCSTATE.COMPLETE;
                        break;
                    }
                    throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS);
                }
                bs.setRange(arg.vs, arg.v < 0xff ? arg.v : 0xff);
                addCodeRange(env, arg.vs, arg.v);
            }
            // ccs_range_end:
            arg.state = CCSTATE.COMPLETE;
            break;

        case COMPLETE:
        case START:
            arg.state = CCSTATE.VALUE;
            break;

        default:
            break;

        } // switch

        arg.vsIsRaw = arg.vIsRaw;
        arg.vs = arg.v;
        arg.type = arg.inType;
    }
 
Example #29
Source File: CClassNode.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void addCodeRange(final ScanEnvironment env, final int from, final int to) {
    mbuf = CodeRangeBuffer.addCodeRange(mbuf, env, from, to);
}
 
Example #30
Source File: QuantifierNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
public int setQuantifier(final Node tgt, final boolean group, final ScanEnvironment env, final char[] chars, final int p, final int end) {
    if (lower == 1 && upper == 1) {
        return 1;
    }

    switch(tgt.getType()) {

    case STR:
        if (!group) {
            final StringNode sn = (StringNode)tgt;
            if (sn.canBeSplit()) {
                final StringNode n = sn.splitLastChar();
                if (n != null) {
                    setTarget(n);
                    return 2;
                }
            }
        }
        break;

    case QTFR:
        /* check redundant double repeat. */
        /* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
        final QuantifierNode qnt = (QuantifierNode)tgt;
        final int nestQNum = popularNum();
        final int targetQNum = qnt.popularNum();

        if (Config.USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR) {
            if (!isByNumber() && !qnt.isByNumber() && env.syntax.warnReduntantNestedRepeat()) {
                switch(REDUCE_TABLE[targetQNum][nestQNum]) {
                case ASIS:
                    break;

                case DEL:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " redundant nested repeat operator");
                    break;

                default:
                    env.reg.getWarnings().warn(new String(chars, p, end) +
                            " nested repeat operator " + PopularQStr[targetQNum] +
                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
                }
            }
        } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR

        if (targetQNum >= 0) {
            if (nestQNum >= 0) {
                reduceNestedQuantifier(qnt);
                return 0;
            } else if (targetQNum == 1 || targetQNum == 2) { /* * or + */
                /* (?:a*){n,m}, (?:a+){n,m} => (?:a*){n,n}, (?:a+){n,n} */
                if (!isRepeatInfinite(upper) && upper > 1 && greedy) {
                    upper = lower == 0 ? 1 : lower;
                }
            }
        }

    default:
        break;
    }

    setTarget(tgt);
    return 0;
}