daydreamer
daydreamer

Reputation: 92119

"Expected whitespace character" when running a custom inputKey

I am creating a custom inputKey which looks like

val rating = inputKey[Option[Int]]("How will you rate this course?")
rating := {
  import complete.DefaultParsers._
  import complete.Parser
  val r: Parser[Int] = IntBasic.examples("<rating>")
  r.result
}

This sits in file projectRoot/build.sbt.

I try to run this on sbt shell using multiple times, each time it fails

sbt:Hello> rating 1
[error] Expected whitespace character
[error] Expected '/'
[error] rating 1
[error]        ^
sbt:Hello>

Then,

sbt:Hello> show "rating 3"
[error] Expected whitespace character
[error] Expected 'Global'
[error] Expected '*'
[error] Expected 'Zero'
[error] Expected 'ThisBuild'
[error] Expected 'ProjectRef('
[error] Expected '{'
[error] Expected project ID
[error] Expected configuration
[error] Expected configuration ident
[error] Expected key
[error] show "rating 3"
[error]      ^
sbt:Hello>

Also, as

sbt:Hello> rating "5"
[error] Expected whitespace character
[error] Expected '/'
[error] rating "5"
[error]        ^
sbt:Hello>

I do not know what I am missing here. Can someone please point out my mistake here?

Upvotes: 3

Views: 2490

Answers (1)

Mario Galic
Mario Galic

Reputation: 48420

Since there is a space character before the integer, try using Space ~> IntBasic parser combination like so

lazy val rating = inputKey[Int]("How will you rate this course?")
rating := {
  import complete.DefaultParsers._
  val rating = (Space ~> IntBasic).examples("<rating>").parsed
  println(s"Rating input = $rating")
  rating
}

Executing rating 3 in sbt should now output Rating input = 3

Upvotes: 4

Related Questions