regex - Having trouble with Scala's "repsep" as seen in parser combinators -


Please help! I am trying to create a parser to parse SSDP messages as defined. (See "Discovery" section)

Actually this is the title of the HTTP, OK, after the name: Add value, and finally a blank line. After

5000 combinations, it's one that I think should most "is" work: * class SsdpParser () JavaTokenParsers {

def fulldoc: Parser [ssdpMessage] = header ~ nameValuePairs & LT; ~ "\ R \ n" ^^ {case header ~ value = & gt; SsdpMessage (header, value)}

nameValuePairs def: parser [list [(String, String)]] = repsep (nameValuePair, "\ r \ n")

nameValuePair def: Parser [(string, string)] = (// name ("" "[-a-gaa-z.-9.] *" "" .rrl; ~ ":") // value ~ "" " [A -ZA-Z0-9: /, _; [] .- \ "\ '\? =] *" "". R) ^^ {case name = value => (name, value)} < / p>

def title: parser [SsdpType] = (notifyLine | okLine | mSearch) def notifyLine: notify parser [SsdpType] = "notify * HTTP / 1.1 \ r \ n" ^^ (X = & gt; ) Def mSearch: Parser [SsdpType] = "M-Search * HTTP / 1.1 \ r \ n" ^ ^ (x = & gt; Search) Def A: Parser [SSDP Type] = "HTTP / 1.1 200 OK \ r \ n" ^ ^ (x =

}

However, when it is running It seems that it sticks to the very first name / value pair.

Failure: [3.1] Failure: String mailing regex \ r \ n 'expected but 'Miley

Date: Mon, 28 Mar 2011 06:37:31 GMT

^

It looks like a line break, it Why is not a mail? And yes, I have verified that there are two letters (aka 0x0 D 0x0a UTF-8) in both specification and actual data received.

A sample data dump is here: *

 HTTP / 1.1 200 OK cache-control: Max-age = 300 Date: Mon, 28 Mar 2011 06:37:31 GMT Ext location: server: POSIX UPnP / 1.0 DD-WRT Linux / V24 ST: urn: Skima- UPnP- organization: Services: WANCommonInterfaceConfig: 1 USN: UUID: 01A0DDA7-7404-815B-63C4-539B920D5E56 :: urn: Skima- UPnP -ORG: Service: WANCOMInInterfaceConfig: 1 

0000 00 50 8db 5 2b df 00 12 17 39 a2 17 08 00 45 00 p .. + .... 9 .... e. 0010 01 83 00 00 40 00 40 11 B5F 0 C801 01 C AA .... @ @ ......... 0020 01 28 07 6C CF 07 016 F7DB848 54 54 50 2F31 (.l ... o). HTTP / 1 0030 2E31 2032 30 30 20 4F 4 BD A A A163 61 63 68 65.1 200 OK .. Catch 0040 2D 43 6F 6 A 74 72 6 F 6 C3A206 D 61 78 2D 61 67- Control: Max-0000 00 00 65 65 3 33 30 30 0A 44 61 74 65 3A 20 53 75 6EE = 300..Date: Sun 0060 2C20 32 37 20 4D 61 72 20 32 30 31 31 20 30 38, 27 March 2011 08 0070 3A 34 37 3 A 33 34 20 47 4 54 54 DD A 45 78 74 3A: 47: 34 GMT..Act 0080 20 0 D A6C 6 F 63 61 74 69 6 F 6 A3A 20 68 74 74. Location: Hippal 0090 70 3 A2F2F313932 2E3136 38 2E 31 2E313 AP: 1952.168.1.1: 00 A137 37 38 30 2 F 49 6 E 74 65 72 6 65 65 47 47 74 74 1780 / Internetgate 00b0 65 77 61 79 44 65 76 69 63 65 2e 78 6d 6c 0d 0aEveidice Xml .. 00c0 53 65 72 76 65 72 3 A 20 50 4 F 53 49 58 20 55 50 Server: POSIX UP 00 D6 B 50 2 F 31 2 A 30 20 44 44 2 D 57 52 54 20 4 C 69 NP / 1.0 DD-Wert Lee 00E 06 6A 75 78 2F 56 32 34 D A 53 54 3A 20 75 72 6N News / V24..ST: Porn 00 F 3 A 73 63 68 65 6 D 61 73 2D 75 70 6 E 70 2D 6 F 72: Schema-up NAP- or 0100 67 3 A 73 65 72 76 69 63 65 3 A 57 41 4E 43 6 F 6 D: Service: Wankom 0110 6 D6 F 6E 49 6 E 74 65 72 66 61 63 65 43 6 F 6 E 66 Mon Interface Conf 0120 69 67 3A 31 DD A 5553 4 E3A 20 75 75 69 64 3 A IG : 1. USN: UUID: 0130 30 31 41 30 44 44 41 37 2D 37 34 30 34 2 D 38 31 01A0DDA7-7404-81 0140 35 42 2 D 36 33 43 34 2 D 35 33 39 42 39 32 30 44 5 b -63 C4-539B920D 0150 35 45 35 36 3 A 3 A 75 72 6E 3A 73 63 68 65 6d 61 5E56 :: urn: schemas 0160 73 2 D 75 70 6E 70 2D 6F 72 67 3 A 73 65 72 76 69 S UPnP- organization: servi 0170 63 65 3 A 57 41 4e 43 6F 6d 6d 6F 6e 49 6e 74 65 CE: WANCommonInte 0180 72 66 61 63 65 43 6 F 6 A 66 69 67 3A 31 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 After a quick glance, three suggestions:

  • Use of JavaTokenParsers instead of using the following JavaTokenParsers: / div>

Comments