| ... | @@ -84,11 +84,11 @@ pub const StreamingParser = struct { | ... | @@ -84,11 +84,11 @@ pub const StreamingParser = struct { |
| 84 | } | 84 | } |
| 85 | | 85 | |
| 86 | pub fn reset(p: *StreamingParser) void { | 86 | pub fn reset(p: *StreamingParser) void { |
| 87 | p.state = State.TopLevelBegin; | 87 | p.state = .TopLevelBegin; |
| 88 | p.count = 0; | 88 | p.count = 0; |
| 89 | // Set before ever read in main transition function | 89 | // Set before ever read in main transition function |
| 90 | p.after_string_state = undefined; | 90 | p.after_string_state = undefined; |
| 91 | p.after_value_state = State.ValueEnd; // handle end of values normally | 91 | p.after_value_state = .ValueEnd; // handle end of values normally |
| 92 | p.stack = 0; | 92 | p.stack = 0; |
| 93 | p.stack_used = 0; | 93 | p.stack_used = 0; |
| 94 | p.complete = false; | 94 | p.complete = false; |
| ... | @@ -187,14 +187,14 @@ pub const StreamingParser = struct { | ... | @@ -187,14 +187,14 @@ pub const StreamingParser = struct { |
| 187 | // Perform a single transition on the state machine and return any possible token. | 187 | // Perform a single transition on the state machine and return any possible token. |
| 188 | fn transition(p: *StreamingParser, c: u8, token: *?Token) Error!bool { | 188 | fn transition(p: *StreamingParser, c: u8, token: *?Token) Error!bool { |
| 189 | switch (p.state) { | 189 | switch (p.state) { |
| 190 | State.TopLevelBegin => switch (c) { | 190 | .TopLevelBegin => switch (c) { |
| 191 | '{' => { | 191 | '{' => { |
| 192 | p.stack <<= 1; | 192 | p.stack <<= 1; |
| 193 | p.stack |= object_bit; | 193 | p.stack |= object_bit; |
| 194 | p.stack_used += 1; | 194 | p.stack_used += 1; |
| 195 | | 195 | |
| 196 | p.state = State.ValueBegin; | 196 | p.state = .ValueBegin; |
| 197 | p.after_string_state = State.ObjectSeparator; | 197 | p.after_string_state = .ObjectSeparator; |
| 198 | | 198 | |
| 199 | token.* = Token.ObjectBegin; | 199 | token.* = Token.ObjectBegin; |
| 200 | }, | 200 | }, |
| ... | @@ -203,50 +203,50 @@ pub const StreamingParser = struct { | ... | @@ -203,50 +203,50 @@ pub const StreamingParser = struct { |
| 203 | p.stack |= array_bit; | 203 | p.stack |= array_bit; |
| 204 | p.stack_used += 1; | 204 | p.stack_used += 1; |
| 205 | | 205 | |
| 206 | p.state = State.ValueBegin; | 206 | p.state = .ValueBegin; |
| 207 | p.after_string_state = State.ValueEnd; | 207 | p.after_string_state = .ValueEnd; |
| 208 | | 208 | |
| 209 | token.* = Token.ArrayBegin; | 209 | token.* = Token.ArrayBegin; |
| 210 | }, | 210 | }, |
| 211 | '-' => { | 211 | '-' => { |
| 212 | p.number_is_integer = true; | 212 | p.number_is_integer = true; |
| 213 | p.state = State.Number; | 213 | p.state = .Number; |
| 214 | p.after_value_state = State.TopLevelEnd; | 214 | p.after_value_state = .TopLevelEnd; |
| 215 | p.count = 0; | 215 | p.count = 0; |
| 216 | }, | 216 | }, |
| 217 | '0' => { | 217 | '0' => { |
| 218 | p.number_is_integer = true; | 218 | p.number_is_integer = true; |
| 219 | p.state = State.NumberMaybeDotOrExponent; | 219 | p.state = .NumberMaybeDotOrExponent; |
| 220 | p.after_value_state = State.TopLevelEnd; | 220 | p.after_value_state = .TopLevelEnd; |
| 221 | p.count = 0; | 221 | p.count = 0; |
| 222 | }, | 222 | }, |
| 223 | '1'...'9' => { | 223 | '1'...'9' => { |
| 224 | p.number_is_integer = true; | 224 | p.number_is_integer = true; |
| 225 | p.state = State.NumberMaybeDigitOrDotOrExponent; | 225 | p.state = .NumberMaybeDigitOrDotOrExponent; |
| 226 | p.after_value_state = State.TopLevelEnd; | 226 | p.after_value_state = .TopLevelEnd; |
| 227 | p.count = 0; | 227 | p.count = 0; |
| 228 | }, | 228 | }, |
| 229 | '"' => { | 229 | '"' => { |
| 230 | p.state = State.String; | 230 | p.state = .String; |
| 231 | p.after_value_state = State.TopLevelEnd; | 231 | p.after_value_state = .TopLevelEnd; |
| 232 | // We don't actually need the following since after_value_state should override. | 232 | // We don't actually need the following since after_value_state should override. |
| 233 | p.after_string_state = State.ValueEnd; | 233 | p.after_string_state = .ValueEnd; |
| 234 | p.string_has_escape = false; | 234 | p.string_has_escape = false; |
| 235 | p.count = 0; | 235 | p.count = 0; |
| 236 | }, | 236 | }, |
| 237 | 't' => { | 237 | 't' => { |
| 238 | p.state = State.TrueLiteral1; | 238 | p.state = .TrueLiteral1; |
| 239 | p.after_value_state = State.TopLevelEnd; | 239 | p.after_value_state = .TopLevelEnd; |
| 240 | p.count = 0; | 240 | p.count = 0; |
| 241 | }, | 241 | }, |
| 242 | 'f' => { | 242 | 'f' => { |
| 243 | p.state = State.FalseLiteral1; | 243 | p.state = .FalseLiteral1; |
| 244 | p.after_value_state = State.TopLevelEnd; | 244 | p.after_value_state = .TopLevelEnd; |
| 245 | p.count = 0; | 245 | p.count = 0; |
| 246 | }, | 246 | }, |
| 247 | 'n' => { | 247 | 'n' => { |
| 248 | p.state = State.NullLiteral1; | 248 | p.state = .NullLiteral1; |
| 249 | p.after_value_state = State.TopLevelEnd; | 249 | p.after_value_state = .TopLevelEnd; |
| 250 | p.count = 0; | 250 | p.count = 0; |
| 251 | }, | 251 | }, |
| 252 | 0x09, 0x0A, 0x0D, 0x20 => { | 252 | 0x09, 0x0A, 0x0D, 0x20 => { |
| ... | @@ -257,7 +257,7 @@ pub const StreamingParser = struct { | ... | @@ -257,7 +257,7 @@ pub const StreamingParser = struct { |
| 257 | }, | 257 | }, |
| 258 | }, | 258 | }, |
| 259 | | 259 | |
| 260 | State.TopLevelEnd => switch (c) { | 260 | .TopLevelEnd => switch (c) { |
| 261 | 0x09, 0x0A, 0x0D, 0x20 => { | 261 | 0x09, 0x0A, 0x0D, 0x20 => { |
| 262 | // whitespace | 262 | // whitespace |
| 263 | }, | 263 | }, |
| ... | @@ -266,7 +266,7 @@ pub const StreamingParser = struct { | ... | @@ -266,7 +266,7 @@ pub const StreamingParser = struct { |
| 266 | }, | 266 | }, |
| 267 | }, | 267 | }, |
| 268 | | 268 | |
| 269 | State.ValueBegin => switch (c) { | 269 | .ValueBegin => switch (c) { |
| 270 | // NOTE: These are shared in ValueEnd as well, think we can reorder states to | 270 | // NOTE: These are shared in ValueEnd as well, think we can reorder states to |
| 271 | // be a bit clearer and avoid this duplication. | 271 | // be a bit clearer and avoid this duplication. |
| 272 | '}' => { | 272 | '}' => { |
| ... | @@ -278,7 +278,7 @@ pub const StreamingParser = struct { | ... | @@ -278,7 +278,7 @@ pub const StreamingParser = struct { |
| 278 | return error.TooManyClosingItems; | 278 | return error.TooManyClosingItems; |
| 279 | } | 279 | } |
| 280 | | 280 | |
| 281 | p.state = State.ValueBegin; | 281 | p.state = .ValueBegin; |
| 282 | p.after_string_state = State.fromInt(p.stack & 1); | 282 | p.after_string_state = State.fromInt(p.stack & 1); |
| 283 | | 283 | |
| 284 | p.stack >>= 1; | 284 | p.stack >>= 1; |
| ... | @@ -287,10 +287,10 @@ pub const StreamingParser = struct { | ... | @@ -287,10 +287,10 @@ pub const StreamingParser = struct { |
| 287 | switch (p.stack_used) { | 287 | switch (p.stack_used) { |
| 288 | 0 => { | 288 | 0 => { |
| 289 | p.complete = true; | 289 | p.complete = true; |
| 290 | p.state = State.TopLevelEnd; | 290 | p.state = .TopLevelEnd; |
| 291 | }, | 291 | }, |
| 292 | else => { | 292 | else => { |
| 293 | p.state = State.ValueEnd; | 293 | p.state = .ValueEnd; |
| 294 | }, | 294 | }, |
| 295 | } | 295 | } |
| 296 | | 296 | |
| ... | @@ -304,7 +304,7 @@ pub const StreamingParser = struct { | ... | @@ -304,7 +304,7 @@ pub const StreamingParser = struct { |
| 304 | return error.TooManyClosingItems; | 304 | return error.TooManyClosingItems; |
| 305 | } | 305 | } |
| 306 | | 306 | |
| 307 | p.state = State.ValueBegin; | 307 | p.state = .ValueBegin; |
| 308 | p.after_string_state = State.fromInt(p.stack & 1); | 308 | p.after_string_state = State.fromInt(p.stack & 1); |
| 309 | | 309 | |
| 310 | p.stack >>= 1; | 310 | p.stack >>= 1; |
| ... | @@ -313,10 +313,10 @@ pub const StreamingParser = struct { | ... | @@ -313,10 +313,10 @@ pub const StreamingParser = struct { |
| 313 | switch (p.stack_used) { | 313 | switch (p.stack_used) { |
| 314 | 0 => { | 314 | 0 => { |
| 315 | p.complete = true; | 315 | p.complete = true; |
| 316 | p.state = State.TopLevelEnd; | 316 | p.state = .TopLevelEnd; |
| 317 | }, | 317 | }, |
| 318 | else => { | 318 | else => { |
| 319 | p.state = State.ValueEnd; | 319 | p.state = .ValueEnd; |
| 320 | }, | 320 | }, |
| 321 | } | 321 | } |
| 322 | | 322 | |
| ... | @@ -331,8 +331,8 @@ pub const StreamingParser = struct { | ... | @@ -331,8 +331,8 @@ pub const StreamingParser = struct { |
| 331 | p.stack |= object_bit; | 331 | p.stack |= object_bit; |
| 332 | p.stack_used += 1; | 332 | p.stack_used += 1; |
| 333 | | 333 | |
| 334 | p.state = State.ValueBegin; | 334 | p.state = .ValueBegin; |
| 335 | p.after_string_state = State.ObjectSeparator; | 335 | p.after_string_state = .ObjectSeparator; |
| 336 | | 336 | |
| 337 | token.* = Token.ObjectBegin; | 337 | token.* = Token.ObjectBegin; |
| 338 | }, | 338 | }, |
| ... | @@ -345,40 +345,40 @@ pub const StreamingParser = struct { | ... | @@ -345,40 +345,40 @@ pub const StreamingParser = struct { |
| 345 | p.stack |= array_bit; | 345 | p.stack |= array_bit; |
| 346 | p.stack_used += 1; | 346 | p.stack_used += 1; |
| 347 | | 347 | |
| 348 | p.state = State.ValueBegin; | 348 | p.state = .ValueBegin; |
| 349 | p.after_string_state = State.ValueEnd; | 349 | p.after_string_state = .ValueEnd; |
| 350 | | 350 | |
| 351 | token.* = Token.ArrayBegin; | 351 | token.* = Token.ArrayBegin; |
| 352 | }, | 352 | }, |
| 353 | '-' => { | 353 | '-' => { |
| 354 | p.number_is_integer = true; | 354 | p.number_is_integer = true; |
| 355 | p.state = State.Number; | 355 | p.state = .Number; |
| 356 | p.count = 0; | 356 | p.count = 0; |
| 357 | }, | 357 | }, |
| 358 | '0' => { | 358 | '0' => { |
| 359 | p.number_is_integer = true; | 359 | p.number_is_integer = true; |
| 360 | p.state = State.NumberMaybeDotOrExponent; | 360 | p.state = .NumberMaybeDotOrExponent; |
| 361 | p.count = 0; | 361 | p.count = 0; |
| 362 | }, | 362 | }, |
| 363 | '1'...'9' => { | 363 | '1'...'9' => { |
| 364 | p.number_is_integer = true; | 364 | p.number_is_integer = true; |
| 365 | p.state = State.NumberMaybeDigitOrDotOrExponent; | 365 | p.state = .NumberMaybeDigitOrDotOrExponent; |
| 366 | p.count = 0; | 366 | p.count = 0; |
| 367 | }, | 367 | }, |
| 368 | '"' => { | 368 | '"' => { |
| 369 | p.state = State.String; | 369 | p.state = .String; |
| 370 | p.count = 0; | 370 | p.count = 0; |
| 371 | }, | 371 | }, |
| 372 | 't' => { | 372 | 't' => { |
| 373 | p.state = State.TrueLiteral1; | 373 | p.state = .TrueLiteral1; |
| 374 | p.count = 0; | 374 | p.count = 0; |
| 375 | }, | 375 | }, |
| 376 | 'f' => { | 376 | 'f' => { |
| 377 | p.state = State.FalseLiteral1; | 377 | p.state = .FalseLiteral1; |
| 378 | p.count = 0; | 378 | p.count = 0; |
| 379 | }, | 379 | }, |
| 380 | 'n' => { | 380 | 'n' => { |
| 381 | p.state = State.NullLiteral1; | 381 | p.state = .NullLiteral1; |
| 382 | p.count = 0; | 382 | p.count = 0; |
| 383 | }, | 383 | }, |
| 384 | 0x09, 0x0A, 0x0D, 0x20 => { | 384 | 0x09, 0x0A, 0x0D, 0x20 => { |
| ... | @@ -390,7 +390,7 @@ pub const StreamingParser = struct { | ... | @@ -390,7 +390,7 @@ pub const StreamingParser = struct { |
| 390 | }, | 390 | }, |
| 391 | | 391 | |
| 392 | // TODO: A bit of duplication here and in the following state, redo. | 392 | // TODO: A bit of duplication here and in the following state, redo. |
| 393 | State.ValueBeginNoClosing => switch (c) { | 393 | .ValueBeginNoClosing => switch (c) { |
| 394 | '{' => { | 394 | '{' => { |
| 395 | if (p.stack_used == max_stack_size) { | 395 | if (p.stack_used == max_stack_size) { |
| 396 | return error.TooManyNestedItems; | 396 | return error.TooManyNestedItems; |
| ... | @@ -400,8 +400,8 @@ pub const StreamingParser = struct { | ... | @@ -400,8 +400,8 @@ pub const StreamingParser = struct { |
| 400 | p.stack |= object_bit; | 400 | p.stack |= object_bit; |
| 401 | p.stack_used += 1; | 401 | p.stack_used += 1; |
| 402 | | 402 | |
| 403 | p.state = State.ValueBegin; | 403 | p.state = .ValueBegin; |
| 404 | p.after_string_state = State.ObjectSeparator; | 404 | p.after_string_state = .ObjectSeparator; |
| 405 | | 405 | |
| 406 | token.* = Token.ObjectBegin; | 406 | token.* = Token.ObjectBegin; |
| 407 | }, | 407 | }, |
| ... | @@ -414,40 +414,40 @@ pub const StreamingParser = struct { | ... | @@ -414,40 +414,40 @@ pub const StreamingParser = struct { |
| 414 | p.stack |= array_bit; | 414 | p.stack |= array_bit; |
| 415 | p.stack_used += 1; | 415 | p.stack_used += 1; |
| 416 | | 416 | |
| 417 | p.state = State.ValueBegin; | 417 | p.state = .ValueBegin; |
| 418 | p.after_string_state = State.ValueEnd; | 418 | p.after_string_state = .ValueEnd; |
| 419 | | 419 | |
| 420 | token.* = Token.ArrayBegin; | 420 | token.* = Token.ArrayBegin; |
| 421 | }, | 421 | }, |
| 422 | '-' => { | 422 | '-' => { |
| 423 | p.number_is_integer = true; | 423 | p.number_is_integer = true; |
| 424 | p.state = State.Number; | 424 | p.state = .Number; |
| 425 | p.count = 0; | 425 | p.count = 0; |
| 426 | }, | 426 | }, |
| 427 | '0' => { | 427 | '0' => { |
| 428 | p.number_is_integer = true; | 428 | p.number_is_integer = true; |
| 429 | p.state = State.NumberMaybeDotOrExponent; | 429 | p.state = .NumberMaybeDotOrExponent; |
| 430 | p.count = 0; | 430 | p.count = 0; |
| 431 | }, | 431 | }, |
| 432 | '1'...'9' => { | 432 | '1'...'9' => { |
| 433 | p.number_is_integer = true; | 433 | p.number_is_integer = true; |
| 434 | p.state = State.NumberMaybeDigitOrDotOrExponent; | 434 | p.state = .NumberMaybeDigitOrDotOrExponent; |
| 435 | p.count = 0; | 435 | p.count = 0; |
| 436 | }, | 436 | }, |
| 437 | '"' => { | 437 | '"' => { |
| 438 | p.state = State.String; | 438 | p.state = .String; |
| 439 | p.count = 0; | 439 | p.count = 0; |
| 440 | }, | 440 | }, |
| 441 | 't' => { | 441 | 't' => { |
| 442 | p.state = State.TrueLiteral1; | 442 | p.state = .TrueLiteral1; |
| 443 | p.count = 0; | 443 | p.count = 0; |
| 444 | }, | 444 | }, |
| 445 | 'f' => { | 445 | 'f' => { |
| 446 | p.state = State.FalseLiteral1; | 446 | p.state = .FalseLiteral1; |
| 447 | p.count = 0; | 447 | p.count = 0; |
| 448 | }, | 448 | }, |
| 449 | 'n' => { | 449 | 'n' => { |
| 450 | p.state = State.NullLiteral1; | 450 | p.state = .NullLiteral1; |
| 451 | p.count = 0; | 451 | p.count = 0; |
| 452 | }, | 452 | }, |
| 453 | 0x09, 0x0A, 0x0D, 0x20 => { | 453 | 0x09, 0x0A, 0x0D, 0x20 => { |
| ... | @@ -458,17 +458,17 @@ pub const StreamingParser = struct { | ... | @@ -458,17 +458,17 @@ pub const StreamingParser = struct { |
| 458 | }, | 458 | }, |
| 459 | }, | 459 | }, |
| 460 | | 460 | |
| 461 | State.ValueEnd => switch (c) { | 461 | .ValueEnd => switch (c) { |
| 462 | ',' => { | 462 | ',' => { |
| 463 | p.after_string_state = State.fromInt(p.stack & 1); | 463 | p.after_string_state = State.fromInt(p.stack & 1); |
| 464 | p.state = State.ValueBeginNoClosing; | 464 | p.state = .ValueBeginNoClosing; |
| 465 | }, | 465 | }, |
| 466 | ']' => { | 466 | ']' => { |
| 467 | if (p.stack_used == 0) { | 467 | if (p.stack_used == 0) { |
| 468 | return error.UnbalancedBrackets; | 468 | return error.UnbalancedBrackets; |
| 469 | } | 469 | } |
| 470 | | 470 | |
| 471 | p.state = State.ValueEnd; | 471 | p.state = .ValueEnd; |
| 472 | p.after_string_state = State.fromInt(p.stack & 1); | 472 | p.after_string_state = State.fromInt(p.stack & 1); |
| 473 | | 473 | |
| 474 | p.stack >>= 1; | 474 | p.stack >>= 1; |
| ... | @@ -476,7 +476,7 @@ pub const StreamingParser = struct { | ... | @@ -476,7 +476,7 @@ pub const StreamingParser = struct { |
| 476 | | 476 | |
| 477 | if (p.stack_used == 0) { | 477 | if (p.stack_used == 0) { |
| 478 | p.complete = true; | 478 | p.complete = true; |
| 479 | p.state = State.TopLevelEnd; | 479 | p.state = .TopLevelEnd; |
| 480 | } | 480 | } |
| 481 | | 481 | |
| 482 | token.* = Token.ArrayEnd; | 482 | token.* = Token.ArrayEnd; |
| ... | @@ -486,7 +486,7 @@ pub const StreamingParser = struct { | ... | @@ -486,7 +486,7 @@ pub const StreamingParser = struct { |
| 486 | return error.UnbalancedBraces; | 486 | return error.UnbalancedBraces; |
| 487 | } | 487 | } |
| 488 | | 488 | |
| 489 | p.state = State.ValueEnd; | 489 | p.state = .ValueEnd; |
| 490 | p.after_string_state = State.fromInt(p.stack & 1); | 490 | p.after_string_state = State.fromInt(p.stack & 1); |
| 491 | | 491 | |
| 492 | p.stack >>= 1; | 492 | p.stack >>= 1; |
| ... | @@ -494,7 +494,7 @@ pub const StreamingParser = struct { | ... | @@ -494,7 +494,7 @@ pub const StreamingParser = struct { |
| 494 | | 494 | |
| 495 | if (p.stack_used == 0) { | 495 | if (p.stack_used == 0) { |
| 496 | p.complete = true; | 496 | p.complete = true; |
| 497 | p.state = State.TopLevelEnd; | 497 | p.state = .TopLevelEnd; |
| 498 | } | 498 | } |
| 499 | | 499 | |
| 500 | token.* = Token.ObjectEnd; | 500 | token.* = Token.ObjectEnd; |
| ... | @@ -507,10 +507,10 @@ pub const StreamingParser = struct { | ... | @@ -507,10 +507,10 @@ pub const StreamingParser = struct { |
| 507 | }, | 507 | }, |
| 508 | }, | 508 | }, |
| 509 | | 509 | |
| 510 | State.ObjectSeparator => switch (c) { | 510 | .ObjectSeparator => switch (c) { |
| 511 | ':' => { | 511 | ':' => { |
| 512 | p.state = State.ValueBegin; | 512 | p.state = .ValueBegin; |
| 513 | p.after_string_state = State.ValueEnd; | 513 | p.after_string_state = .ValueEnd; |
| 514 | }, | 514 | }, |
| 515 | 0x09, 0x0A, 0x0D, 0x20 => { | 515 | 0x09, 0x0A, 0x0D, 0x20 => { |
| 516 | // whitespace | 516 | // whitespace |
| ... | @@ -520,14 +520,14 @@ pub const StreamingParser = struct { | ... | @@ -520,14 +520,14 @@ pub const StreamingParser = struct { |
| 520 | }, | 520 | }, |
| 521 | }, | 521 | }, |
| 522 | | 522 | |
| 523 | State.String => switch (c) { | 523 | .String => switch (c) { |
| 524 | 0x00...0x1F => { | 524 | 0x00...0x1F => { |
| 525 | return error.InvalidControlCharacter; | 525 | return error.InvalidControlCharacter; |
| 526 | }, | 526 | }, |
| 527 | '"' => { | 527 | '"' => { |
| 528 | p.state = p.after_string_state; | 528 | p.state = p.after_string_state; |
| 529 | if (p.after_value_state == State.TopLevelEnd) { | 529 | if (p.after_value_state == .TopLevelEnd) { |
| 530 | p.state = State.TopLevelEnd; | 530 | p.state = .TopLevelEnd; |
| 531 | p.complete = true; | 531 | p.complete = true; |
| 532 | } | 532 | } |
| 533 | | 533 | |
| ... | @@ -539,41 +539,41 @@ pub const StreamingParser = struct { | ... | @@ -539,41 +539,41 @@ pub const StreamingParser = struct { |
| 539 | }; | 539 | }; |
| 540 | }, | 540 | }, |
| 541 | '\\' => { | 541 | '\\' => { |
| 542 | p.state = State.StringEscapeCharacter; | 542 | p.state = .StringEscapeCharacter; |
| 543 | }, | 543 | }, |
| 544 | 0x20, 0x21, 0x23...0x5B, 0x5D...0x7F => { | 544 | 0x20, 0x21, 0x23...0x5B, 0x5D...0x7F => { |
| 545 | // non-control ascii | 545 | // non-control ascii |
| 546 | }, | 546 | }, |
| 547 | 0xC0...0xDF => { | 547 | 0xC0...0xDF => { |
| 548 | p.state = State.StringUtf8Byte1; | 548 | p.state = .StringUtf8Byte1; |
| 549 | }, | 549 | }, |
| 550 | 0xE0...0xEF => { | 550 | 0xE0...0xEF => { |
| 551 | p.state = State.StringUtf8Byte2; | 551 | p.state = .StringUtf8Byte2; |
| 552 | }, | 552 | }, |
| 553 | 0xF0...0xFF => { | 553 | 0xF0...0xFF => { |
| 554 | p.state = State.StringUtf8Byte3; | 554 | p.state = .StringUtf8Byte3; |
| 555 | }, | 555 | }, |
| 556 | else => { | 556 | else => { |
| 557 | return error.InvalidUtf8Byte; | 557 | return error.InvalidUtf8Byte; |
| 558 | }, | 558 | }, |
| 559 | }, | 559 | }, |
| 560 | | 560 | |
| 561 | State.StringUtf8Byte3 => switch (c >> 6) { | 561 | .StringUtf8Byte3 => switch (c >> 6) { |
| 562 | 0b10 => p.state = State.StringUtf8Byte2, | 562 | 0b10 => p.state = .StringUtf8Byte2, |
| 563 | else => return error.InvalidUtf8Byte, | 563 | else => return error.InvalidUtf8Byte, |
| 564 | }, | 564 | }, |
| 565 | | 565 | |
| 566 | State.StringUtf8Byte2 => switch (c >> 6) { | 566 | .StringUtf8Byte2 => switch (c >> 6) { |
| 567 | 0b10 => p.state = State.StringUtf8Byte1, | 567 | 0b10 => p.state = .StringUtf8Byte1, |
| 568 | else => return error.InvalidUtf8Byte, | 568 | else => return error.InvalidUtf8Byte, |
| 569 | }, | 569 | }, |
| 570 | | 570 | |
| 571 | State.StringUtf8Byte1 => switch (c >> 6) { | 571 | .StringUtf8Byte1 => switch (c >> 6) { |
| 572 | 0b10 => p.state = State.String, | 572 | 0b10 => p.state = .String, |
| 573 | else => return error.InvalidUtf8Byte, | 573 | else => return error.InvalidUtf8Byte, |
| 574 | }, | 574 | }, |
| 575 | | 575 | |
| 576 | State.StringEscapeCharacter => switch (c) { | 576 | .StringEscapeCharacter => switch (c) { |
| 577 | // NOTE: '/' is allowed as an escaped character but it also is allowed | 577 | // NOTE: '/' is allowed as an escaped character but it also is allowed |
| 578 | // as unescaped according to the RFC. There is a reported errata which suggests | 578 | // as unescaped according to the RFC. There is a reported errata which suggests |
| 579 | // removing the non-escaped variant but it makes more sense to simply disallow | 579 | // removing the non-escaped variant but it makes more sense to simply disallow |
| ... | @@ -584,53 +584,53 @@ pub const StreamingParser = struct { | ... | @@ -584,53 +584,53 @@ pub const StreamingParser = struct { |
| 584 | // is further clarified. | 584 | // is further clarified. |
| 585 | '"', '\\', '/', 'b', 'f', 'n', 'r', 't' => { | 585 | '"', '\\', '/', 'b', 'f', 'n', 'r', 't' => { |
| 586 | p.string_has_escape = true; | 586 | p.string_has_escape = true; |
| 587 | p.state = State.String; | 587 | p.state = .String; |
| 588 | }, | 588 | }, |
| 589 | 'u' => { | 589 | 'u' => { |
| 590 | p.string_has_escape = true; | 590 | p.string_has_escape = true; |
| 591 | p.state = State.StringEscapeHexUnicode4; | 591 | p.state = .StringEscapeHexUnicode4; |
| 592 | }, | 592 | }, |
| 593 | else => { | 593 | else => { |
| 594 | return error.InvalidEscapeCharacter; | 594 | return error.InvalidEscapeCharacter; |
| 595 | }, | 595 | }, |
| 596 | }, | 596 | }, |
| 597 | | 597 | |
| 598 | State.StringEscapeHexUnicode4 => switch (c) { | 598 | .StringEscapeHexUnicode4 => switch (c) { |
| 599 | '0'...'9', 'A'...'F', 'a'...'f' => { | 599 | '0'...'9', 'A'...'F', 'a'...'f' => { |
| 600 | p.state = State.StringEscapeHexUnicode3; | 600 | p.state = .StringEscapeHexUnicode3; |
| 601 | }, | 601 | }, |
| 602 | else => return error.InvalidUnicodeHexSymbol, | 602 | else => return error.InvalidUnicodeHexSymbol, |
| 603 | }, | 603 | }, |
| 604 | | 604 | |
| 605 | State.StringEscapeHexUnicode3 => switch (c) { | 605 | .StringEscapeHexUnicode3 => switch (c) { |
| 606 | '0'...'9', 'A'...'F', 'a'...'f' => { | 606 | '0'...'9', 'A'...'F', 'a'...'f' => { |
| 607 | p.state = State.StringEscapeHexUnicode2; | 607 | p.state = .StringEscapeHexUnicode2; |
| 608 | }, | 608 | }, |
| 609 | else => return error.InvalidUnicodeHexSymbol, | 609 | else => return error.InvalidUnicodeHexSymbol, |
| 610 | }, | 610 | }, |
| 611 | | 611 | |
| 612 | State.StringEscapeHexUnicode2 => switch (c) { | 612 | .StringEscapeHexUnicode2 => switch (c) { |
| 613 | '0'...'9', 'A'...'F', 'a'...'f' => { | 613 | '0'...'9', 'A'...'F', 'a'...'f' => { |
| 614 | p.state = State.StringEscapeHexUnicode1; | 614 | p.state = .StringEscapeHexUnicode1; |
| 615 | }, | 615 | }, |
| 616 | else => return error.InvalidUnicodeHexSymbol, | 616 | else => return error.InvalidUnicodeHexSymbol, |
| 617 | }, | 617 | }, |
| 618 | | 618 | |
| 619 | State.StringEscapeHexUnicode1 => switch (c) { | 619 | .StringEscapeHexUnicode1 => switch (c) { |
| 620 | '0'...'9', 'A'...'F', 'a'...'f' => { | 620 | '0'...'9', 'A'...'F', 'a'...'f' => { |
| 621 | p.state = State.String; | 621 | p.state = .String; |
| 622 | }, | 622 | }, |
| 623 | else => return error.InvalidUnicodeHexSymbol, | 623 | else => return error.InvalidUnicodeHexSymbol, |
| 624 | }, | 624 | }, |
| 625 | | 625 | |
| 626 | State.Number => { | 626 | .Number => { |
| 627 | p.complete = p.after_value_state == State.TopLevelEnd; | 627 | p.complete = p.after_value_state == .TopLevelEnd; |
| 628 | switch (c) { | 628 | switch (c) { |
| 629 | '0' => { | 629 | '0' => { |
| 630 | p.state = State.NumberMaybeDotOrExponent; | 630 | p.state = .NumberMaybeDotOrExponent; |
| 631 | }, | 631 | }, |
| 632 | '1'...'9' => { | 632 | '1'...'9' => { |
| 633 | p.state = State.NumberMaybeDigitOrDotOrExponent; | 633 | p.state = .NumberMaybeDigitOrDotOrExponent; |
| 634 | }, | 634 | }, |
| 635 | else => { | 635 | else => { |
| 636 | return error.InvalidNumber; | 636 | return error.InvalidNumber; |
| ... | @@ -638,16 +638,16 @@ pub const StreamingParser = struct { | ... | @@ -638,16 +638,16 @@ pub const StreamingParser = struct { |
| 638 | } | 638 | } |
| 639 | }, | 639 | }, |
| 640 | | 640 | |
| 641 | State.NumberMaybeDotOrExponent => { | 641 | .NumberMaybeDotOrExponent => { |
| 642 | p.complete = p.after_value_state == State.TopLevelEnd; | 642 | p.complete = p.after_value_state == .TopLevelEnd; |
| 643 | switch (c) { | 643 | switch (c) { |
| 644 | '.' => { | 644 | '.' => { |
| 645 | p.number_is_integer = false; | 645 | p.number_is_integer = false; |
| 646 | p.state = State.NumberFractionalRequired; | 646 | p.state = .NumberFractionalRequired; |
| 647 | }, | 647 | }, |
| 648 | 'e', 'E' => { | 648 | 'e', 'E' => { |
| 649 | p.number_is_integer = false; | 649 | p.number_is_integer = false; |
| 650 | p.state = State.NumberExponent; | 650 | p.state = .NumberExponent; |
| 651 | }, | 651 | }, |
| 652 | else => { | 652 | else => { |
| 653 | p.state = p.after_value_state; | 653 | p.state = p.after_value_state; |
| ... | @@ -662,16 +662,16 @@ pub const StreamingParser = struct { | ... | @@ -662,16 +662,16 @@ pub const StreamingParser = struct { |
| 662 | } | 662 | } |
| 663 | }, | 663 | }, |
| 664 | | 664 | |
| 665 | State.NumberMaybeDigitOrDotOrExponent => { | 665 | .NumberMaybeDigitOrDotOrExponent => { |
| 666 | p.complete = p.after_value_state == State.TopLevelEnd; | 666 | p.complete = p.after_value_state == .TopLevelEnd; |
| 667 | switch (c) { | 667 | switch (c) { |
| 668 | '.' => { | 668 | '.' => { |
| 669 | p.number_is_integer = false; | 669 | p.number_is_integer = false; |
| 670 | p.state = State.NumberFractionalRequired; | 670 | p.state = .NumberFractionalRequired; |
| 671 | }, | 671 | }, |
| 672 | 'e', 'E' => { | 672 | 'e', 'E' => { |
| 673 | p.number_is_integer = false; | 673 | p.number_is_integer = false; |
| 674 | p.state = State.NumberExponent; | 674 | p.state = .NumberExponent; |
| 675 | }, | 675 | }, |
| 676 | '0'...'9' => { | 676 | '0'...'9' => { |
| 677 | // another digit | 677 | // another digit |
| ... | @@ -689,11 +689,11 @@ pub const StreamingParser = struct { | ... | @@ -689,11 +689,11 @@ pub const StreamingParser = struct { |
| 689 | } | 689 | } |
| 690 | }, | 690 | }, |
| 691 | | 691 | |
| 692 | State.NumberFractionalRequired => { | 692 | .NumberFractionalRequired => { |
| 693 | p.complete = p.after_value_state == State.TopLevelEnd; | 693 | p.complete = p.after_value_state == .TopLevelEnd; |
| 694 | switch (c) { | 694 | switch (c) { |
| 695 | '0'...'9' => { | 695 | '0'...'9' => { |
| 696 | p.state = State.NumberFractional; | 696 | p.state = .NumberFractional; |
| 697 | }, | 697 | }, |
| 698 | else => { | 698 | else => { |
| 699 | return error.InvalidNumber; | 699 | return error.InvalidNumber; |
| ... | @@ -701,15 +701,15 @@ pub const StreamingParser = struct { | ... | @@ -701,15 +701,15 @@ pub const StreamingParser = struct { |
| 701 | } | 701 | } |
| 702 | }, | 702 | }, |
| 703 | | 703 | |
| 704 | State.NumberFractional => { | 704 | .NumberFractional => { |
| 705 | p.complete = p.after_value_state == State.TopLevelEnd; | 705 | p.complete = p.after_value_state == .TopLevelEnd; |
| 706 | switch (c) { | 706 | switch (c) { |
| 707 | '0'...'9' => { | 707 | '0'...'9' => { |
| 708 | // another digit | 708 | // another digit |
| 709 | }, | 709 | }, |
| 710 | 'e', 'E' => { | 710 | 'e', 'E' => { |
| 711 | p.number_is_integer = false; | 711 | p.number_is_integer = false; |
| 712 | p.state = State.NumberExponent; | 712 | p.state = .NumberExponent; |
| 713 | }, | 713 | }, |
| 714 | else => { | 714 | else => { |
| 715 | p.state = p.after_value_state; | 715 | p.state = p.after_value_state; |
| ... | @@ -724,12 +724,12 @@ pub const StreamingParser = struct { | ... | @@ -724,12 +724,12 @@ pub const StreamingParser = struct { |
| 724 | } | 724 | } |
| 725 | }, | 725 | }, |
| 726 | | 726 | |
| 727 | State.NumberMaybeExponent => { | 727 | .NumberMaybeExponent => { |
| 728 | p.complete = p.after_value_state == State.TopLevelEnd; | 728 | p.complete = p.after_value_state == .TopLevelEnd; |
| 729 | switch (c) { | 729 | switch (c) { |
| 730 | 'e', 'E' => { | 730 | 'e', 'E' => { |
| 731 | p.number_is_integer = false; | 731 | p.number_is_integer = false; |
| 732 | p.state = State.NumberExponent; | 732 | p.state = .NumberExponent; |
| 733 | }, | 733 | }, |
| 734 | else => { | 734 | else => { |
| 735 | p.state = p.after_value_state; | 735 | p.state = p.after_value_state; |
| ... | @@ -744,32 +744,32 @@ pub const StreamingParser = struct { | ... | @@ -744,32 +744,32 @@ pub const StreamingParser = struct { |
| 744 | } | 744 | } |
| 745 | }, | 745 | }, |
| 746 | | 746 | |
| 747 | State.NumberExponent => switch (c) { | 747 | .NumberExponent => switch (c) { |
| 748 | '-', '+' => { | 748 | '-', '+' => { |
| 749 | p.complete = false; | 749 | p.complete = false; |
| 750 | p.state = State.NumberExponentDigitsRequired; | 750 | p.state = .NumberExponentDigitsRequired; |
| 751 | }, | 751 | }, |
| 752 | '0'...'9' => { | 752 | '0'...'9' => { |
| 753 | p.complete = p.after_value_state == State.TopLevelEnd; | 753 | p.complete = p.after_value_state == .TopLevelEnd; |
| 754 | p.state = State.NumberExponentDigits; | 754 | p.state = .NumberExponentDigits; |
| 755 | }, | 755 | }, |
| 756 | else => { | 756 | else => { |
| 757 | return error.InvalidNumber; | 757 | return error.InvalidNumber; |
| 758 | }, | 758 | }, |
| 759 | }, | 759 | }, |
| 760 | | 760 | |
| 761 | State.NumberExponentDigitsRequired => switch (c) { | 761 | .NumberExponentDigitsRequired => switch (c) { |
| 762 | '0'...'9' => { | 762 | '0'...'9' => { |
| 763 | p.complete = p.after_value_state == State.TopLevelEnd; | 763 | p.complete = p.after_value_state == .TopLevelEnd; |
| 764 | p.state = State.NumberExponentDigits; | 764 | p.state = .NumberExponentDigits; |
| 765 | }, | 765 | }, |
| 766 | else => { | 766 | else => { |
| 767 | return error.InvalidNumber; | 767 | return error.InvalidNumber; |
| 768 | }, | 768 | }, |
| 769 | }, | 769 | }, |
| 770 | | 770 | |
| 771 | State.NumberExponentDigits => { | 771 | .NumberExponentDigits => { |
| 772 | p.complete = p.after_value_state == State.TopLevelEnd; | 772 | p.complete = p.after_value_state == .TopLevelEnd; |
| 773 | switch (c) { | 773 | switch (c) { |
| 774 | '0'...'9' => { | 774 | '0'...'9' => { |
| 775 | // another digit | 775 | // another digit |
| ... | @@ -787,20 +787,20 @@ pub const StreamingParser = struct { | ... | @@ -787,20 +787,20 @@ pub const StreamingParser = struct { |
| 787 | } | 787 | } |
| 788 | }, | 788 | }, |
| 789 | | 789 | |
| 790 | State.TrueLiteral1 => switch (c) { | 790 | .TrueLiteral1 => switch (c) { |
| 791 | 'r' => p.state = State.TrueLiteral2, | 791 | 'r' => p.state = .TrueLiteral2, |
| 792 | else => return error.InvalidLiteral, | 792 | else => return error.InvalidLiteral, |
| 793 | }, | 793 | }, |
| 794 | | 794 | |
| 795 | State.TrueLiteral2 => switch (c) { | 795 | .TrueLiteral2 => switch (c) { |
| 796 | 'u' => p.state = State.TrueLiteral3, | 796 | 'u' => p.state = .TrueLiteral3, |
| 797 | else => return error.InvalidLiteral, | 797 | else => return error.InvalidLiteral, |
| 798 | }, | 798 | }, |
| 799 | | 799 | |
| 800 | State.TrueLiteral3 => switch (c) { | 800 | .TrueLiteral3 => switch (c) { |
| 801 | 'e' => { | 801 | 'e' => { |
| 802 | p.state = p.after_value_state; | 802 | p.state = p.after_value_state; |
| 803 | p.complete = p.state == State.TopLevelEnd; | 803 | p.complete = p.state == .TopLevelEnd; |
| 804 | token.* = Token.True; | 804 | token.* = Token.True; |
| 805 | }, | 805 | }, |
| 806 | else => { | 806 | else => { |
| ... | @@ -808,25 +808,25 @@ pub const StreamingParser = struct { | ... | @@ -808,25 +808,25 @@ pub const StreamingParser = struct { |
| 808 | }, | 808 | }, |
| 809 | }, | 809 | }, |
| 810 | | 810 | |
| 811 | State.FalseLiteral1 => switch (c) { | 811 | .FalseLiteral1 => switch (c) { |
| 812 | 'a' => p.state = State.FalseLiteral2, | 812 | 'a' => p.state = .FalseLiteral2, |
| 813 | else => return error.InvalidLiteral, | 813 | else => return error.InvalidLiteral, |
| 814 | }, | 814 | }, |
| 815 | | 815 | |
| 816 | State.FalseLiteral2 => switch (c) { | 816 | .FalseLiteral2 => switch (c) { |
| 817 | 'l' => p.state = State.FalseLiteral3, | 817 | 'l' => p.state = .FalseLiteral3, |
| 818 | else => return error.InvalidLiteral, | 818 | else => return error.InvalidLiteral, |
| 819 | }, | 819 | }, |
| 820 | | 820 | |
| 821 | State.FalseLiteral3 => switch (c) { | 821 | .FalseLiteral3 => switch (c) { |
| 822 | 's' => p.state = State.FalseLiteral4, | 822 | 's' => p.state = .FalseLiteral4, |
| 823 | else => return error.InvalidLiteral, | 823 | else => return error.InvalidLiteral, |
| 824 | }, | 824 | }, |
| 825 | | 825 | |
| 826 | State.FalseLiteral4 => switch (c) { | 826 | .FalseLiteral4 => switch (c) { |
| 827 | 'e' => { | 827 | 'e' => { |
| 828 | p.state = p.after_value_state; | 828 | p.state = p.after_value_state; |
| 829 | p.complete = p.state == State.TopLevelEnd; | 829 | p.complete = p.state == .TopLevelEnd; |
| 830 | token.* = Token.False; | 830 | token.* = Token.False; |
| 831 | }, | 831 | }, |
| 832 | else => { | 832 | else => { |
| ... | @@ -834,20 +834,20 @@ pub const StreamingParser = struct { | ... | @@ -834,20 +834,20 @@ pub const StreamingParser = struct { |
| 834 | }, | 834 | }, |
| 835 | }, | 835 | }, |
| 836 | | 836 | |
| 837 | State.NullLiteral1 => switch (c) { | 837 | .NullLiteral1 => switch (c) { |
| 838 | 'u' => p.state = State.NullLiteral2, | 838 | 'u' => p.state = .NullLiteral2, |
| 839 | else => return error.InvalidLiteral, | 839 | else => return error.InvalidLiteral, |
| 840 | }, | 840 | }, |
| 841 | | 841 | |
| 842 | State.NullLiteral2 => switch (c) { | 842 | .NullLiteral2 => switch (c) { |
| 843 | 'l' => p.state = State.NullLiteral3, | 843 | 'l' => p.state = .NullLiteral3, |
| 844 | else => return error.InvalidLiteral, | 844 | else => return error.InvalidLiteral, |
| 845 | }, | 845 | }, |
| 846 | | 846 | |
| 847 | State.NullLiteral3 => switch (c) { | 847 | .NullLiteral3 => switch (c) { |
| 848 | 'l' => { | 848 | 'l' => { |
| 849 | p.state = p.after_value_state; | 849 | p.state = p.after_value_state; |
| 850 | p.complete = p.state == State.TopLevelEnd; | 850 | p.complete = p.state == .TopLevelEnd; |
| 851 | token.* = Token.Null; | 851 | token.* = Token.Null; |
| 852 | }, | 852 | }, |
| 853 | else => { | 853 | else => { |
| ... | @@ -1075,7 +1075,7 @@ pub const Parser = struct { | ... | @@ -1075,7 +1075,7 @@ pub const Parser = struct { |
| 1075 | pub fn init(allocator: *Allocator, copy_strings: bool) Parser { | 1075 | pub fn init(allocator: *Allocator, copy_strings: bool) Parser { |
| 1076 | return Parser{ | 1076 | return Parser{ |
| 1077 | .allocator = allocator, | 1077 | .allocator = allocator, |
| 1078 | .state = State.Simple, | 1078 | .state = .Simple, |
| 1079 | .copy_strings = copy_strings, | 1079 | .copy_strings = copy_strings, |
| 1080 | .stack = Array.init(allocator), | 1080 | .stack = Array.init(allocator), |
| 1081 | }; | 1081 | }; |
| ... | @@ -1086,7 +1086,7 @@ pub const Parser = struct { | ... | @@ -1086,7 +1086,7 @@ pub const Parser = struct { |
| 1086 | } | 1086 | } |
| 1087 | | 1087 | |
| 1088 | pub fn reset(p: *Parser) void { | 1088 | pub fn reset(p: *Parser) void { |
| 1089 | p.state = State.Simple; | 1089 | p.state = .Simple; |
| 1090 | p.stack.shrink(0); | 1090 | p.stack.shrink(0); |
| 1091 | } | 1091 | } |
| 1092 | | 1092 | |
| ... | @@ -1112,7 +1112,7 @@ pub const Parser = struct { | ... | @@ -1112,7 +1112,7 @@ pub const Parser = struct { |
| 1112 | // can be cleaned up on error correctly during a `parse` on call. | 1112 | // can be cleaned up on error correctly during a `parse` on call. |
| 1113 | fn transition(p: *Parser, allocator: *Allocator, input: []const u8, i: usize, token: Token) !void { | 1113 | fn transition(p: *Parser, allocator: *Allocator, input: []const u8, i: usize, token: Token) !void { |
| 1114 | switch (p.state) { | 1114 | switch (p.state) { |
| 1115 | State.ObjectKey => switch (token) { | 1115 | .ObjectKey => switch (token) { |
| 1116 | .ObjectEnd => { | 1116 | .ObjectEnd => { |
| 1117 | if (p.stack.len == 1) { | 1117 | if (p.stack.len == 1) { |
| 1118 | return; | 1118 | return; |
| ... | @@ -1123,7 +1123,7 @@ pub const Parser = struct { | ... | @@ -1123,7 +1123,7 @@ pub const Parser = struct { |
| 1123 | }, | 1123 | }, |
| 1124 | .String => |s| { | 1124 | .String => |s| { |
| 1125 | try p.stack.append(try p.parseString(allocator, s, input, i)); | 1125 | try p.stack.append(try p.parseString(allocator, s, input, i)); |
| 1126 | p.state = State.ObjectValue; | 1126 | p.state = .ObjectValue; |
| 1127 | }, | 1127 | }, |
| 1128 | else => { | 1128 | else => { |
| 1129 | // The streaming parser would return an error eventually. | 1129 | // The streaming parser would return an error eventually. |
| ... | @@ -1132,50 +1132,50 @@ pub const Parser = struct { | ... | @@ -1132,50 +1132,50 @@ pub const Parser = struct { |
| 1132 | return error.InvalidLiteral; | 1132 | return error.InvalidLiteral; |
| 1133 | }, | 1133 | }, |
| 1134 | }, | 1134 | }, |
| 1135 | State.ObjectValue => { | 1135 | .ObjectValue => { |
| 1136 | var object = &p.stack.items[p.stack.len - 2].Object; | 1136 | var object = &p.stack.items[p.stack.len - 2].Object; |
| 1137 | var key = p.stack.items[p.stack.len - 1].String; | 1137 | var key = p.stack.items[p.stack.len - 1].String; |
| 1138 | | 1138 | |
| 1139 | switch (token) { | 1139 | switch (token) { |
| 1140 | .ObjectBegin => { | 1140 | .ObjectBegin => { |
| 1141 | try p.stack.append(Value{ .Object = ObjectMap.init(allocator) }); | 1141 | try p.stack.append(Value{ .Object = ObjectMap.init(allocator) }); |
| 1142 | p.state = State.ObjectKey; | 1142 | p.state = .ObjectKey; |
| 1143 | }, | 1143 | }, |
| 1144 | .ArrayBegin => { | 1144 | .ArrayBegin => { |
| 1145 | try p.stack.append(Value{ .Array = Array.init(allocator) }); | 1145 | try p.stack.append(Value{ .Array = Array.init(allocator) }); |
| 1146 | p.state = State.ArrayValue; | 1146 | p.state = .ArrayValue; |
| 1147 | }, | 1147 | }, |
| 1148 | .String => |s| { | 1148 | .String => |s| { |
| 1149 | _ = try object.put(key, try p.parseString(allocator, s, input, i)); | 1149 | _ = try object.put(key, try p.parseString(allocator, s, input, i)); |
| 1150 | _ = p.stack.pop(); | 1150 | _ = p.stack.pop(); |
| 1151 | p.state = State.ObjectKey; | 1151 | p.state = .ObjectKey; |
| 1152 | }, | 1152 | }, |
| 1153 | .Number => |n| { | 1153 | .Number => |n| { |
| 1154 | _ = try object.put(key, try p.parseNumber(n, input, i)); | 1154 | _ = try object.put(key, try p.parseNumber(n, input, i)); |
| 1155 | _ = p.stack.pop(); | 1155 | _ = p.stack.pop(); |
| 1156 | p.state = State.ObjectKey; | 1156 | p.state = .ObjectKey; |
| 1157 | }, | 1157 | }, |
| 1158 | .True => { | 1158 | .True => { |
| 1159 | _ = try object.put(key, Value{ .Bool = true }); | 1159 | _ = try object.put(key, Value{ .Bool = true }); |
| 1160 | _ = p.stack.pop(); | 1160 | _ = p.stack.pop(); |
| 1161 | p.state = State.ObjectKey; | 1161 | p.state = .ObjectKey; |
| 1162 | }, | 1162 | }, |
| 1163 | .False => { | 1163 | .False => { |
| 1164 | _ = try object.put(key, Value{ .Bool = false }); | 1164 | _ = try object.put(key, Value{ .Bool = false }); |
| 1165 | _ = p.stack.pop(); | 1165 | _ = p.stack.pop(); |
| 1166 | p.state = State.ObjectKey; | 1166 | p.state = .ObjectKey; |
| 1167 | }, | 1167 | }, |
| 1168 | .Null => { | 1168 | .Null => { |
| 1169 | _ = try object.put(key, Value.Null); | 1169 | _ = try object.put(key, Value.Null); |
| 1170 | _ = p.stack.pop(); | 1170 | _ = p.stack.pop(); |
| 1171 | p.state = State.ObjectKey; | 1171 | p.state = .ObjectKey; |
| 1172 | }, | 1172 | }, |
| 1173 | .ObjectEnd, .ArrayEnd => { | 1173 | .ObjectEnd, .ArrayEnd => { |
| 1174 | unreachable; | 1174 | unreachable; |
| 1175 | }, | 1175 | }, |
| 1176 | } | 1176 | } |
| 1177 | }, | 1177 | }, |
| 1178 | State.ArrayValue => { | 1178 | .ArrayValue => { |
| 1179 | var array = &p.stack.items[p.stack.len - 1].Array; | 1179 | var array = &p.stack.items[p.stack.len - 1].Array; |
| 1180 | | 1180 | |
| 1181 | switch (token) { | 1181 | switch (token) { |
| ... | @@ -1189,11 +1189,11 @@ pub const Parser = struct { | ... | @@ -1189,11 +1189,11 @@ pub const Parser = struct { |
| 1189 | }, | 1189 | }, |
| 1190 | .ObjectBegin => { | 1190 | .ObjectBegin => { |
| 1191 | try p.stack.append(Value{ .Object = ObjectMap.init(allocator) }); | 1191 | try p.stack.append(Value{ .Object = ObjectMap.init(allocator) }); |
| 1192 | p.state = State.ObjectKey; | 1192 | p.state = .ObjectKey; |
| 1193 | }, | 1193 | }, |
| 1194 | .ArrayBegin => { | 1194 | .ArrayBegin => { |
| 1195 | try p.stack.append(Value{ .Array = Array.init(allocator) }); | 1195 | try p.stack.append(Value{ .Array = Array.init(allocator) }); |
| 1196 | p.state = State.ArrayValue; | 1196 | p.state = .ArrayValue; |
| 1197 | }, | 1197 | }, |
| 1198 | .String => |s| { | 1198 | .String => |s| { |
| 1199 | try array.append(try p.parseString(allocator, s, input, i)); | 1199 | try array.append(try p.parseString(allocator, s, input, i)); |
| ... | @@ -1215,14 +1215,14 @@ pub const Parser = struct { | ... | @@ -1215,14 +1215,14 @@ pub const Parser = struct { |
| 1215 | }, | 1215 | }, |
| 1216 | } | 1216 | } |
| 1217 | }, | 1217 | }, |
| 1218 | State.Simple => switch (token) { | 1218 | .Simple => switch (token) { |
| 1219 | .ObjectBegin => { | 1219 | .ObjectBegin => { |
| 1220 | try p.stack.append(Value{ .Object = ObjectMap.init(allocator) }); | 1220 | try p.stack.append(Value{ .Object = ObjectMap.init(allocator) }); |
| 1221 | p.state = State.ObjectKey; | 1221 | p.state = .ObjectKey; |
| 1222 | }, | 1222 | }, |
| 1223 | .ArrayBegin => { | 1223 | .ArrayBegin => { |
| 1224 | try p.stack.append(Value{ .Array = Array.init(allocator) }); | 1224 | try p.stack.append(Value{ .Array = Array.init(allocator) }); |
| 1225 | p.state = State.ArrayValue; | 1225 | p.state = .ArrayValue; |
| 1226 | }, | 1226 | }, |
| 1227 | .String => |s| { | 1227 | .String => |s| { |
| 1228 | try p.stack.append(try p.parseString(allocator, s, input, i)); | 1228 | try p.stack.append(try p.parseString(allocator, s, input, i)); |
| ... | @@ -1254,12 +1254,12 @@ pub const Parser = struct { | ... | @@ -1254,12 +1254,12 @@ pub const Parser = struct { |
| 1254 | | 1254 | |
| 1255 | var object = &p.stack.items[p.stack.len - 1].Object; | 1255 | var object = &p.stack.items[p.stack.len - 1].Object; |
| 1256 | _ = try object.put(key, value.*); | 1256 | _ = try object.put(key, value.*); |
| 1257 | p.state = State.ObjectKey; | 1257 | p.state = .ObjectKey; |
| 1258 | }, | 1258 | }, |
| 1259 | // Array Parent -> [ ..., <array>, value ] | 1259 | // Array Parent -> [ ..., <array>, value ] |
| 1260 | Value.Array => |*array| { | 1260 | Value.Array => |*array| { |
| 1261 | try array.append(value.*); | 1261 | try array.append(value.*); |
| 1262 | p.state = State.ArrayValue; | 1262 | p.state = .ArrayValue; |
| 1263 | }, | 1263 | }, |
| 1264 | else => { | 1264 | else => { |
| 1265 | unreachable; | 1265 | unreachable; |