diff --git a/prototype/Doubt/Cofree.swift b/prototype/Doubt/Cofree.swift index e9fc3c44d..e4ba01733 100644 --- a/prototype/Doubt/Cofree.swift +++ b/prototype/Doubt/Cofree.swift @@ -124,5 +124,21 @@ public protocol CofreeType { extension Cofree: CofreeType {} +extension CofreeType where Self.Annotation == Range { + public func JSON(source: String) -> Doubt.JSON { + return unwrap.JSON( + ifLeaf: { _ in .String(source[extract]) }, + ifRecur: { + [ + "range": [ + "offset": .Number(Double(source.startIndex.distanceTo($0.extract.startIndex))), + "length": .Number(Double($0.extract.count)), + ], + "unwrap": $0.JSON(source) + ] + }) + } +} + import Prelude