/** * A scanner for a quoted string that starts with {@code begin} and ends with {@code end}. * * @param begin begins a quote * @param end ends a quote * @param quoted the parser that recognizes the quoted pattern. * @return the scanner. * @deprecated Use {@code Parsers.sequence(begin, quoted.skipMany(), end).source()}. */ @Deprecated public static Parser<String> quoted(Parser<Void> begin, Parser<Void> end, Parser<?> quoted) { return Parsers.sequence(begin, quoted.skipMany(), end).source(); }
/** * A scanner for a quoted string that starts with character {@code begin} and ends with character * {@code end}. */ public static Parser<String> quoted(char begin, char end) { Pattern beforeClosingQuote = Patterns.isChar(begin).next(Patterns.many(CharPredicates.notChar(end))); return beforeClosingQuote.toScanner(Character.toString(begin)).next(isChar(end)).source(); }
/** * A {@link Parser} that succeeds only if the {@link Token} objects in the {@link List} are * adjacent. */ public static Parser<Token> adjacent(Parser<List<Token>> parser, final Parser<?> otherwise) { return parser.next(tokens -> { if (tokens.isEmpty()) return Parsers.always(); int offset = tokens.get(0).index(); for (Token token : tokens) { if (token.index() != offset) { return otherwise; } offset += token.length(); } return Parsers.always(); }).atomic().source().token(); }