package tools;

/** Trait for parsers that support a check combinator. */
trait AdditionalParsers extends Parsers {

  /** Does the expected string occur in the input? */
  def check[a](expected: String): Parser[Unit];

  /** Parse an optional list of p items, separated by sep,
   *  returning a list of the generated ASTs. */
  def separatedList[a](p: Parser[a], sep: String): Parser[List[a]] =
    mandatorySeparatedList(p, sep) ||| succeed(List());
    
  /** Parse one or more p items, separated by sep,
   *  returning a list of the generated ASTs. */
  def mandatorySeparatedList[a](p: Parser[a], sep: String): Parser[List[a]] =
    for ( val t1 <- p; 
          val ts <- rep(check(sep) &&& p) )
      yield t1 :: ts;
}
