diff --git a/util/complete/Parser.scala b/util/complete/Parser.scala index b9f1fe577..53d6ca01a 100644 --- a/util/complete/Parser.scala +++ b/util/complete/Parser.scala @@ -45,7 +45,7 @@ sealed trait RichParser[A] /** Explicitly defines the completions for the original Parser.*/ def examples(s: String*): Parser[A] /** Explicitly defines the completions for the original Parser.*/ - def examples(s: Set[String]): Parser[A] + def examples(s: Set[String], check: Boolean = false): Parser[A] /** Converts a Parser returning a Char sequence to a Parser returning a String.*/ def string(implicit ev: A <:< Seq[Char]): Parser[String] /** Produces a Parser that filters the original parser. @@ -173,7 +173,7 @@ trait ParserMain def & (o: Parser[_]) = and(a, o) def - (o: Parser[_]) = sub(a, o) def examples(s: String*): Parser[A] = examples(s.toSet) - def examples(s: Set[String]): Parser[A] = Parser.examples(a, s, check = true) + def examples(s: Set[String], check: Boolean = false): Parser[A] = Parser.examples(a, s, check) def filter(f: A => Boolean): Parser[A] = filterParser(a, f) def string(implicit ev: A <:< Seq[Char]): Parser[String] = map(_.mkString) def flatMap[B](f: A => Parser[B]) = bindParser(a, f) diff --git a/util/complete/Parsers.scala b/util/complete/Parsers.scala index 096614ad9..85c5a73fb 100644 --- a/util/complete/Parsers.scala +++ b/util/complete/Parsers.scala @@ -44,6 +44,8 @@ trait Parsers private[this] def toInt(neg: Option[Char], digits: Seq[Char]): Int = (neg.toSeq ++ digits).mkString.toInt + def repsep[T](rep: Parser[T], sep: Parser[_]): Parser[Seq[T]] = + rep1sep(rep, sep) ?? Nil def rep1sep[T](rep: Parser[T], sep: Parser[_]): Parser[Seq[T]] = (rep ~ (sep ~> rep).*).map { case (x ~ xs) => x +: xs } @@ -58,4 +60,9 @@ trait Parsers def Uri(ex: Set[URI]) = mapOrFail(URIClass)( uri => new URI(uri)) examples(ex.map(_.toString)) } object Parsers extends Parsers -object DefaultParsers extends Parsers with ParserMain \ No newline at end of file +object DefaultParsers extends Parsers with ParserMain +{ + def matches(p: Parser[_], s: String): Boolean = + apply(p)(s).resultEmpty.isDefined + def validID(s: String): Boolean = matches(ID, s) +} \ No newline at end of file