1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 18:23:44 +03:00

Return Members as Fixed

This commit is contained in:
joshvera 2015-10-26 15:06:45 -04:00
parent 92539dec54
commit e59946aa0a

View File

@ -39,16 +39,18 @@ let stringBody: StringParser = { $0.map({ String($0) }).joinWithSeparator("") }
String.lift(noneOf("\"")*) String.lift(noneOf("\"")*)
let quoted = %"\"" *> stringBody <* %"\"" <* whitespace let quoted = %"\"" *> stringBody <* %"\"" <* whitespace
typealias MembersParser = Parser<String, [(String, CofreeJSON)]>.Function; typealias MembersParser = Parser<String, [CofreeJSON]>.Function;
// Parses an array of (String, CofreeJSON) object members // Parses an array of (String, CofreeJSON) object members
func members(json: JSONParser) -> MembersParser { func members(json: JSONParser) -> MembersParser {
let pairs: Parser<String, (String, CofreeJSON)>.Function = (curry(pair) <^> let pairs: Parser<String, CofreeJSON>.Function = (curry(pair) <^>
quoted quoted
<* whitespace <* whitespace
<* %":" <* %":"
<* whitespace <* whitespace
<*> json) <*> json) --> { (_, range, values) in
Cofree(range, .Keyed(Dictionary(dictionaryLiteral: values)))
}
let separatedPairs: MembersParser = (%"," *> whitespace *> pairs <* whitespace)* let separatedPairs: MembersParser = (%"," *> whitespace *> pairs <* whitespace)*
@ -91,13 +93,7 @@ public let json: JSONParser = fix { json in
<* %"}" <* %"}"
<* whitespace <* whitespace
--> { (_, range, values) in --> { (_, range, values) in
let vs: [CofreeJSON] = values.map({ (string, value) in Cofree(range, .Fixed(values))
let valueRange = value.extract
let newRange = Range(start: range.startIndex, end: valueRange.endIndex)
return Cofree(newRange, .Keyed([string: value]))
})
return Cofree(range, .Fixed(vs))
} <?> "object" } <?> "object"
let doubleParser: DoubleParser = number let doubleParser: DoubleParser = number