I've got this text
--make_123
Say:Hello
Say:Bye
--make_123--
I need to parse it like this into map:
{
makeId : 123
firstNode : Hello
secondNode : Bye
}
I've got the following scala code:
class MyParser extends RegexParsers {
def parseText(input: String): MapContent = parseAll(parseRequest, input) match {
case Success(result, _) => result
case NoSuccess(msg, _) => throw new SomeException(msg)
}
def parseRequest: Parser[MapContent] = parseMakeId ~ parseText ^^ {
case makeId ~ firstNode => {
MapContent(
Map("makeId" -> makeId) ++
Map("firstNode" -> firstNode))
}
}
def parseMakeId: Parser[String] = "--make_" ~> ".*".r
def parseText: Parser[String] = "Say:" ~> ".*".r
}
case class MapContent(map: Map[String, String])
Well, here i receive
string matching regex `.*\z$' expected but `S' found
which is the second line and the first literal of "Say:"
How to parse that text? How to omit an empty line on the 3rd line? Thx