0001    //
0002    //  Decoder.swift
0003    //  PMJSON
0004    //
0005    //  Created by Kevin Ballard on 10/8/15.
0006    //  Copyright © 2016 Postmates.
0007    //
0008    //  Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
0009    //  http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
0010    //  <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
0011    //  option. This file may not be copied, modified, or distributed
0012    //  except according to those terms.
0013    //
0014    
0015    #if os(Linux)
0016        import Glibc
0017    #else
0018        import Darwin
0019    #endif
0020    
0021    /// A streaming JSON parser that consumes a sequence of unicode scalars.
0022    public struct JSONParser
Decoder.swift:21
        var parser = JSONParser(string.unicodeScalars)
Decoder.swift:32
        var parser = JSONParser(scalars)
<Seq
Parser.swift:23
    public init(_ seq: Seq) {
Parser.swift:29
    public func generate() -> JSONParserGenerator<Seq.Generator> {
Parser.swift:35
    private let base: Seq
: SequenceType where Seq.Generator.Element == UnicodeScalar>: SequenceType { 0023 public init
Decoder.swift:21
        var parser = JSONParser(string.unicodeScalars)
Decoder.swift:32
        var parser = JSONParser(scalars)
(_ seq: Seq) { 0024 base = seq 0025 } 0026 0027 public var strict
Decoder.swift:22
        parser.strict = strict
Decoder.swift:33
        parser.strict = strict
Parser.swift:31
        gen.strict = strict
: Bool = false 0028 0029 public func generate() -> JSONParserGenerator<Seq.Generator> { 0030 var gen = JSONParserGenerator(base.generate()) 0031 gen.strict = strict 0032 return gen 0033 } 0034 0035 private let base
Parser.swift:24
        base = seq
Parser.swift:30
        var gen = JSONParserGenerator(base.generate())
: Seq 0036 } 0037 0038 /// The generator for JSONParser. 0039 public struct JSONParserGenerator
Parser.swift:29
    public func generate() -> JSONParserGenerator<Seq.Generator> {
Parser.swift:30
        var gen = JSONParserGenerator(base.generate())
<Gen
Parser.swift:40
    public init(_ gen: Gen) {
Parser.swift:399
    private var base: PeekGenerator<Gen>
: GeneratorType where Gen.Element == UnicodeScalar>: JSONEventGenerator { 0040 public init
Parser.swift:30
        var gen = JSONParserGenerator(base.generate())
(_ gen: Gen) { 0041 base = PeekGenerator(gen) 0042 } 0043 0044 public var strict
Parser.swift:31
        gen.strict = strict
Parser.swift:92
                        if !first && strict {
Parser.swift:113
                        if !first && strict {
: Bool = false 0045 0046 public mutating func next() -> JSONEvent? { 0047 do { 0048 // the only states that may loop are ParseArrayComma and ParseObjectComma 0049 // which are guaranteed to shift to other states (if they don't return) so the loop is finite 0050 while true { 0051 switch state { 0052 case .ParseArrayComma: 0053 switch skipWhitespace() { 0054 case ","?: 0055 state = .ParseArray(first: false) 0056 continue 0057 case "]"?: 0058 try popStack() 0059 return .ArrayEnd 0060 case .Some: 0061 throw error(.InvalidSyntax) 0062 case nil: 0063 throw error(.UnexpectedEOF) 0064 } 0065 case .ParseObjectComma: 0066 switch skipWhitespace() { 0067 case ","?: 0068 state = .ParseObjectKey(first: false) 0069 continue 0070 case "}"?: 0071 try popStack() 0072 return .ObjectEnd 0073 case .Some: 0074 throw error(.InvalidSyntax) 0075 case nil: 0076 throw error(.UnexpectedEOF) 0077 } 0078 case .Initial: 0079 guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) } 0080 let evt = try parseValue(c) 0081 switch evt { 0082 case .ArrayStart, .ObjectStart: 0083 break 0084 default: 0085 state = .ParseEnd 0086 } 0087 return evt 0088 case .ParseArray(let first): 0089 guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) } 0090 switch c { 0091 case "]": 0092 if !first && strict { 0093 throw error(.TrailingComma) 0094 } 0095 try popStack() 0096 return .ArrayEnd 0097 case ",": 0098 throw error(.MissingValue) 0099 default: 0100 let evt = try parseValue(c) 0101 switch evt { 0102 case .ArrayStart, .ObjectStart: 0103 break 0104 default: 0105 state = .ParseArrayComma 0106 } 0107 return evt 0108 } 0109 case .ParseObjectKey(let first): 0110 guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) } 0111 switch c { 0112 case "}": 0113 if !first && strict { 0114 throw error(.TrailingComma) 0115 } 0116 try popStack() 0117 return .ObjectEnd 0118 case ",", ":": 0119 throw error(.MissingKey) 0120 default: 0121 let evt = try parseValue(c) 0122 switch evt { 0123 case .StringValue: 0124 state = .ParseObjectValue 0125 default: 0126 throw error(.NonStringKey) 0127 } 0128 return evt 0129 } 0130 case .ParseObjectValue: 0131 guard skipWhitespace() == ":" else { throw error(.ExpectedColon) } 0132 guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) } 0133 switch c { 0134 case ",", "}": 0135 throw error(.MissingValue) 0136 default: 0137 let evt = try parseValue(c) 0138 switch evt { 0139 case .ArrayStart, .ObjectStart: 0140 break 0141 default: 0142 state = .ParseObjectComma 0143 } 0144 return evt 0145 } 0146 case .ParseEnd: 0147 if skipWhitespace() != nil { 0148 throw error(.TrailingCharacters) 0149 } 0150 state = .Finished 0151 return nil 0152 case .Finished: 0153 return nil 0154 } 0155 } 0156 } catch let error as JSONParserError { 0157 state = .Finished 0158 return .Error(error) 0159 } catch { 0160 fatalError("unexpected error \(error)") 0161 } 0162 } 0163 0164 private mutating func popStack
Parser.swift:58
                        try popStack()
Parser.swift:71
                        try popStack()
Parser.swift:95
                        try popStack()
Parser.swift:116
                        try popStack()
() throws { 0165 if stack.popLast() == nil { 0166 fatalError("exhausted stack") 0167 } 0168 switch stack.last { 0169 case .Array?: 0170 state = .ParseArrayComma 0171 case .Object?: 0172 state = .ParseObjectComma 0173 case nil: 0174 state = .ParseEnd 0175 } 0176 } 0177 0178 private mutating func parseValue
Parser.swift:80
                    let evt = try parseValue(c)
Parser.swift:100
                        let evt = try parseValue(c)
Parser.swift:121
                        let evt = try parseValue(c)
Parser.swift:137
                        let evt = try parseValue(c)
(c: UnicodeScalar) throws -> JSONEvent { 0179 switch c { 0180 case "[": 0181 state = .ParseArray(first: true) 0182 stack.append(.Array) 0183 return .ArrayStart 0184 case "{": 0185 state = .ParseObjectKey(first: true) 0186 stack.append(.Object) 0187 return .ObjectStart 0188 case "\"": 0189 var s = "" 0190 while let c = bump() { 0191 switch c { 0192 case "\"": 0193 return .StringValue(s) 0194 case "\\": 0195 let c = try bumpRequired() 0196 switch c { 0197 case "\"", "\\", "/": s.append(c) 0198 case "b": s.append(UnicodeScalar(0x8)) 0199 case "f": s.append(UnicodeScalar(0xC)) 0200 case "n": s.append("\n" as UnicodeScalar) 0201 case "r": s.append("\r" as UnicodeScalar) 0202 case "t": s.append("\t" as UnicodeScalar) 0203 case "u": 0204 let codeUnit = try parseFourHex() 0205 if UTF16.isLeadSurrogate(codeUnit) { 0206 guard try (bumpRequired() == "\\" && bumpRequired() == "u") else { 0207 throw error(.LoneLeadingSurrogateInUnicodeEscape) 0208 } 0209 let trail = try parseFourHex() 0210 if UTF16.isTrailSurrogate(trail) { 0211 let lead = UInt32(codeUnit) 0212 let trail = UInt32(trail) 0213 s.append(UnicodeScalar(((lead - 0xD800) << 10) + (trail - 0xDC00) + 0x10000)) 0214 } else { 0215 throw error(.LoneLeadingSurrogateInUnicodeEscape) 0216 } 0217 } else { 0218 s.append(UnicodeScalar(codeUnit)) 0219 } 0220 default: 0221 throw error(.InvalidEscape) 0222 } 0223 case "\0"..."\u{1F}": 0224 throw error(.InvalidSyntax) 0225 default: 0226 s.append(c) 0227 } 0228 } 0229 throw error(.UnexpectedEOF) 0230 case "-", "0"..."9": 0231 var tempBuffer: ContiguousArray<Int8> 0232 if let buffer = replace(&self.tempBuffer, with: nil) { 0233 tempBuffer = buffer 0234 tempBuffer.removeAll(keepCapacity: true) 0235 } else { 0236 tempBuffer = ContiguousArray() 0237 tempBuffer.reserveCapacity(12) 0238 } 0239 defer { self.tempBuffer = tempBuffer } 0240 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0241 outerLoop: while let c = base.peek() { 0242 switch c { 0243 case "0"..."9": 0244 bump() 0245 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0246 case ".": 0247 bump() 0248 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0249 guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) } 0250 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0251 loop: while let c = base.peek() { 0252 switch c { 0253 case "0"..."9": 0254 bump() 0255 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0256 case "e", "E": 0257 bump() 0258 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0259 guard let c = bump() else { throw error(.InvalidNumber) } 0260 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0261 switch c { 0262 case "-", "+": 0263 guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) } 0264 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0265 case "0"..."9": break 0266 default: throw error(.InvalidNumber) 0267 } 0268 while let c = base.peek() { 0269 switch c { 0270 case "0"..."9": 0271 bump() 0272 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0273 default: 0274 break loop 0275 } 0276 } 0277 break loop 0278 default: 0279 break loop 0280 } 0281 } 0282 tempBuffer.append(0) 0283 return .DoubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)})) 0284 case "e", "E": 0285 bump() 0286 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0287 guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) } 0288 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0289 loop: while let c = base.peek() { 0290 switch c { 0291 case "0"..."9": 0292 bump() 0293 tempBuffer.append(Int8(truncatingBitPattern: c.value)) 0294 default: 0295 break loop 0296 } 0297 } 0298 tempBuffer.append(0) 0299 return .DoubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)})) 0300 default: 0301 break outerLoop 0302 } 0303 } 0304 if tempBuffer.count == 1 && tempBuffer[0] == 0x2d /* - */ { 0305 throw error(.InvalidNumber) 0306 } 0307 tempBuffer.append(0) 0308 let num = tempBuffer.withUnsafeBufferPointer({ ptr -> Int64? in 0309 errno = 0 0310 let n = strtoll(ptr.baseAddress, nil, 10) 0311 if n == 0 && errno != 0 { 0312 return nil 0313 } else { 0314 return n 0315 } 0316 }) 0317 if let num = num { 0318 return .Int64Value(num) 0319 } 0320 // out of range, fall back to Double 0321 return .DoubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)})) 0322 case "t": 0323 let line = self.line, column = self.column 0324 guard case "r"? = bump(), case "u"? = bump(), case "e"? = bump() else { 0325 throw JSONParserError(code: .InvalidSyntax, line: line, column: column) 0326 } 0327 return .BooleanValue(true) 0328 case "f": 0329 let line = self.line, column = self.column 0330 guard case "a"? = bump(), case "l"? = bump(), case "s"? = bump(), case "e"? = bump() else { 0331 throw JSONParserError(code: .InvalidSyntax, line: line, column: column) 0332 } 0333 return .BooleanValue(false) 0334 case "n": 0335 let line = self.line, column = self.column 0336 guard case "u"? = bump(), case "l"? = bump(), case "l"? = bump() else { 0337 throw JSONParserError(code: .InvalidSyntax, line: line, column: column) 0338 } 0339 return .NullValue 0340 default: 0341 throw error(.InvalidSyntax) 0342 } 0343 } 0344 0345 private mutating func skipWhitespace
Parser.swift:53
                    switch skipWhitespace() {
Parser.swift:66
                    switch skipWhitespace() {
Parser.swift:79
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:89
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:110
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:131
                    guard skipWhitespace() == ":" else { throw error(.ExpectedColon) }
Parser.swift:132
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:147
                    if skipWhitespace() != nil {
() -> UnicodeScalar? { 0346 while let c = bump() { 0347 switch c { 0348 case " ", "\t", "\n", "\r": continue 0349 default: return c 0350 } 0351 } 0352 return nil 0353 } 0354 0355 private mutating func parseFourHex
Parser.swift:204
                        let codeUnit = try parseFourHex()
Parser.swift:209
                            let trail = try parseFourHex()
() throws -> UInt16 { 0356 var codepoint: UInt32 = 0 0357 for _ in 0..<4 { 0358 let c = try bumpRequired() 0359 codepoint <<= 4 0360 switch c { 0361 case "0"..."9": 0362 codepoint += c.value - 48 0363 case "a"..."f": 0364 codepoint += c.value - 87 0365 case "A"..."F": 0366 codepoint += c.value - 55 0367 default: 0368 throw error(.InvalidEscape) 0369 } 0370 } 0371 return UInt16(truncatingBitPattern: codepoint) 0372 } 0373 0374 @inline(__always) private mutating func bump
Parser.swift:190
            while let c = bump() {
Parser.swift:244
                    bump()
Parser.swift:247
                    bump()
Parser.swift:249
                    guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) }
Parser.swift:254
                            bump()
Parser.swift:257
                            bump()
Parser.swift:259
                            guard let c = bump() else { throw error(.InvalidNumber) }
Parser.swift:263
                                guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) }
