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

The following examples show how to use jdk.nashorn.internal.runtime.regexp.joni.Regex. 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: JoniRegExp.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
 *
 * @param pattern RegExp pattern string
 * @param flags RegExp flag string
 * @throws ParserException if flags is invalid or pattern string has syntax error.
 */
public JoniRegExp(final String pattern, final String flags) throws ParserException {
    super(pattern, flags);

    int option = Option.SINGLELINE;

    if (this.isIgnoreCase()) {
        option |= Option.IGNORECASE;
    }
    if (this.isMultiline()) {
        option &= ~Option.SINGLELINE;
        option |= Option.NEGATE_SINGLELINE;
    }

    try {
        RegExpScanner parsed;

        try {
            parsed = RegExpScanner.scan(pattern);
        } catch (final PatternSyntaxException e) {
            // refine the exception with a better syntax error, if this
            // passes, just rethrow what we have
            Pattern.compile(pattern, 0);
            throw e;
        }

        if (parsed != null) {
            final char[] javaPattern = parsed.getJavaPattern().toCharArray();
            this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
            this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
        }
    } catch (final PatternSyntaxException | JOniException e2) {
        throwParserException("syntax", e2.getMessage());
    }
}
 
Example #2
Source File: JoniRegExp.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
 *
 * @param pattern RegExp pattern string
 * @param flags RegExp flag string
 * @throws ParserException if flags is invalid or pattern string has syntax error.
 */
public JoniRegExp(final String pattern, final String flags) throws ParserException {
    super(pattern, flags);

    int option = Option.SINGLELINE;

    if (this.isIgnoreCase()) {
        option |= Option.IGNORECASE;
    }
    if (this.isMultiline()) {
        option &= ~Option.SINGLELINE;
        option |= Option.NEGATE_SINGLELINE;
    }

    try {
        RegExpScanner parsed;

        try {
            parsed = RegExpScanner.scan(pattern);
        } catch (final PatternSyntaxException e) {
            // refine the exception with a better syntax error, if this
            // passes, just rethrow what we have
            Pattern.compile(pattern, 0);
            throw e;
        }

        if (parsed != null) {
            char[] javaPattern = parsed.getJavaPattern().toCharArray();
            this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
            this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
        }
    } catch (final PatternSyntaxException | JOniException e2) {
        throwParserException("syntax", e2.getMessage());
    }
}
 
Example #3
Source File: JoniTest.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDump() {
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpTree();
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpByteCode();
    new Regex("(abc){4,}{2,5}").dumpTree();
    new Regex("(abc){4,}{2,5}").dumpByteCode();
    new Regex("aaa|aa|bbbb|ccc").dumpTree();
    new Regex("aaa|aa|bbbb|ccc").dumpByteCode();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpTree();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpByteCode();
}
 
Example #4
Source File: JoniRegExp.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
 *
 * @param pattern RegExp pattern string
 * @param flags RegExp flag string
 * @throws ParserException if flags is invalid or pattern string has syntax error.
 */
public JoniRegExp(final String pattern, final String flags) throws ParserException {
    super(pattern, flags);

    int option = Option.SINGLELINE;

    if (this.isIgnoreCase()) {
        option |= Option.IGNORECASE;
    }
    if (this.isMultiline()) {
        option &= ~Option.SINGLELINE;
        option |= Option.NEGATE_SINGLELINE;
    }

    try {
        RegExpScanner parsed;

        try {
            parsed = RegExpScanner.scan(pattern);
        } catch (final PatternSyntaxException e) {
            // refine the exception with a better syntax error, if this
            // passes, just rethrow what we have
            Pattern.compile(pattern, 0);
            throw e;
        }

        if (parsed != null) {
            final char[] javaPattern = parsed.getJavaPattern().toCharArray();
            this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
            this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
        }
    } catch (final PatternSyntaxException | JOniException e2) {
        throwParserException("syntax", e2.getMessage());
    } catch (StackOverflowError e3) {
        throw new RuntimeException(e3);
    }
}
 
Example #5
Source File: JoniRegExp.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
 *
 * @param pattern RegExp pattern string
 * @param flags RegExp flag string
 * @throws ParserException if flags is invalid or pattern string has syntax error.
 */
public JoniRegExp(final String pattern, final String flags) throws ParserException {
    super(pattern, flags);

    int option = Option.SINGLELINE;

    if (this.isIgnoreCase()) {
        option |= Option.IGNORECASE;
    }
    if (this.isMultiline()) {
        option &= ~Option.SINGLELINE;
        option |= Option.NEGATE_SINGLELINE;
    }

    try {
        RegExpScanner parsed;

        try {
            parsed = RegExpScanner.scan(pattern);
        } catch (final PatternSyntaxException e) {
            // refine the exception with a better syntax error, if this
            // passes, just rethrow what we have
            Pattern.compile(pattern, 0);
            throw e;
        }

        if (parsed != null) {
            char[] javaPattern = parsed.getJavaPattern().toCharArray();
            this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
            this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
        }
    } catch (final PatternSyntaxException | JOniException e2) {
        throwParserException("syntax", e2.getMessage());
    }
}
 
