/** * 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); }
def("attributeValue", ref("attributeValueDouble") .or(ref("attributeValueSingle")) .pick(1)); def("attributeValueDouble", of(DOUBLE_QUOTE) .seq(new XmlCharacterParser(DOUBLE_QUOTE, 0)) def("content", ref("characterData") .or(ref("element")) .or(ref("processing")) .or(ref("comment")) .or(ref("cdata")) .star()); def("doctype", of(OPEN_DOCTYPE) .seq(ref("space")) .seq(ref("nameToken") .or(ref("attributeValue")) .or(any() .starLazy(of(OPEN_DOCTYPE_BLOCK)) .seq(of(OPEN_DOCTYPE_BLOCK)) .seq(any().starLazy(of(CLOSE_DOCTYPE_BLOCK))) .seq(of(CLOSE_DOCTYPE_BLOCK))) .separatedBy(ref("space")) .flatten()) .seq(ref("space optional")) def("misc", ref("space") .or(ref("comment")) .or(ref("processing")) .star());
def("arrayItem", ref("literal") .or(ref("symbolLiteralArray")) .or(ref("arrayLiteralArray")) .or(ref("byteLiteralArray"))); def("arrayLiteral", token("#(") .seq(ref("arrayItem").star()) def("literal", ref("numberLiteral") .or(ref("stringLiteral")) .or(ref("charLiteral")) .or(ref("arrayLiteral")) .or(ref("byteLiteral")) .or(ref("symbolLiteral")) .or(ref("nilLiteral")) .or(ref("trueLiteral")) .or(ref("falseLiteral"))); def("message", ref("keywordMessage") .or(ref("binaryMessage")) .or(ref("unaryMessage"))); def("method", ref("methodDeclaration") .seq(ref("methodSequence"))); def("methodDeclaration", ref("keywordMethod") .or(ref("unaryMethod")) .or(ref("binaryMethod"))); def("methodSequence", ref("periodToken").star() .seq(ref("pragmas")) def("pragmaMessage", ref("keywordPragma") .or(ref("unaryPragma"))
/** * Returns a list of all successful non-overlapping parses of the {@code input}. */ @SuppressWarnings("unchecked") public <T> List<T> matchesSkipping(String input) { List<Object> list = new ArrayList<>(); this.map(list::add).or(any()).star().parse(input); return (List<T>) list; }
def("placeholder", ref("inner_placeholder").or(ref("withPrefixPlaceholder"))); def("withPrefixPlaceholder", ref("prefix_placeholder").seq(ref("inner_placeholder"))); def("chars", letter().or(digit(), anyOf("_-.+")).plus().flatten());
/** * Returns a list of all successful non-overlapping parses of the {@code input}. */ @SuppressWarnings("unchecked") public <T> List<T> matchesSkipping(String input) { List<Object> list = new ArrayList<>(); this.map(list::add).or(any()).star().parse(input); return (List<T>) list; }
def("positiveNumber", ref("scaledDecimal") .or(ref("float")) .or(ref("integer")));
/** * Returns a list of all successful overlapping parses of the {@code input}. */ @SuppressWarnings("unchecked") public <T> List<T> matches(String input) { List<Object> list = new ArrayList<>(); this.and().map(list::add).seq(any()).or(any()).star().parse(input); return (List<T>) list; }
@Override public ChoiceParser copy() { return new ChoiceParser(Arrays.copyOf(parsers, parsers.length)); } }
/** * Returns a list of all successful overlapping parses of the {@code input}. */ @SuppressWarnings("unchecked") public <T> List<T> matches(String input) { List<Object> list = new ArrayList<>(); this.and().map(list::add).seq(any()).or(any()).star().parse(input); return (List<T>) list; }
/** * 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()])); } }