For a first test with scala combinators, I am trying to get all words from a sentence, but I am just getting "None" from the following code :
import java.io.File
import scala.io.Source
import scala.util.parsing.combinator._
object PgnReader extends TagParser {
def parseFile(inputFile:File) = {
val pgnStream = Source.fromFile(inputFile)
val pgnStr = pgnStream.mkString
println(parseAll(tag, "Hello World !").getOrElse("None"))
pgnStream.close
}
}
trait TagParser extends RegexParsers {
val tag:Parser[String] = """[:alpha:]+""".r ^^ (_.toString)
}
I would like to get something like :
Hello
World
or even like :
List(Hello, World)
Am I on the right way with my code ?
I am using scala 2.11 and scala combinators