From e59946aa0ab697e79a68304f3dcbd48d2f99b25d Mon Sep 17 00:00:00 2001 From: joshvera Date: Mon, 26 Oct 2015 15:06:45 -0400 Subject: [PATCH] Return Members as Fixed --- prototype/Doubt/JSONParser.swift | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/prototype/Doubt/JSONParser.swift b/prototype/Doubt/JSONParser.swift index 87d36725a..99706ea94 100644 --- a/prototype/Doubt/JSONParser.swift +++ b/prototype/Doubt/JSONParser.swift @@ -39,16 +39,18 @@ let stringBody: StringParser = { $0.map({ String($0) }).joinWithSeparator("") } String.lift(noneOf("\"")*) let quoted = %"\"" *> stringBody <* %"\"" <* whitespace -typealias MembersParser = Parser.Function; +typealias MembersParser = Parser.Function; // Parses an array of (String, CofreeJSON) object members func members(json: JSONParser) -> MembersParser { - let pairs: Parser.Function = (curry(pair) <^> + let pairs: Parser.Function = (curry(pair) <^> quoted <* whitespace <* %":" <* whitespace - <*> json) + <*> json) --> { (_, range, values) in + Cofree(range, .Keyed(Dictionary(dictionaryLiteral: values))) + } let separatedPairs: MembersParser = (%"," *> whitespace *> pairs <* whitespace)* @@ -91,13 +93,7 @@ public let json: JSONParser = fix { json in <* %"}" <* whitespace --> { (_, range, values) in - let vs: [CofreeJSON] = values.map({ (string, value) in - let valueRange = value.extract - let newRange = Range(start: range.startIndex, end: valueRange.endIndex) - return Cofree(newRange, .Keyed([string: value])) - }) - - return Cofree(range, .Fixed(vs)) + Cofree(range, .Fixed(values)) } "object" let doubleParser: DoubleParser = number