1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 11:02:26 +03:00

Terms annotated with ranges over a string can be printed to JSON.

This commit is contained in:
Rob Rix 2015-10-16 11:09:20 -04:00
parent c058e81183
commit 8c341fc129

View File

@ -124,5 +124,21 @@ public protocol CofreeType {
extension Cofree: CofreeType {}
extension CofreeType where Self.Annotation == Range<String.Index> {
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