1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 16:33:03 +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 typealias TSDocument = COpaquePointer
extension TSNode { extension TSNode {
func name(document: TSDocument) throws -> String { func category(document: TSDocument) throws -> String {
guard let name = String.fromCString(ts_node_name(self, document)) else { throw E() } guard let category = 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() }
return category return category
} }

View File

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