private Matcher escape() { char c = peek(); if (c == 'Q') { return quotation(); } else if (c == 'c') { throw unsupported("control character"); } else if (Constants.DIGIT.contains(c) || c == 'k') { throw unsupported("back references"); } else { AsciiSet set = namedCharClass(); if (set == null) { advance(); return new CharSeqMatcher(String.valueOf(c)); } else { return new CharClassMatcher(set); } } }
private Matcher escape() { char c = peek(); if (c == 'Q') { return quotation(); } else if (c == 'c') { throw unsupported("control character"); } else if (Constants.DIGIT.contains(c) || c == 'k') { throw unsupported("back references"); } else { AsciiSet set = namedCharClass(); if (set == null) { advance(); return new CharSeqMatcher(String.valueOf(c)); } else { return new CharClassMatcher(set); } } }
@SuppressWarnings("PMD.MissingBreakInSwitch") private AsciiSet namedCharClass() { boolean invert = false; char c = advance(); switch (c) { case 'd': return Constants.DIGIT; case 'D': return Constants.DIGIT.invert(); case 's': return Constants.SPACE; case 'S': return Constants.SPACE.invert(); case 'w': return Constants.WORD_CHARS; case 'W': return Constants.WORD_CHARS.invert(); case 'h': case 'H': throw unsupported("horizontal whitespace class"); case 'v': case 'V': throw unsupported("vertical whitespace class"); case 'P': invert = true; case 'p': return newNamedCharSet(name(), invert); default: --current; return null; } }
@SuppressWarnings("PMD.MissingBreakInSwitch") private AsciiSet namedCharClass() { boolean invert = false; char c = advance(); switch (c) { case 'd': return Constants.DIGIT; case 'D': return Constants.DIGIT.invert(); case 's': return Constants.SPACE; case 'S': return Constants.SPACE.invert(); case 'w': return Constants.WORD_CHARS; case 'W': return Constants.WORD_CHARS.invert(); case 'h': case 'H': throw unsupported("horizontal whitespace class"); case 'v': case 'V': throw unsupported("vertical whitespace class"); case 'P': invert = true; case 'p': return newNamedCharSet(name(), invert); default: --current; return null; } }
private Matcher group() { if (peek() == '?') { advance(); char c = advance(); switch (c) { case '<': // Named capturing group advance(v -> v != '>'); if (isAtEnd()) { throw error("unclosed name for capturing group"); } return groupExpr(); case ':': // Non-capturing group return groupExpr(); case '=': return new PositiveLookaheadMatcher(expr()); case '!': return new NegativeLookaheadMatcher(expr()); default: throw unsupported("inline flags"); } } else { return groupExpr(); } }
private Matcher group() { if (peek() == '?') { advance(); char c = advance(); switch (c) { case '<': // Named capturing group advance(v -> v != '>'); if (isAtEnd()) { throw error("unclosed name for capturing group"); } return groupExpr(); case ':': // Non-capturing group return groupExpr(); case '=': return new PositiveLookaheadMatcher(expr()); case '!': return new NegativeLookaheadMatcher(expr()); default: throw unsupported("inline flags"); } } else { return groupExpr(); } }