Example #6
Source File: JoniRegExp.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
 *
 * @param pattern RegExp pattern string
 * @param flags RegExp flag string
 * @throws ParserException if flags is invalid or pattern string has syntax error.
 */
public JoniRegExp(final String pattern, final String flags) throws ParserException {
    super(pattern, flags);

    int option = Option.SINGLELINE;

    if (this.isIgnoreCase()) {
        option |= Option.IGNORECASE;
    }
    if (this.isMultiline()) {
        option &= ~Option.SINGLELINE;
        option |= Option.NEGATE_SINGLELINE;
    }

    try {
        RegExpScanner parsed;

        try {
            parsed = RegExpScanner.scan(pattern);
        } catch (final PatternSyntaxException e) {
            // refine the exception with a better syntax error, if this
            // passes, just rethrow what we have
            Pattern.compile(pattern, 0);
            throw e;
        }

        if (parsed != null) {
            char[] javaPattern = parsed.getJavaPattern().toCharArray();
            this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
            this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
        }
    } catch (final PatternSyntaxException | JOniException e2) {
        throwParserException("syntax", e2.getMessage());
    }
}
 
Example #7
Source File: JoniTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDump() {
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpTree();
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpByteCode();
    new Regex("(abc){4,}{2,5}").dumpTree();
    new Regex("(abc){4,}{2,5}").dumpByteCode();
    new Regex("aaa|aa|bbbb|ccc").dumpTree();
    new Regex("aaa|aa|bbbb|ccc").dumpByteCode();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpTree();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpByteCode();
}
 
Example #8
Source File: JoniRegExp.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
 *
 * @param pattern RegExp pattern string
 * @param flags RegExp flag string
 * @throws ParserException if flags is invalid or pattern string has syntax error.
 */
public JoniRegExp(final String pattern, final String flags) throws ParserException {
    super(pattern, flags);

    int option = Option.SINGLELINE;

    if (this.isIgnoreCase()) {
        option |= Option.IGNORECASE;
    }
    if (this.isMultiline()) {
        option &= ~Option.SINGLELINE;
        option |= Option.NEGATE_SINGLELINE;
    }

    try {
        RegExpScanner parsed;

        try {
            parsed = RegExpScanner.scan(pattern);
        } catch (final PatternSyntaxException e) {
            // refine the exception with a better syntax error, if this
            // passes, just rethrow what we have
            Pattern.compile(pattern, 0);
            throw e;
        }

        if (parsed != null) {
            final char[] javaPattern = parsed.getJavaPattern().toCharArray();
            this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
            this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
        }
    } catch (final PatternSyntaxException | JOniException e2) {
        throwParserException("syntax", e2.getMessage());
    }
}
 
Example #9
Source File: JoniTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDump() {
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpTree();
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpByteCode();
    new Regex("(abc){4,}{2,5}").dumpTree();
    new Regex("(abc){4,}{2,5}").dumpByteCode();
    new Regex("aaa|aa|bbbb|ccc").dumpTree();
    new Regex("aaa|aa|bbbb|ccc").dumpByteCode();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpTree();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpByteCode();
}
 
Example #10
Source File: JoniRegExp.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
 *
 * @param pattern RegExp pattern string
 * @param flags RegExp flag string
 * @throws ParserException if flags is invalid or pattern string has syntax error.
 */
public JoniRegExp(final String pattern, final String flags) throws ParserException {
    super(pattern, flags);

    int option = Option.SINGLELINE;

    if (this.isIgnoreCase()) {
        option |= Option.IGNORECASE;
    }
    if (this.isMultiline()) {
        option &= ~Option.SINGLELINE;
        option |= Option.NEGATE_SINGLELINE;
    }

    try {
        RegExpScanner parsed;

        try {
            parsed = RegExpScanner.scan(pattern);
        } catch (final PatternSyntaxException e) {
            // refine the exception with a better syntax error, if this
            // passes, just rethrow what we have
            Pattern.compile(pattern, 0);
            throw e;
        }

        if (parsed != null) {
            final char[] javaPattern = parsed.getJavaPattern().toCharArray();
            this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
            this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
        }
    } catch (final PatternSyntaxException | JOniException e2) {
        throwParserException("syntax", e2.getMessage());
    } catch (StackOverflowError e3) {
        throw new RuntimeException(e3);
    }
}
 
Example #11
Source File: JoniTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDump() {
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpTree();
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpByteCode();
    new Regex("(abc){4,}{2,5}").dumpTree();
    new Regex("(abc){4,}{2,5}").dumpByteCode();
    new Regex("aaa|aa|bbbb|ccc").dumpTree();
    new Regex("aaa|aa|bbbb|ccc").dumpByteCode();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpTree();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpByteCode();
}
 
Example #12
Source File: JoniRegExp.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
 *
 * @param pattern RegExp pattern string
 * @param flags RegExp flag string
 * @throws ParserException if flags is invalid or pattern string has syntax error.
 */
