Search in sources :

Example 1 with RegExpMatcher

use of com.github.anba.es6draft.regexp.RegExpMatcher in project es6draft by anba.

the class RegExpPrototype method matchOrNull.

/**
     * 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) (1)
     * 
     * @param r
     *            the regular expression object
     * @param s
     *            the string
     * @param lastIndex
     *            the lastIndex position
     * @param global
     *            the global flag
     * @param sticky
     *            the sticky flag
     * @return the match state or {@code null}
     */
private static MatchState matchOrNull(RegExpObject r, String s, int lastIndex, boolean global, boolean sticky) {
    /* step 1 */
    assert r.getRegExpMatcher() != null;
    /* step 10 */
    if (!global && !sticky) {
        lastIndex = 0;
    }
    /* step 15.a */
    if (lastIndex > s.length()) {
        return null;
    }
    /* step 11 */
    RegExpMatcher matcher = r.getRegExpMatcher();
    /* steps 12-13 (not applicable) */
    /* steps 14-15 */
    MatchState m = matcher.matcher(s);
    boolean matchSucceeded;
    if (!sticky) {
        matchSucceeded = m.find(lastIndex);
    } else {
        matchSucceeded = m.matches(lastIndex);
    }
    /* step 15.a, 15.c */
    if (!matchSucceeded) {
        return null;
    }
    return m;
}
Also used : RegExpMatcher(com.github.anba.es6draft.regexp.RegExpMatcher) MatchState(com.github.anba.es6draft.regexp.MatchState)

Example 2 with RegExpMatcher

use of com.github.anba.es6draft.regexp.RegExpMatcher in project es6draft by anba.

the class RegExpConstructor method RegExpInitialize.

private static RegExpObject RegExpInitialize(ExecutionContext cx, RegExpObject obj, String p, String f) {
    /* steps 7-10 */
    RegExpMatcher matcher;
    try {
        matcher = RegExpParser.parse(p, f, "<regexp>", 1, 1, cx.getRealm().isEnabled(CompatibilityOption.WebRegularExpressions));
    } catch (ParserException e) {
        throw e.toScriptException(cx);
    }
    /* steps 11-13 */
    obj.initialize(p, f, matcher);
    /* steps 14-15 */
    Set(cx, obj, "lastIndex", 0, true);
    /* step 16 */
    return obj;
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) RegExpMatcher(com.github.anba.es6draft.regexp.RegExpMatcher)

Aggregations

RegExpMatcher (com.github.anba.es6draft.regexp.RegExpMatcher)2 ParserException (com.github.anba.es6draft.parser.ParserException)1 MatchState (com.github.anba.es6draft.regexp.MatchState)1