The simplest way to do this is to use the fromLines
method on PagedSeq
:
import scala.collection.immutable.PagedSeq
import scala.io.Source
import scala.util.parsing.input.PagedSeqReader
val lines = Source.fromFile("file.txt").getLines.map(
_.replaceAll("#.*", "").trim
).filterNot(_.isEmpty)
val reader = new PagedSeqReader(PagedSeq.fromLines(lines))
And now you've got a scala.util.parsing.input.Reader
that you can plug into your parser. This is essentially what happens when you parse a java.io.Reader
, anyway—it immediately gets wrapped in a PagedSeqReader
.