1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 17:04:47 +03:00

Capture the quoted range in members' keys

This commit is contained in:
joshvera 2015-10-27 13:28:35 -04:00
parent 96bcc25b23
commit 0718e49343
2 changed files with 6 additions and 7 deletions

View File

@ -50,16 +50,15 @@ typealias MembersParser = Parser<String, [(String, CofreeJSON)]>.Function;
// Parses an array of (String, CofreeJSON) object members
func members(json: JSONParser) -> MembersParser {
let pairs: Parser<String, (String, CofreeJSON)>.Function = (curry(pair) <^>
quoted
(quoted --> { (_, range, key) -> (String, CofreeJSON) in
return (key, Cofree(range, .Leaf(.String(key))))
})
<* whitespace
<* %":"
<* whitespace
<*> json) --> { (_, range, values) in
let key = values.0
let keyRange = Range(start: range.startIndex, end: range.startIndex.advancedBy(key.characters.count))
let cofreeKey: CofreeJSON = Cofree(keyRange, .Leaf(.String(key)))
return (key, Cofree(range, .Fixed([cofreeKey, values.1])))
let key = values.0.0
return (key, Cofree(range, .Fixed([values.0.1, values.1])))
}
return sepBy(pairs, whitespace <* %"," <* whitespace)

View File

@ -12,7 +12,7 @@ final class JSONParserTests: XCTestCase {
Cofree(29..<37, .Leaf(.String("sailor")))
]))
let fixedPairs: Cofree<JSONLeaf, Range<Int>> = Cofree(2..<41, .Keyed(["hello": array]))
let fixedPairs: Cofree<JSONLeaf, Range<Int>> = Cofree(2..<41, .Fixed([Cofree(2..<9, .Leaf(.String("hello"))), array]))
let expected: Cofree<JSONLeaf, Range<Int>> = Cofree(0..<42, .Keyed(["hello": fixedPairs]))
let actual = Madness.parse(json, input: dictWithArray).right!