mirror of https://github.com/sbt/sbt.git
move error processing to complete/
This commit is contained in:
parent
57ec3bf37e
commit
3587777638
|
|
@ -139,7 +139,7 @@ object Project extends Init[Scope] with ProjectExtra
|
|||
def apply(id: String, base: File, aggregate: => Seq[ProjectReference] = Nil, dependencies: => Seq[ClasspathDep[ProjectReference]] = Nil, delegates: => Seq[ProjectReference] = Nil,
|
||||
settings: => Seq[Setting[_]] = defaultSettings, configurations: Seq[Configuration] = Configurations.default): Project =
|
||||
{
|
||||
Command.parse(id, DefaultParsers.ID).left.foreach(errMsg => error("Invalid project ID: " + errMsg))
|
||||
DefaultParsers.parse(id, DefaultParsers.ID).left.foreach(errMsg => error("Invalid project ID: " + errMsg))
|
||||
new ProjectDef[ProjectReference](id, base, aggregate, dependencies, delegates, settings, configurations) with Project
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ private[sbt] final class ArbitraryCommand(val parser: State => Parser[() => Stat
|
|||
|
||||
object Command
|
||||
{
|
||||
def pointerSpace(s: String, i: Int): String = (s take i) map { case '\t' => '\t'; case _ => ' ' } mkString;
|
||||
|
||||
import DefaultParsers._
|
||||
|
||||
def command(name: String, briefHelp: String, detail: String)(f: State => State): Command = command(name, Help(name, (name, briefHelp), detail))(f)
|
||||
|
|
@ -95,36 +93,6 @@ object Command
|
|||
state.fail
|
||||
}
|
||||
}
|
||||
def parse[T](str: String, parser: Parser[T]): Either[String, T] =
|
||||
Parser.result(parser, str).left.map { failures =>
|
||||
val (msgs,pos) = failures()
|
||||
commandError(str, msgs, pos)
|
||||
}
|
||||
|
||||
def commandError(command: String, msgs: Seq[String], index: Int): String =
|
||||
{
|
||||
val (line, modIndex) = extractLine(command, index)
|
||||
val point = pointerSpace(command, modIndex)
|
||||
msgs.mkString("\n") + "\n" + line + "\n" + point + "^"
|
||||
}
|
||||
def extractLine(s: String, i: Int): (String, Int) =
|
||||
{
|
||||
val notNewline = (c: Char) => c != '\n' && c != '\r'
|
||||
val left = takeRightWhile( s.substring(0, i) )( notNewline )
|
||||
val right = s substring i takeWhile notNewline
|
||||
(left + right, left.length)
|
||||
}
|
||||
def takeRightWhile(s: String)(pred: Char => Boolean): String =
|
||||
{
|
||||
def loop(i: Int): String =
|
||||
if(i < 0)
|
||||
s
|
||||
else if( pred(s(i)) )
|
||||
loop(i-1)
|
||||
else
|
||||
s.substring(i+1)
|
||||
loop(s.length - 1)
|
||||
}
|
||||
def invalidValue(label: String, allowed: Iterable[String])(value: String): String =
|
||||
"Not a valid " + label + ": " + value + similar(value, allowed)
|
||||
def similar(value: String, allowed: Iterable[String]): String =
|
||||
|
|
|
|||
|
|
@ -277,6 +277,12 @@ trait ParserMain
|
|||
def unapply[A,B](t: (A,B)): Some[(A,B)] = Some(t)
|
||||
}
|
||||
|
||||
def parse[T](str: String, parser: Parser[T]): Either[String, T] =
|
||||
Parser.result(parser, str).left.map { failures =>
|
||||
val (msgs,pos) = failures()
|
||||
ProcessError(str, msgs, pos)
|
||||
}
|
||||
|
||||
// intended to be temporary pending proper error feedback
|
||||
def result[T](p: Parser[T], s: String): Either[() => (Seq[String],Int), T] =
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package sbt.complete
|
||||
|
||||
object ProcessError
|
||||
{
|
||||
def apply(command: String, msgs: Seq[String], index: Int): String =
|
||||
{
|
||||
val (line, modIndex) = extractLine(command, index)
|
||||
val point = pointerSpace(command, modIndex)
|
||||
msgs.mkString("\n") + "\n" + line + "\n" + point + "^"
|
||||
}
|
||||
def extractLine(s: String, i: Int): (String, Int) =
|
||||
{
|
||||
val notNewline = (c: Char) => c != '\n' && c != '\r'
|
||||
val left = takeRightWhile( s.substring(0, i) )( notNewline )
|
||||
val right = s substring i takeWhile notNewline
|
||||
(left + right, left.length)
|
||||
}
|
||||
def takeRightWhile(s: String)(pred: Char => Boolean): String =
|
||||
{
|
||||
def loop(i: Int): String =
|
||||
if(i < 0)
|
||||
s
|
||||
else if( pred(s(i)) )
|
||||
loop(i-1)
|
||||
else
|
||||
s.substring(i+1)
|
||||
loop(s.length - 1)
|
||||
}
|
||||
def pointerSpace(s: String, i: Int): String = (s take i) map { case '\t' => '\t'; case _ => ' ' } mkString;
|
||||
}
|
||||
Loading…
Reference in New Issue