mirror of
https://github.com/github/semantic.git
synced 2024-11-28 10:15:55 +03:00
Capture the quoted range in members' keys
This commit is contained in:
parent
96bcc25b23
commit
0718e49343
@ -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)
|
||||
|
@ -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!
|
||||
|
Loading…
Reference in New Issue
Block a user