예제 #1
0
 /**
  * Returns a parser that produces the given stream of characters or fails otherwise.
  *
  * @param missing The error if the producing stream could not supply more characters.
  * @param sat The error if a character was produced that is not the given stream of characters.
  * @param cs The stream of characters to produce.
  * @return A parser that produces the given stream of characters or fails otherwise.
  */
 public static <E> Parser<Stream<Character>, Stream<Character>, E> characters(
     final F0<E> missing, final F<Character, E> sat, final Stream<Character> cs) {
   return cs.isEmpty()
       ? Parser.<Stream<Character>, Stream<Character>, E>value(Stream.<Character>nil())
       : character(missing, sat, cs.head())
           .bind(characters(missing, sat, cs.tail()._1()), Stream.<Character>cons_());
 }
예제 #2
0
 /**
  * Splits this lazy string by characters matching the given predicate.
  *
  * @param p A predicate that matches characters to be considered delimiters.
  * @return A stream of the substrings in this lazy string, when separated by the given predicate.
  */
 public Stream<LazyString> split(final F<Character, Boolean> p) {
   final Stream<Character> findIt = s.dropWhile(p);
   final P2<Stream<Character>, Stream<Character>> ws = findIt.split(p);
   return findIt.isEmpty()
       ? Stream.<LazyString>nil()
       : Stream.cons(
           fromStream(ws._1()),
           new P1<Stream<LazyString>>() {
             public Stream<LazyString> _1() {
               return fromStream(ws._2()).split(p);
             }
           });
 }
예제 #3
0
 /**
  * Returns a parser that produces the given number of characters, or fails with the given error.
  *
  * @param missing The error if the given number of characters is unavailable.
  * @param n The number of characters to produce in the parse result.
  * @return A parser that produces the given number of characters, or fails with the given error.
  */
 public static <E> Parser<Stream<Character>, Stream<Character>, E> characters(
     final F0<E> missing, final int n) {
   return n <= 0
       ? Parser.<Stream<Character>, Stream<Character>, E>value(Stream.<Character>nil())
       : character(missing).bind(characters(missing, n - 1), Stream.<Character>cons_());
 }
예제 #4
0
 /**
  * Returns a parser that repeats application of this parser zero or many times.
  *
  * @return A parser that repeats application of this parser zero or many times.
  */
 public Parser<I, Stream<A>, E> repeat() {
   return repeat1().or(() -> value(Stream.<A>nil()));
 }