/** * Returns a parser that accepts the receiver or {@code other}. The resulting parser returns the * parse result of the receiver, if the receiver fails it returns the parse result of {@code * other} (exclusive ordered choice). */ public ChoiceParser or(Parser... others) { Parser[] parsers = new Parser[1 + others.length]; parsers[0] = this; System.arraycopy(others, 0, parsers, 1, others.length); return new ChoiceParser(parsers); }
@Override public ChoiceParser copy() { return new ChoiceParser(Arrays.copyOf(parsers, parsers.length)); } }
/** * Returns a parser that accepts the receiver or {@code other}. The resulting parser returns the * parse result of the receiver, if the receiver fails it returns the parse result of {@code * other} (exclusive ordered choice). */ public ChoiceParser or(Parser... others) { Parser[] parsers = new Parser[1 + others.length]; parsers[0] = this; System.arraycopy(others, 0, parsers, 1, others.length); return new ChoiceParser(parsers); }
@Override public ChoiceParser copy() { return new ChoiceParser(Arrays.copyOf(parsers, parsers.length)); } }
@Override public ChoiceParser or(Parser... others) { Parser[] array = Arrays.copyOf(parsers, parsers.length + others.length); System.arraycopy(others, 0, array, parsers.length, others.length); return new ChoiceParser(array); }
@Override public ChoiceParser or(Parser... others) { Parser[] array = Arrays.copyOf(parsers, parsers.length + others.length); System.arraycopy(others, 0, array, parsers.length, others.length); return new ChoiceParser(array); }
private Parser buildChoice(List<Parser> parsers, Parser otherwise) { if (parsers.isEmpty()) { return otherwise; } else if (parsers.size() == 1) { return parsers.get(0); } else { return new ChoiceParser(parsers.toArray(new Parser[parsers.size()])); } }
private Parser buildChoice(List<Parser> parsers, Parser otherwise) { if (parsers.isEmpty()) { return otherwise; } else if (parsers.size() == 1) { return parsers.get(0); } else { return new ChoiceParser(parsers.toArray(new Parser[parsers.size()])); } }