Please help! I am trying to build a parser to parse SSDP messages as defined in the UPnP protocol. (see \"Discovery\" section)
Basically it\'s a header of HTTP OK,
As jrudolph said, RegexParsers
(and its subclass JavaTokenParsers
) skip whitespace by default. You have the option of telling it not to skip whitespace, by overriding skipWhitespace
, and you also have the option of telling it what you consider to be whitespace, by overriding the protected val whiteSpace: Regex
.
The problem comes from this:
def nameValuePairs:Parser[List[(String, String)]] = repsep(nameValuePair, "\r\n")
Here, \r\n
is being skipped automatically, so it is never found. Once you changed skipWhitespace
, you got errors because there's an extra \r\n
at the end of the file, so it expects to see another nameValuePair
.
You might have better luck with this:
def nameValuePairs:Parser[List[(String, String)]] = rep(nameValuePair <~ "\r\n")
Alternatively, you might remove \r\n
altogether and let the parser skip whitespace.
After a quick glance, three suggestions: