1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 10:15:55 +03:00

Add an Info constructor from ranges/JSON leaves.

This commit is contained in:
Rob Rix 2015-10-30 14:52:22 -04:00
parent 28e417e1c4
commit 13a872d477

View File

@ -4,6 +4,22 @@ struct Info: Categorizable, CustomJSONConvertible, Equatable {
self.categories = categories
}
init(range: Range<String.CharacterView.Index>, leaf: JSONLeaf) {
// FIXME: this is terrible. see also https://github.com/github/semantic-diff/issues/136
self.range = Int(String(range.startIndex))!..<Int(String(range.endIndex))!
switch leaf {
case .Number:
self.categories = [ "number" ]
case .Boolean:
self.categories = [ "boolean" ]
case .String:
self.categories = [ "string" ]
case .Null:
self.categories = [ "null" ]
}
}
let range: Range<Int>