Parser.swift:271
                                    bump()
Parser.swift:285
                    bump()
Parser.swift:287
                    guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) }
Parser.swift:292
                            bump()
Parser.swift:324
            guard case "r"? = bump(), case "u"? = bump(), case "e"? = bump() else {
Parser.swift:324
            guard case "r"? = bump(), case "u"? = bump(), case "e"? = bump() else {
Parser.swift:324
            guard case "r"? = bump(), case "u"? = bump(), case "e"? = bump() else {
Parser.swift:330
            guard case "a"? = bump(), case "l"? = bump(), case "s"? = bump(), case "e"? = bump() else {
Parser.swift:330
            guard case "a"? = bump(), case "l"? = bump(), case "s"? = bump(), case "e"? = bump() else {
Parser.swift:330
            guard case "a"? = bump(), case "l"? = bump(), case "s"? = bump(), case "e"? = bump() else {
Parser.swift:330
            guard case "a"? = bump(), case "l"? = bump(), case "s"? = bump(), case "e"? = bump() else {
Parser.swift:336
            guard case "u"? = bump(), case "l"? = bump(), case "l"? = bump() else {
Parser.swift:336
            guard case "u"? = bump(), case "l"? = bump(), case "l"? = bump() else {
Parser.swift:336
            guard case "u"? = bump(), case "l"? = bump(), case "l"? = bump() else {
Parser.swift:346
        while let c = bump() {
Parser.swift:386
        guard let c = bump() else { throw error(.UnexpectedEOF) }
() -> UnicodeScalar? { 0375 let c = base.next() 0376 if c == "\n" { 0377 line += 1 0378 column = 0 0379 } else { 0380 column += 1 0381 } 0382 return c 0383 } 0384 0385 @inline(__always) private mutating func bumpRequired
Parser.swift:195
                    let c = try bumpRequired()
Parser.swift:206
                            guard try (bumpRequired() == "\\" && bumpRequired() == "u") else {
Parser.swift:206
                            guard try (bumpRequired() == "\\" && bumpRequired() == "u") else {
Parser.swift:358
            let c = try bumpRequired()
() throws -> UnicodeScalar { 0386 guard let c = bump() else { throw error(.UnexpectedEOF) } 0387 return c 0388 } 0389 0390 private func error
Parser.swift:61
                        throw error(.InvalidSyntax)
Parser.swift:63
                        throw error(.UnexpectedEOF)
Parser.swift:74
                        throw error(.InvalidSyntax)
Parser.swift:76
                        throw error(.UnexpectedEOF)
Parser.swift:79
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:89
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:93
                            throw error(.TrailingComma)
Parser.swift:98
                        throw error(.MissingValue)
Parser.swift:110
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:114
                            throw error(.TrailingComma)
Parser.swift:119
                        throw error(.MissingKey)
Parser.swift:126
                            throw error(.NonStringKey)
Parser.swift:131
                    guard skipWhitespace() == ":" else { throw error(.ExpectedColon) }
Parser.swift:132
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:135
                        throw error(.MissingValue)
Parser.swift:148
                        throw error(.TrailingCharacters)
Parser.swift:207
                                throw error(.LoneLeadingSurrogateInUnicodeEscape)
Parser.swift:215
                                throw error(.LoneLeadingSurrogateInUnicodeEscape)
Parser.swift:221
                        throw error(.InvalidEscape)
Parser.swift:224
                    throw error(.InvalidSyntax)
Parser.swift:229
            throw error(.UnexpectedEOF)
Parser.swift:249
                    guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) }
Parser.swift:259
                            guard let c = bump() else { throw error(.InvalidNumber) }
Parser.swift:263
                                guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) }
Parser.swift:266
                            default: throw error(.InvalidNumber)
Parser.swift:287
                    guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) }
Parser.swift:305
                throw error(.InvalidNumber)
Parser.swift:341
            throw error(.InvalidSyntax)
Parser.swift:368
                throw error(.InvalidEscape)
Parser.swift:386
        guard let c = bump() else { throw error(.UnexpectedEOF) }
(code: JSONParserError.Code) -> JSONParserError { 0391 return JSONParserError(code: code, line: line, column: column) 0392 } 0393 0394 /// The line of the last emitted token. 0395 public private(set) var line
Parser.swift:323
            let line = self.line, column = self.column
Parser.swift:329
            let line = self.line, column = self.column
Parser.swift:335
            let line = self.line, column = self.column
Parser.swift:377
            line += 1
Parser.swift:391
        return JSONParserError(code: code, line: line, column: column)
: UInt = 0 0396 /// The column of the last emitted token. 0397 public private(set) var column
Parser.swift:323
            let line = self.line, column = self.column
Parser.swift:329
            let line = self.line, column = self.column
Parser.swift:335
            let line = self.line, column = self.column
Parser.swift:378
            column = 0
Parser.swift:380
            column += 1
Parser.swift:391
        return JSONParserError(code: code, line: line, column: column)
: UInt = 0 0398 0399 private var base
Parser.swift:41
        base = PeekGenerator(gen)
Parser.swift:241
            outerLoop: while let c = base.peek() {
Parser.swift:251
                    loop: while let c = base.peek() {
Parser.swift:268
                            while let c = base.peek() {
Parser.swift:289
                    loop: while let c = base.peek() {
Parser.swift:375
        let c = base.next()
: PeekGenerator<Gen> 0400 private var state
Parser.swift:51
                switch state {
Parser.swift:55
                        state = .ParseArray(first: false)
Parser.swift:68
                        state = .ParseObjectKey(first: false)
Parser.swift:85
                        state = .ParseEnd
Parser.swift:105
                            state = .ParseArrayComma
Parser.swift:124
                            state = .ParseObjectValue
Parser.swift:142
                            state = .ParseObjectComma
Parser.swift:150
                    state = .Finished
Parser.swift:157
            state = .Finished
Parser.swift:170
            state = .ParseArrayComma
Parser.swift:172
            state = .ParseObjectComma
Parser.swift:174
            state = .ParseEnd
Parser.swift:181
            state = .ParseArray(first: true)
Parser.swift:185
            state = .ParseObjectKey(first: true)
: State = .Initial 0401 private var stack
Parser.swift:165
        if stack.popLast() == nil {
Parser.swift:168
        switch stack.last {
Parser.swift:182
            stack.append(.Array)
Parser.swift:186
            stack.append(.Object)
: [Stack] = [] 0402 private var tempBuffer
Parser.swift:232
            if let buffer = replace(&self.tempBuffer, with: nil) {
Parser.swift:239
            defer { self.tempBuffer = tempBuffer }
: ContiguousArray<Int8>? 0403 } 0404 0405 private enum State
Parser.swift:400
    private var state: State = .Initial
{ 0406 /// Initial state 0407 case Initial
Parser.swift:78
                case .Initial:
Parser.swift:400
    private var state: State = .Initial
0408 /// Parse an element or the end of the array 0409 case ParseArray
Parser.swift:55
                        state = .ParseArray(first: false)
Parser.swift:88
                case .ParseArray(let first):
Parser.swift:181
            state = .ParseArray(first: true)
(first: Bool) 0410 /// Parse a comma or the end of the array 0411 case ParseArrayComma
Parser.swift:52
                case .ParseArrayComma:
Parser.swift:105
                            state = .ParseArrayComma
Parser.swift:170
            state = .ParseArrayComma
0412 /// Parse an object key or the end of the array 0413 case ParseObjectKey
Parser.swift:68
                        state = .ParseObjectKey(first: false)
Parser.swift:109
                case .ParseObjectKey(let first):
Parser.swift:185
            state = .ParseObjectKey(first: true)
(first: Bool) 0414 /// Parse a colon followed by an object value 0415 case ParseObjectValue
Parser.swift:124
                            state = .ParseObjectValue
Parser.swift:130
                case .ParseObjectValue:
0416 /// Parse a comma or the end of the object 0417 case ParseObjectComma
Parser.swift:65
                case .ParseObjectComma:
Parser.swift:142
                            state = .ParseObjectComma
Parser.swift:172
            state = .ParseObjectComma
0418 /// Parse whitespace or EOF 0419 case ParseEnd
Parser.swift:85
                        state = .ParseEnd
Parser.swift:146
                case .ParseEnd:
Parser.swift:174
            state = .ParseEnd
0420 /// Parsing has completed 0421 case Finished
Parser.swift:150
                    state = .Finished
Parser.swift:152
                case .Finished:
Parser.swift:157
            state = .Finished
0422 } 0423 0424 private enum Stack
Parser.swift:401
    private var stack: [Stack] = []
{ 0425 case Array
Parser.swift:169
        case .Array?:
Parser.swift:182
            stack.append(.Array)
0426 case Object
Parser.swift:171
        case .Object?:
Parser.swift:186
            stack.append(.Object)
0427 } 0428 0429 /// A streaming JSON parser event. 0430 public enum JSONEvent
Decoder.swift:114
    private var token: JSONEvent?
Parser.swift:46
    public mutating func next() -> JSONEvent? {
Parser.swift:178
    private mutating func parseValue(c: UnicodeScalar) throws -> JSONEvent {
{ 0431 /// The start of an object. 0432 /// Inside of an object, each key/value pair is emitted as a 0433 /// `StringValue` for the key followed by the `JSONEvent` sequence 0434 /// that describes the value. 0435 case ObjectStart
Decoder.swift:63
        case .ObjectStart?: return try buildObject()
Parser.swift:82
                    case .ArrayStart, .ObjectStart:
Parser.swift:102
                        case .ArrayStart, .ObjectStart:
Parser.swift:139
                        case .ArrayStart, .ObjectStart:
Parser.swift:187
            return .ObjectStart
0436 /// The end of an object. 0437 case ObjectEnd
Decoder.swift:64
        case .ObjectEnd?: throw error(.InvalidSyntax)
Decoder.swift:84
            case .ObjectEnd: return .Object(JSONObject(dict))
Parser.swift:72
                        return .ObjectEnd
Parser.swift:117
                        return .ObjectEnd
0438 /// The start of an array. 0439 case ArrayStart
Decoder.swift:65
        case .ArrayStart?: return try buildArray()
Parser.swift:82
                    case .ArrayStart, .ObjectStart:
Parser.swift:102
                        case .ArrayStart, .ObjectStart:
Parser.swift:139
                        case .ArrayStart, .ObjectStart:
Parser.swift:183
            return .ArrayStart
0440 /// The end of an array. 0441 case ArrayEnd
Decoder.swift:66
        case .ArrayEnd?: throw error(.InvalidSyntax)
Decoder.swift:100
            if case .ArrayEnd = token {
Parser.swift:59
                        return .ArrayEnd
Parser.swift:96
                        return .ArrayEnd
0442 /// A boolean value. 0443 case BooleanValue
Decoder.swift:67
        case .BooleanValue(let b)?: return .Bool(b)
Parser.swift:327
            return .BooleanValue(true)
Parser.swift:333
            return .BooleanValue(false)
(Bool) 0444 /// A signed 64-bit integral value. 0445 case Int64Value
Decoder.swift:68
        case .Int64Value(let i)?: return .Int64(i)
Parser.swift:318
                return .Int64Value(num)
(Int64) 0446 /// A double value. 0447 case DoubleValue
Decoder.swift:69
        case .DoubleValue(let d)?: return .Double(d)
Parser.swift:283
                    return .DoubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)}))
Parser.swift:299
                    return .DoubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)}))
Parser.swift:321
            return .DoubleValue(tempBuffer.withUnsafeBufferPointer({strtod($0.baseAddress, nil)}))
(Double) 0448 /// A string value. 0449 case StringValue
Decoder.swift:70
        case .StringValue(let s)?: return .String(s)
Decoder.swift:86
            case .StringValue(let s): key = s
Parser.swift:123
                        case .StringValue:
Parser.swift:193
                    return .StringValue(s)
(String) 0450 /// The null value. 0451 case NullValue
Decoder.swift:71
        case .NullValue?: return .Null
Parser.swift:339
            return .NullValue
0452 /// A parser error. 0453 case Error
Decoder.swift:51
        case .Some(.Error(let err)): throw err
Decoder.swift:72
        case .Error(let err)?: throw err
Decoder.swift:85
            case .Error(let err): throw err
Parser.swift:158
            return .Error(error)
(JSONParserError) 0454 } 0455 0456 /// A generator of `JSONEvent`s that records column/line info. 0457 public protocol JSONEventGenerator
Parser.swift:39
public struct JSONParserGenerator<Gen: GeneratorType where Gen.Element == UnicodeScalar>: JSONEventGenerator {
: GeneratorType { 0458 /// The line of the last emitted token. 0459 var line
Decoder.swift:110
        return JSONParserError(code: code, line: gen.line, column: gen.column)
: UInt { get } 0460 /// The column of the last emitted token. 0461 var column
Decoder.swift:110
        return JSONParserError(code: code, line: gen.line, column: gen.column)
: UInt { get } 0462 } 0463 0464 public struct JSONParserError
Decoder.swift:109
    private func error(code: JSONParserError.Code) -> JSONParserError {
Decoder.swift:109
    private func error(code: JSONParserError.Code) -> JSONParserError {
Decoder.swift:110
        return JSONParserError(code: code, line: gen.line, column: gen.column)
Parser.swift:156
        } catch let error as JSONParserError {
Parser.swift:325
                throw JSONParserError(code: .InvalidSyntax, line: line, column: column)
Parser.swift:331
                throw JSONParserError(code: .InvalidSyntax, line: line, column: column)
Parser.swift:337
                throw JSONParserError(code: .InvalidSyntax, line: line, column: column)
Parser.swift:390
    private func error(code: JSONParserError.Code) -> JSONParserError {
Parser.swift:390
    private func error(code: JSONParserError.Code) -> JSONParserError {
Parser.swift:391
        return JSONParserError(code: code, line: line, column: column)
Parser.swift:453
    case Error(JSONParserError)
: ErrorType, CustomStringConvertible { 0465 public let code
Parser.swift:470
        self.code = code
Parser.swift:475
    public var _code: Int { return code.rawValue }
Parser.swift:509
        return "JSONParserError(\(code), line: \(line), column: \(column))"
: Code 0466 public let line
Parser.swift:471
        self.line = line
Parser.swift:509
        return "JSONParserError(\(code), line: \(line), column: \(column))"
: UInt 0467 public let column
Parser.swift:472
        self.column = column
Parser.swift:509
        return "JSONParserError(\(code), line: \(line), column: \(column))"
: UInt 0468 0469 public init
Decoder.swift:110
        return JSONParserError(code: code, line: gen.line, column: gen.column)
Parser.swift:325
                throw JSONParserError(code: .InvalidSyntax, line: line, column: column)
Parser.swift:331
                throw JSONParserError(code: .InvalidSyntax, line: line, column: column)
Parser.swift:337
                throw JSONParserError(code: .InvalidSyntax, line: line, column: column)
Parser.swift:391
        return JSONParserError(code: code, line: line, column: column)
(code: Code, line: UInt, column: UInt) { 0470 self.code = code 0471 self.line = line 0472 self.column = column 0473 } 0474 0475 public var _code: Int { return code.rawValue } 0476 0477 public enum Code
Decoder.swift:109
    private func error(code: JSONParserError.Code) -> JSONParserError {
Parser.swift:390
    private func error(code: JSONParserError.Code) -> JSONParserError {
Parser.swift:465
    public let code: Code
Parser.swift:469
    public init(code: Code, line: UInt, column: UInt) {
: Int { 0478 /// A generic syntax error. 0479 case InvalidSyntax
Decoder.swift:64
        case .ObjectEnd?: throw error(.InvalidSyntax)
Decoder.swift:66
        case .ArrayEnd?: throw error(.InvalidSyntax)
Parser.swift:61
                        throw error(.InvalidSyntax)
Parser.swift:74
                        throw error(.InvalidSyntax)
Parser.swift:224
                    throw error(.InvalidSyntax)
Parser.swift:325
                throw JSONParserError(code: .InvalidSyntax, line: line, column: column)
Parser.swift:331
                throw JSONParserError(code: .InvalidSyntax, line: line, column: column)
Parser.swift:337
                throw JSONParserError(code: .InvalidSyntax, line: line, column: column)
Parser.swift:341
            throw error(.InvalidSyntax)
0480 /// An invalid number. 0481 case InvalidNumber
Parser.swift:249
                    guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) }
Parser.swift:259
                            guard let c = bump() else { throw error(.InvalidNumber) }
Parser.swift:263
                                guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) }
Parser.swift:266
                            default: throw error(.InvalidNumber)
Parser.swift:287
                    guard let c = bump(), case "0"..."9" = c else { throw error(.InvalidNumber) }
Parser.swift:305
                throw error(.InvalidNumber)
0482 /// An invalid string escape. 0483 case InvalidEscape
Parser.swift:221
                        throw error(.InvalidEscape)
Parser.swift:368
                throw error(.InvalidEscape)
0484 /// A unicode string escape with an invalid code point. 0485 case InvalidUnicodeScalar 0486 /// A unicode string escape representing a leading surrogate without 0487 /// a corresponding trailing surrogate. 0488 case LoneLeadingSurrogateInUnicodeEscape
Parser.swift:207
                                throw error(.LoneLeadingSurrogateInUnicodeEscape)
Parser.swift:215
                                throw error(.LoneLeadingSurrogateInUnicodeEscape)
0489 /// A control character in a string. 0490 case ControlCharacterInString 0491 /// A comma was found where a colon was expected in an object. 0492 case ExpectedColon
Parser.swift:131
                    guard skipWhitespace() == ":" else { throw error(.ExpectedColon) }
0493 /// A comma or colon was found in an object without a key. 0494 case MissingKey
Parser.swift:119
                        throw error(.MissingKey)
0495 /// An object key was found that was not a string. 0496 case NonStringKey
Decoder.swift:87
            default: throw error(.NonStringKey)
Parser.swift:126
                            throw error(.NonStringKey)
0497 /// A comma or object end was encountered where a value was expected. 0498 case MissingValue
Parser.swift:98
                        throw error(.MissingValue)
Parser.swift:135
                        throw error(.MissingValue)
0499 /// A trailing comma was found in an array or object. Only emitted when `strict` mode is enabled. 0500 case TrailingComma
Parser.swift:93
                            throw error(.TrailingComma)
Parser.swift:114
                            throw error(.TrailingComma)
0501 /// Trailing (non-whitespace) characters found after the close 0502 /// of the root value. 0503 case TrailingCharacters
Parser.swift:148
                        throw error(.TrailingCharacters)
0504 /// EOF was found before the root value finished parsing. 0505 case UnexpectedEOF
Decoder.swift:73
        case nil: throw error(.UnexpectedEOF)
Decoder.swift:93
        throw error(.UnexpectedEOF)
Decoder.swift:106
        throw error(.UnexpectedEOF)
Parser.swift:63
                        throw error(.UnexpectedEOF)
Parser.swift:76
                        throw error(.UnexpectedEOF)
Parser.swift:79
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:89
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:110
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:132
                    guard let c = skipWhitespace() else { throw error(.UnexpectedEOF) }
Parser.swift:229
            throw error(.UnexpectedEOF)
Parser.swift:386
        guard let c = bump() else { throw error(.UnexpectedEOF) }
0506 } 0507 0508 public var description: String { 0509 return "JSONParserError(\(code), line: \(line), column: \(column))" 0510 } 0511 } 0512 0513 private struct PeekGenerator
Parser.swift:41
        base = PeekGenerator(gen)
Parser.swift:399
    private var base: PeekGenerator<Gen>
<Base
Parser.swift:514
    init(_ base: Base) {
Parser.swift:518
    mutating func peek() -> Base.Element? {
Parser.swift:527
    mutating func next() -> Base.Element? {
Parser.swift:535
    private var base: Base
Parser.swift:536
    private var peeked: Base.Element??
: GeneratorType> { 0514 init
Parser.swift:41
        base = PeekGenerator(gen)
(_ base: Base) { 0515 self.base = base 0516 } 0517 0518 mutating func peek
Parser.swift:241
            outerLoop: while let c = base.peek() {
Parser.swift:251
                    loop: while let c = base.peek() {
Parser.swift:268
                            while let c = base.peek() {
Parser.swift:289
                    loop: while let c = base.peek() {
() -> Base.Element? { 0519 if let elt = peeked { 0520 return elt 0521 } 0522 let elt = base.next() 0523 peeked = .Some(elt) 0524 return elt 0525 } 0526 0527 mutating func next
Parser.swift:375
        let c = base.next()
() -> Base.Element? { 0528 if let elt = peeked { 0529 peeked = nil 0530 return elt 0531 } 0532 return base.next() 0533 } 0534 0535 private var base
Parser.swift:515
        self.base = base
Parser.swift:522
        let elt = base.next()
Parser.swift:532
        return base.next()
: Base 0536 private var peeked
Parser.swift:519
        if let elt = peeked {
Parser.swift:523
        peeked = .Some(elt)
Parser.swift:528
        if let elt = peeked {
Parser.swift:529
            peeked = nil
: Base.Element?? 0537 } 0538 0539 private func replace
Parser.swift:232
            if let buffer = replace(&self.tempBuffer, with: nil) {
<T>(inout a: T, with b: T) -> T { 0540 var b = b 0541 swap(&a, &b) 0542 return b 0543 } 0544