I write a scala script string_split.sc:
val s = " some interesting stuff ... "
// this does not work
val x = s.toLowerCase()
.replaceAll("[^\\w']", " ")
.split(" ")
.filter(w => w.trim.length >=1)
.groupBy(identity)
.mapValues(_.size)
when load it in sbt console with :load:
scala> :load src/main/scala/string_split.sc
src/main/scala/string_split.sc:1: error: illegal start of definition
.replaceAll("[^\\w']", " ")
^
src/main/scala/string_split.sc:1: error: illegal start of definition
.split(" ")
^
src/main/scala/string_split.sc:1: error: illegal start of definition
.filter(w => w.trim.length >=1)
^
src/main/scala/string_split.sc:1: error: illegal start of definition
.groupBy(identity)
^
src/main/scala/string_split.sc:1: error: illegal start of definition
.mapValues(_.size)
sbt console can not parsing the line start with '.'
The code is fine to load in scala REPL directly. compile it also fine. ':paste' it to sbt console also fine.
Only the sbt console has problem to load this. Is it a bug in sbt console? Is there work around?
my build.sbt is simple:
name := "Simple SBT"
version := "1.0"
scalaVersion := "2.11.12"