mirror of
https://github.com/github/semantic.git
synced 2024-11-24 17:04:47 +03:00
commit
3e7bbee2c8
@ -111,7 +111,20 @@ func toTerm(term: CofreeJSON) -> Term {
|
||||
}
|
||||
}
|
||||
|
||||
func parserForType(type: String) -> (String throws -> Term)? {
|
||||
func lines(input: String) -> Term {
|
||||
var lines: [Term] = []
|
||||
var previous = 0
|
||||
input.enumerateSubstringsInRange(input.characters.indices, options: .ByLines) { (line, _, enclosingRange, _) in
|
||||
let range: Range<Int> = previous..<(previous + enclosingRange.count)
|
||||
previous = range.endIndex
|
||||
if let line = line {
|
||||
lines.append(Term(Info(range: range, categories: []), Syntax.Leaf(line)))
|
||||
}
|
||||
}
|
||||
return Term(Info(range: 0..<input.utf16.count, categories: []), .Indexed(lines))
|
||||
}
|
||||
|
||||
func parserForType(type: String) -> String throws -> Term {
|
||||
switch type {
|
||||
case "json":
|
||||
return { (input: String) throws -> Term in
|
||||
@ -123,7 +136,10 @@ func parserForType(type: String) -> (String throws -> Term)? {
|
||||
}
|
||||
}
|
||||
default:
|
||||
return Source.languagesByType[type].map(termWithInput)
|
||||
if let parser = Source.languagesByType[type].map(termWithInput) {
|
||||
return parser
|
||||
}
|
||||
return lines
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,7 +149,7 @@ guard let bSource = try arguments[2].map(Source.init) else { throw "need source
|
||||
let jsonURL = NSURL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).URLByAppendingPathComponent("diff.json")
|
||||
guard let uiPath = NSBundle.mainBundle().infoDictionary?["PathToUISource"] as? String else { throw "need ui path" }
|
||||
guard aSource.type == bSource.type else { throw "can’t compare files of different types" }
|
||||
guard let parser = parserForType(aSource.type) else { throw "don’t know how to parse files of type \(aSource.type)" }
|
||||
let parser = parserForType(aSource.type)
|
||||
|
||||
let a = try parser(aSource.contents)
|
||||
let b = try parser(bSource.contents)
|
||||
|
Loading…
Reference in New Issue
Block a user