public JoniRegExp(final String pattern, final String flags) throws ParserException {
    super(pattern, flags);

    int option = Option.SINGLELINE;

    if (this.isIgnoreCase()) {
        option |= Option.IGNORECASE;
    }
    if (this.isMultiline()) {
        option &= ~Option.SINGLELINE;
        option |= Option.NEGATE_SINGLELINE;
    }

    try {
        RegExpScanner parsed;

        try {
            parsed = RegExpScanner.scan(pattern);
        } catch (final PatternSyntaxException e) {
            // refine the exception with a better syntax error, if this
            // passes, just rethrow what we have
            Pattern.compile(pattern, 0);
            throw e;
        }

        if (parsed != null) {
            final char[] javaPattern = parsed.getJavaPattern().toCharArray();
            this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
            this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
        }
    } catch (final PatternSyntaxException | JOniException e2) {
        throwParserException("syntax", e2.getMessage());
    }
}
 
Example #13
Source File: JoniTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDump() {
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpTree();
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpByteCode();
    new Regex("(abc){4,}{2,5}").dumpTree();
    new Regex("(abc){4,}{2,5}").dumpByteCode();
    new Regex("aaa|aa|bbbb|ccc").dumpTree();
    new Regex("aaa|aa|bbbb|ccc").dumpByteCode();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpTree();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpByteCode();
}
 
Example #14
Source File: JoniRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
 *
 * @param pattern RegExp pattern string
 * @param flags RegExp flag string
 * @throws ParserException if flags is invalid or pattern string has syntax error.
 */
public JoniRegExp(final String pattern, final String flags) throws ParserException {
    super(pattern, flags);

    int option = Option.SINGLELINE;

    if (this.isIgnoreCase()) {
        option |= Option.IGNORECASE;
    }
    if (this.isMultiline()) {
        option &= ~Option.SINGLELINE;
        option |= Option.NEGATE_SINGLELINE;
    }

    try {
        RegExpScanner parsed;

        try {
            parsed = RegExpScanner.scan(pattern);
        } catch (final PatternSyntaxException e) {
            // refine the exception with a better syntax error, if this
            // passes, just rethrow what we have
            Pattern.compile(pattern, 0);
            throw e;
        }

        if (parsed != null) {
            final char[] javaPattern = parsed.getJavaPattern().toCharArray();
            this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
            this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
        }
    } catch (final PatternSyntaxException | JOniException e2) {
        throwParserException("syntax", e2.getMessage());
    } catch (StackOverflowError e3) {
        throw new RuntimeException(e3);
    }
}
 
Example #15
Source File: JoniTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDump() {
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpTree();
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpByteCode();
    new Regex("(abc){4,}{2,5}").dumpTree();
    new Regex("(abc){4,}{2,5}").dumpByteCode();
    new Regex("aaa|aa|bbbb|ccc").dumpTree();
    new Regex("aaa|aa|bbbb|ccc").dumpByteCode();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpTree();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpByteCode();
}
 
Example #16
Source File: JoniRegExp.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
 *
 * @param pattern RegExp pattern string
 * @param flags RegExp flag string
 * @throws ParserException if flags is invalid or pattern string has syntax error.
 */
public JoniRegExp(final String pattern, final String flags) throws ParserException {
    super(pattern, flags);

    int option = Option.SINGLELINE;

    if (this.isIgnoreCase()) {
        option |= Option.IGNORECASE;
    }
    if (this.isMultiline()) {
        option &= ~Option.SINGLELINE;
        option |= Option.NEGATE_SINGLELINE;
    }

    try {
        RegExpScanner parsed;

        try {
            parsed = RegExpScanner.scan(pattern);
        } catch (final PatternSyntaxException e) {
            // refine the exception with a better syntax error, if this
            // passes, just rethrow what we have
            Pattern.compile(pattern, 0);
            throw e;
        }

        if (parsed != null) {
            final char[] javaPattern = parsed.getJavaPattern().toCharArray();
            this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
            this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
        }
    } catch (final PatternSyntaxException | JOniException e2) {
        throwParserException("syntax", e2.getMessage());
    }
}
 
Example #17
Source File: JoniTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDump() {
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpTree();
    new Regex("^a{3,}(.*)[z]++\\s\\1x$").dumpByteCode();
    new Regex("(abc){4,}{2,5}").dumpTree();
    new Regex("(abc){4,}{2,5}").dumpByteCode();
    new Regex("aaa|aa|bbbb|ccc").dumpTree();
    new Regex("aaa|aa|bbbb|ccc").dumpByteCode();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpTree();
    new Regex("(?:ZFVR.(\\d+\\.\\d+))|(?:(?:Sversbk|TenaCnenqvfb|Vprjrnfry).(\\d+\\.\\d+))|(?:Bcren.(\\d+\\.\\d+))|(?:NccyrJroXvg.(\\d+(?:\\.\\d+)?))").dumpByteCode();
}