I'm trying to parse a string using scala's parser combinators like this:
import scala.util.parsing.combinator._
import scala.util.parsing.input.CharSequenceReader
object TestPackratParser extends RegexParsers with PackratParsers {
lazy val program: PackratParser[Any] = "start" ~ water ~ "end" ^^ (_ => println("program"))
lazy val water: PackratParser[Any] = (""".""".r).* ^^ (_ => println("water"))
def main(args: Array[String]) {
parseAll(phrase(program), new PackratReader(new CharSequenceReader("start something here end")))
}
}
I think this should be successful because a packrat parser backtracks, so "water" will eventually match "something here".
However, it seems that "water" is matching "something here end" instead. I would have thought it shouldn't do this. Is there a way to fix it?