Merge pull request #5745 from eed3si9n/wip/semi

Fixes semicolon showing up in parser errors
This commit is contained in:
eugene yokota 2020-08-14 05:10:44 -04:00 committed by GitHub
commit d7c9b01d81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 11 deletions

View File

@ -89,10 +89,7 @@ object JLineCompletion {
(insert.toSeq, display.toSeq.sorted)
}
def appendNonEmpty(set: Set[String], add: String) = {
val trimmed = add.trim
if (trimmed.isEmpty || trimmed == ";") set else set + add
}
def appendNonEmpty(set: Set[String], add: String) = if (add.trim.isEmpty) set else set + add
def customCompletor(
f: (String, Int) => (Seq[String], Seq[String])

View File

@ -208,10 +208,11 @@ object BasicCommands {
else Parser.success(result.toList)
}
(cmdParser ~ multiCmdParser.+).flatMap {
case ("", rest) => validateCommands(rest)
case (p, rest) => validateCommands(rest).map(p :: _)
}
(cmdParser ~ multiCmdParser.+)
.flatMap {
case ("", rest) => validateCommands(rest)
case (p, rest) => validateCommands(rest).map(p :: _)
}
}
def multiParser(s: State): Parser[List[String]] = multiParserImpl(Some(s))

View File

@ -184,7 +184,8 @@ object Command {
)
def process(command: String, state: State): State = {
parse(command, state.combinedParser) match {
(if (command.contains(";")) parse(command, state.combinedParser)
else parse(command, state.nonMultiParser)) match {
case Right(s) => s() // apply command. command side effects happen here
case Left(errMsg) =>
state.log error errMsg

View File

@ -53,7 +53,11 @@ final case class State(
private[sbt] lazy val (multiCommands, nonMultiCommands) =
definedCommands.partition(_.nameOption.contains(BasicCommandStrings.Multi))
private[sbt] lazy val nonMultiParser = Command.combine(nonMultiCommands)(this)
lazy val combinedParser = multiCommands.foldRight(nonMultiParser)(_.parser(this) | _)
lazy val combinedParser: Parser[() => State] =
multiCommands.headOption match {
case Some(multi) => multi.parser(this) | nonMultiParser
case _ => nonMultiParser
}
def source: Option[CommandSource] =
currentCommand match {

View File

@ -14,7 +14,10 @@ import sbt.internal.util.complete.Parser
object MultiParserSpec {
val parser: Parser[Seq[String]] = BasicCommands.multiParserImpl(None)
implicit class StringOps(val s: String) {
def parse: Seq[String] = Parser.parse(s, parser).right.get
def parse: Seq[String] = Parser.parse(s, parser) match {
case Right(x) => x
case Left(x) => sys.error(s)
}
def parseEither: Either[String, Seq[String]] = Parser.parse(s, parser)
}
}