@Override public Matcher rewriteEnd(Function<Matcher, Matcher> f) { return new RepeatMatcher(f.apply(repeated), min, max); }
@Override public Matcher rewrite(Function<Matcher, Matcher> f) { return new RepeatMatcher(f.apply(repeated), min, max); }
@Override public Matcher rewrite(Function<Matcher, Matcher> f) { return new RepeatMatcher(f.apply(repeated), min, max); }
@Override public Matcher rewriteEnd(Function<Matcher, Matcher> f) { return new RepeatMatcher(f.apply(repeated), min, max); }
private Matcher repeat(Matcher matcher) { int start = current; advance(c -> c != '}'); String[] numbers = tokens.subSequence(start, current - 1).toString().split(","); int min = Integer.parseInt(numbers[0]); int max = (numbers.length > 1) ? Integer.parseInt(numbers[1]) : min; return new RepeatMatcher(matcher, min, max); }
private Matcher repeat(Matcher matcher) { int start = current; advance(c -> c != '}'); String[] numbers = tokens.subSequence(start, current - 1).toString().split(","); int min = Integer.parseInt(numbers[0]); int max = (numbers.length > 1) ? Integer.parseInt(numbers[1]) : min; return new RepeatMatcher(matcher, min, max); }
private Matcher meta(Matcher matcher) { int start = current - 1; advance(c -> META.contains((char) c)); --current; String quantifier = tokens.subSequence(start, current).toString(); switch (quantifier) { case "?": // Makes repeat reluctant if (matcher instanceof RepeatMatcher) { return matcher; } case "??": case "?+": return OrMatcher.create(matcher, TrueMatcher.INSTANCE); case "*": case "*?": return new ZeroOrMoreMatcher(matcher, term()); case "*+": return new RepeatMatcher(matcher, 0, Integer.MAX_VALUE); case "+": case "+?": return SeqMatcher.create(matcher, new ZeroOrMoreMatcher(matcher, term())); case "++": return SeqMatcher.create(matcher, new RepeatMatcher(matcher, 1, Integer.MAX_VALUE)); default: throw new IllegalArgumentException("unknown quantifier: " + quantifier); } }
private Matcher meta(Matcher matcher) { int start = current - 1; advance(c -> META.contains((char) c)); --current; String quantifier = tokens.subSequence(start, current).toString(); switch (quantifier) { case "?": // Makes repeat reluctant if (matcher instanceof RepeatMatcher) { return matcher; } case "??": case "?+": return OrMatcher.create(matcher, TrueMatcher.INSTANCE); case "*": case "*?": return new ZeroOrMoreMatcher(matcher, term()); case "*+": return new RepeatMatcher(matcher, 0, Integer.MAX_VALUE); case "+": case "+?": return SeqMatcher.create(matcher, new ZeroOrMoreMatcher(matcher, term())); case "++": return SeqMatcher.create(matcher, new RepeatMatcher(matcher, 1, Integer.MAX_VALUE)); default: throw new IllegalArgumentException("unknown quantifier: " + quantifier); } }