1
1
mirror of https://github.com/github/semantic.git synced 2024-12-01 00:33:59 +03:00

Terms are annotated with Info.

This commit is contained in:
Rob Rix 2015-10-28 14:41:13 -04:00
parent 9d0805c228
commit ab7c0d172c

View File

@ -7,7 +7,7 @@ func readFile(path: String) -> String? {
return data as String? return data as String?
} }
typealias Term = Cofree<String, Range<Int>> typealias Term = Cofree<String, Info>
struct Info: Categorizable, CustomJSONConvertible, Equatable { struct Info: Categorizable, CustomJSONConvertible, Equatable {
let range: Range<Int> let range: Range<Int>
@ -87,7 +87,7 @@ func termWithInput(string: String) -> Term? {
} (root, Info.Category.Program) } (root, Info.Category.Program)
.map { node, category in .map { node, category in
let start = ts_node_pos(node).chars let start = ts_node_pos(node).chars
return start..<(start + ts_node_size(node).chars) return Info(range: start..<(start + ts_node_size(node).chars), category: category)
} }
} }
} }
@ -105,10 +105,10 @@ if let aString = arguments[1].flatMap(readFile), bString = arguments[2].flatMap(
let JSON: Doubt.JSON = [ let JSON: Doubt.JSON = [
"before": .String(aString), "before": .String(aString),
"after": .String(bString), "after": .String(bString),
"diff": diff.JSON(pure: { $0.JSON { $0.JSON(annotation: range, leaf: Doubt.JSON.String) } }, leaf: Doubt.JSON.String, annotation: { "diff": diff.JSON(pure: { $0.JSON { $0.JSON(annotation: Doubt.JSON.init, leaf: Doubt.JSON.String) } }, leaf: Doubt.JSON.String, annotation: {
[ [
"before": range($0), "before": $0.JSON,
"after": range($1), "after": $1.JSON,
] ]
}), }),
] ]