1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 16:02:43 +03:00

Use strings for the categories.

This commit is contained in:
Rob Rix 2015-10-28 17:48:51 -04:00
parent f7f45444e0
commit 6688f223fe
2 changed files with 6 additions and 11 deletions

View File

@ -3,13 +3,8 @@
typealias TSDocument = COpaquePointer
extension TSNode {
func name(document: TSDocument) throws -> String {
guard let name = String.fromCString(ts_node_name(self, document)) else { throw E() }
return name
}
func category(document: TSDocument) throws -> Info.Category {
guard let category = Info.Category(rawValue: try name(document)) else { throw E() }
func category(document: TSDocument) throws -> String {
guard let category = String.fromCString(ts_node_name(self, document)) else { throw E() }
return category
}

View File

@ -77,13 +77,13 @@ func termWithInput(string: String) -> Term? {
return try? Cofree
.ana { node, category in
let count = node.namedChildren.count
guard count > 0 else { return Syntax.Leaf(category.rawValue) }
guard count > 0 else { return Syntax.Leaf(category) }
switch category {
case .Pair:
case "pair":
return try .Fixed(node.namedChildren.map {
($0, try $0.category(document))
})
case .Object:
case "object":
return try .Keyed(Dictionary(elements: node.namedChildren.map {
guard let range = $0.namedChildren.first?.range else { throw E() }
guard let name = String(string.utf16[String.UTF16View.Index(_offset: range.startIndex)..<String.UTF16View.Index(_offset: range.endIndex)]) else { throw E() }
@ -94,7 +94,7 @@ func termWithInput(string: String) -> Term? {
($0, try $0.category(document))
})
}
} (root, Info.Category.Program)
} (root, "program")
.map { node, category in
node.range
}