From dd8d4bac2c610c662fc15802dda4159df493a499 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 4 Nov 2015 15:11:35 -0500 Subject: [PATCH] Parameterize CofreeJSON by SourcePos --- prototype/Doubt/JSONParser.swift | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/prototype/Doubt/JSONParser.swift b/prototype/Doubt/JSONParser.swift index fe8f7b9c6..3b19d14c2 100644 --- a/prototype/Doubt/JSONParser.swift +++ b/prototype/Doubt/JSONParser.swift @@ -10,7 +10,7 @@ import Foundation import Madness import Prelude -public typealias CofreeJSON = Cofree> +public typealias CofreeJSON = Cofree, Range)> public typealias JSONParser = Parser.Function // Inlined for performance reasons @@ -29,16 +29,16 @@ typealias MembersParser = Parser.F // Parses an array of (String, CofreeJSON) object members func members(json: JSONParser) -> MembersParser { - let keyAndKeyTerm: Parser.Function = quoted --> { (_, range, key) in - (key, Cofree(range, .Leaf(.String(key)))) + let keyAndKeyTerm: Parser.Function = quoted --> { (pos, range, key) in + (key, Cofree((pos, range), .Leaf(.String(key)))) } let pairs: Parser.Function = (curry(pair) <^> keyAndKeyTerm <* whitespace <* %":" <* whitespace - <*> json) --> { (_, range, values) in - (values.0.0, Cofree(range, .Fixed([values.0.1, values.1]))) + <*> json) --> { (pos, range, values) in + (values.0.0, Cofree((pos, range), .Fixed([values.0.1, values.1]))) } return sepBy(pairs, whitespace <* %"," <* whitespace) @@ -46,7 +46,7 @@ func members(json: JSONParser) -> MembersParser { public let json: JSONParser = fix { json in let string: JSONParser = quoted --> { - Cofree($1, .Leaf(.String($2))) + Cofree(($0, $1), .Leaf(.String($2))) } "string" let array: JSONParser = %"[" @@ -55,7 +55,7 @@ public let json: JSONParser = fix { json in <* whitespace <* %"]" --> { - Cofree($1, .Indexed($2)) + Cofree(($0, $1), .Indexed($2)) } "array" let object: JSONParser = %"{" @@ -63,21 +63,21 @@ public let json: JSONParser = fix { json in *> members(json) <* whitespace <* %"}" - --> { (_, range, values: [(String, CofreeJSON)]) in - Cofree(range, .Keyed(Dictionary(elements: values))) + --> { (pos, range, values: [(String, CofreeJSON)]) in + Cofree((pos, range), .Keyed(Dictionary(elements: values))) } "object" - let numberParser: JSONParser = (number --> { _, range, value in - Cofree(range, .Leaf(JSONLeaf.Number(value))) + let numberParser: JSONParser = (number --> { pos, range, value in + Cofree((pos, range), .Leaf(JSONLeaf.Number(value))) }) "number" - let null: JSONParser = %"null" --> { (_, range, value) in - return Cofree(range, .Leaf(.Null)) + let null: JSONParser = %"null" --> { pos, range, value in + return Cofree((pos, range), .Leaf(.Null)) } "null" - let boolean: JSONParser = %"false" <|> %"true" --> { (_, range, value) in + let boolean: JSONParser = %"false" <|> %"true" --> { pos, range, value in let boolean = value == "true" - return Cofree(range, .Leaf(.Boolean(boolean))) + return Cofree((pos, range), .Leaf(.Boolean(boolean))) } "boolean" // TODO: This should be JSON = dict <|> array and