mirror of
https://github.com/github/semantic.git
synced 2024-11-29 02:44:36 +03:00
Rename the Syntax piecewise JSON functions after the type parameters (mostly).
This commit is contained in:
parent
40fe88b4a4
commit
8cbb69fa97
@ -91,7 +91,7 @@ extension Cofree {
|
||||
public func JSON(annotation annotation: Annotation -> Doubt.JSON, leaf: Leaf -> Doubt.JSON) -> Doubt.JSON {
|
||||
return [
|
||||
"extract": annotation(extract),
|
||||
"unwrap": unwrap.JSON(ifLeaf: leaf, ifRecur: { $0.JSON(annotation: annotation, leaf: leaf) })
|
||||
"unwrap": unwrap.JSON(leaf: leaf, recur: { $0.JSON(annotation: annotation, leaf: leaf) })
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -125,8 +125,8 @@ 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: {
|
||||
leaf: { _ in .String(source[extract]) },
|
||||
recur: {
|
||||
[
|
||||
"range": [
|
||||
"offset": .Number(Double(source.startIndex.distanceTo($0.extract.startIndex))),
|
||||
|
@ -193,7 +193,7 @@ extension Free {
|
||||
return analysis(
|
||||
ifPure: pure,
|
||||
ifRoll: {
|
||||
$0.JSON(ifLeaf: leaf, ifRecur: { $0.JSON(pure: pure, leaf: leaf) })
|
||||
$0.JSON(leaf: leaf, recur: { $0.JSON(pure: pure, leaf: leaf) })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -74,14 +74,14 @@ public func == <F: Equatable, A: Equatable> (left: Syntax<F, A>, right: Syntax<F
|
||||
// MARK: - JSON
|
||||
|
||||
extension Syntax {
|
||||
public func JSON(@noescape ifLeaf ifLeaf: A -> Doubt.JSON, @noescape ifRecur: Recur -> Doubt.JSON) -> Doubt.JSON {
|
||||
public func JSON(@noescape leaf leaf: A -> Doubt.JSON, @noescape recur: Recur -> Doubt.JSON) -> Doubt.JSON {
|
||||
switch self {
|
||||
case let .Leaf(a):
|
||||
return ifLeaf(a)
|
||||
return leaf(a)
|
||||
case let .Indexed(a):
|
||||
return .Array(a.map(ifRecur))
|
||||
return .Array(a.map(recur))
|
||||
case let .Keyed(d):
|
||||
return .Dictionary(Dictionary(elements: d.map { ($0, ifRecur($1)) }))
|
||||
return .Dictionary(Dictionary(elements: d.map { ($0, recur($1)) }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user