mirror of https://github.com/sbt/sbt.git
tab completion: example-checking off by default, 'matches' convenience method
This commit is contained in:
parent
127e48f1c0
commit
1dd4a1d1b1
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
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)
|
||||
}
|
||||
Loading…
Reference in New Issue