contrived_json 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 73d8f250dcbb1fb0aad688d70e65ffbde3539fb0
4
- data.tar.gz: a70684b04398bdabd5e17e6ed06de606b9323de3
2
+ SHA256:
3
+ metadata.gz: 2cdc11aa9a2992b6c9c5fb3fcd527bae6b62b931d6b6c6fe08565cf13e04fe9a
4
+ data.tar.gz: 38ebf177c20fed40d00d14c1d05dbbeaa24cdb1715749b25a088d7dfaae85a8a
5
5
  SHA512:
6
- metadata.gz: d7d3610473540af0c114fe53a3a94fe7eb612e613e5c961a732059165ee3666603b91c9544fdce6d63cf71d0e1aac80b1847e7039b5a863a79e7345d3102e815
7
- data.tar.gz: bb1281b75ad9201730f07019fafd27cef2e99e8ee119a35434ceaab7f173c22d4a7abc7fb88e217411dcd1878640bf65339cc9deab36b6e2ecc6d40476804a94
6
+ metadata.gz: 4d8ab4f5af43a1086b1ec777b0b668e38976f7c1d9b9dc59e5b5b22a9bfe80dfff3a5d199adf21f138115df8926858ad763becbb480c2dec86bf2dca1c59f552
7
+ data.tar.gz: 1a2e6db4b470c22b55f3da5e56c8352159c957a5cc3ade5a97ce200eb8d975d7533f56c747766ab031c9f0f84f68d04583c9235d6ab3a9336aa94ec9223b305d
@@ -636,8 +636,32 @@ static yyconst struct yy_trans_info *yy_start_state_list[3] =
636
636
  yylloc->last_column += yyleng;\
637
637
  }while(0);
638
638
 
639
+ static VALUE read_wrapper(VALUE arg)
640
+ {
641
+ VALUE *aarg = (VALUE *)arg;
642
+ return rb_funcall(aarg[0], rb_intern("readpartial"), 1, aarg[1]);
643
+ }
644
+
645
+ static VALUE read_wrapper_rescue(VALUE arg)
646
+ {
647
+ return Qnil;
648
+ }
649
+
650
+ #define YY_INPUT(buf, result, max_size) do {\
651
+ VALUE arg[2];\
652
+ VALUE str;\
653
+ result = 0U;\
654
+ arg[0] = *((VALUE *)yyin);\
655
+ arg[1] = SIZET2NUM(max_size);\
656
+ str = rb_rescue2(read_wrapper, (VALUE)arg, read_wrapper_rescue, Qnil, rb_eEOFError, 0);\
657
+ if(str != Qnil){\
658
+ (void)memcpy(buf, RSTRING_PTR(str), RSTRING_LEN(str));\
659
+ result = (size_t)RSTRING_LEN(str);\
660
+ }\
661
+ } while(0)\
662
+
639
663
  #define YY_NO_INPUT 1
640
- #line 641 "ext/contrived_json/ext_parser/lexer.c"
664
+ #line 665 "ext/contrived_json/ext_parser/lexer.c"
641
665
 
642
666
  #define INITIAL 0
643
667
 
@@ -904,10 +928,10 @@ YY_DECL
904
928
  }
905
929
 
906
930
  {
907
- #line 29 "etc/contrived_json/ext_parser/parser.l"
931
+ #line 53 "etc/contrived_json/ext_parser/parser.l"
908
932
 
909
933
 
910
- #line 911 "ext/contrived_json/ext_parser/lexer.c"
934
+ #line 935 "ext/contrived_json/ext_parser/lexer.c"
911
935
 
912
936
  while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
913
937
  {
@@ -961,75 +985,75 @@ do_action: /* This label is used only to access EOF actions. */
961
985
 
962
986
  case 1:
963
987
  YY_RULE_SETUP
964
- #line 31 "etc/contrived_json/ext_parser/parser.l"
988
+ #line 55 "etc/contrived_json/ext_parser/parser.l"
965
989
  { }
966
990
  YY_BREAK
967
991
  case 2:
968
992
  /* rule 2 can match eol */
969
993
  YY_RULE_SETUP
970
- #line 32 "etc/contrived_json/ext_parser/parser.l"
994
+ #line 56 "etc/contrived_json/ext_parser/parser.l"
971
995
  { yylloc->last_column = 0; yylloc->last_line += yyleng; }
972
996
  YY_BREAK
973
997
  case 3:
974
- #line 35 "etc/contrived_json/ext_parser/parser.l"
998
+ #line 59 "etc/contrived_json/ext_parser/parser.l"
975
999
  case 4:
976
- #line 36 "etc/contrived_json/ext_parser/parser.l"
1000
+ #line 60 "etc/contrived_json/ext_parser/parser.l"
977
1001
  case 5:
978
- #line 37 "etc/contrived_json/ext_parser/parser.l"
1002
+ #line 61 "etc/contrived_json/ext_parser/parser.l"
979
1003
  case 6:
980
- #line 38 "etc/contrived_json/ext_parser/parser.l"
1004
+ #line 62 "etc/contrived_json/ext_parser/parser.l"
981
1005
  case 7:
982
- #line 39 "etc/contrived_json/ext_parser/parser.l"
1006
+ #line 63 "etc/contrived_json/ext_parser/parser.l"
983
1007
  case 8:
984
1008
  YY_RULE_SETUP
985
- #line 39 "etc/contrived_json/ext_parser/parser.l"
1009
+ #line 63 "etc/contrived_json/ext_parser/parser.l"
986
1010
  { return *yytext; }
987
1011
  YY_BREAK
988
1012
  case 9:
989
1013
  YY_RULE_SETUP
990
- #line 41 "etc/contrived_json/ext_parser/parser.l"
1014
+ #line 65 "etc/contrived_json/ext_parser/parser.l"
991
1015
  { *yylval = Qtrue; return TOK_TRUE; }
992
1016
  YY_BREAK
993
1017
  case 10:
994
1018
  YY_RULE_SETUP
995
- #line 42 "etc/contrived_json/ext_parser/parser.l"
1019
+ #line 66 "etc/contrived_json/ext_parser/parser.l"
996
1020
  { *yylval = Qfalse; return TOK_FALSE; }
997
1021
  YY_BREAK
998
1022
  case 11:
999
1023
  YY_RULE_SETUP
1000
- #line 43 "etc/contrived_json/ext_parser/parser.l"
1024
+ #line 67 "etc/contrived_json/ext_parser/parser.l"
1001
1025
  { *yylval = Qnil; return TOK_NULL; }
1002
1026
  YY_BREAK
1003
1027
  case 12:
1004
1028
  YY_RULE_SETUP
1005
- #line 45 "etc/contrived_json/ext_parser/parser.l"
1029
+ #line 69 "etc/contrived_json/ext_parser/parser.l"
1006
1030
  { *yylval = rb_str_new(&yytext[1], yyleng-2U); return TOK_STRING; }
1007
1031
  YY_BREAK
1008
1032
  case 13:
1009
- #line 48 "etc/contrived_json/ext_parser/parser.l"
1033
+ #line 72 "etc/contrived_json/ext_parser/parser.l"
1010
1034
  case 14:
1011
- #line 49 "etc/contrived_json/ext_parser/parser.l"
1035
+ #line 73 "etc/contrived_json/ext_parser/parser.l"
1012
1036
  case 15:
1013
1037
  YY_RULE_SETUP
1014
- #line 49 "etc/contrived_json/ext_parser/parser.l"
1038
+ #line 73 "etc/contrived_json/ext_parser/parser.l"
1015
1039
  { *yylval = rb_funcall(rb_const_get(rb_cObject, rb_intern("BigDecimal")), rb_intern("new"), 1, rb_str_new(yytext, yyleng)); return TOK_NUMBER; }
1016
1040
  YY_BREAK
1017
1041
  case 16:
1018
1042
  YY_RULE_SETUP
1019
- #line 51 "etc/contrived_json/ext_parser/parser.l"
1043
+ #line 75 "etc/contrived_json/ext_parser/parser.l"
1020
1044
  { *yylval = rb_funcall(rb_str_new(yytext, yyleng), rb_intern("to_i"), 0); return TOK_NUMBER; }
1021
1045
  YY_BREAK
1022
1046
  case 17:
1023
1047
  YY_RULE_SETUP
1024
- #line 53 "etc/contrived_json/ext_parser/parser.l"
1048
+ #line 77 "etc/contrived_json/ext_parser/parser.l"
1025
1049
  { return TOK_UNKNOWN; }
1026
1050
  YY_BREAK
1027
1051
  case 18:
1028
1052
  YY_RULE_SETUP
1029
- #line 55 "etc/contrived_json/ext_parser/parser.l"
1053
+ #line 79 "etc/contrived_json/ext_parser/parser.l"
1030
1054
  ECHO;
1031
1055
  YY_BREAK
1032
- #line 1033 "ext/contrived_json/ext_parser/lexer.c"
1056
+ #line 1057 "ext/contrived_json/ext_parser/lexer.c"
1033
1057
  case YY_STATE_EOF(INITIAL):
1034
1058
  yyterminate();
1035
1059
 
@@ -2178,7 +2202,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
2178
2202
 
2179
2203
  #define YYTABLES_NAME "yytables"
2180
2204
 
2181
- #line 55 "etc/contrived_json/ext_parser/parser.l"
2205
+ #line 79 "etc/contrived_json/ext_parser/parser.l"
2182
2206
 
2183
2207
 
2184
2208
 
@@ -355,7 +355,7 @@ extern int yylex \
355
355
  #undef YY_DECL
356
356
  #endif
357
357
 
358
- #line 55 "etc/contrived_json/ext_parser/parser.l"
358
+ #line 79 "etc/contrived_json/ext_parser/parser.l"
359
359
 
360
360
 
361
361
  #line 362 "ext/contrived_json/ext_parser/lexer.h"
@@ -394,18 +394,18 @@ union yyalloc
394
394
  #endif /* !YYCOPY_NEEDED */
395
395
 
396
396
  /* YYFINAL -- State number of the termination state. */
397
- #define YYFINAL 20
397
+ #define YYFINAL 19
398
398
  /* YYLAST -- Last index in YYTABLE. */
399
- #define YYLAST 31
399
+ #define YYLAST 28
400
400
 
401
401
  /* YYNTOKENS -- Number of terminals. */
402
402
  #define YYNTOKENS 15
403
403
  /* YYNNTS -- Number of nonterminals. */
404
404
  #define YYNNTS 8
405
405
  /* YYNRULES -- Number of rules. */
406
- #define YYNRULES 20
406
+ #define YYNRULES 18
407
407
  /* YYNSTATES -- Number of states. */
408
- #define YYNSTATES 31
408
+ #define YYNSTATES 30
409
409
 
410
410
  /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
411
411
  by yylex, with out-of-bounds checking. */
@@ -452,9 +452,8 @@ static const yytype_uint8 yytranslate[] =
452
452
  /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
453
453
  static const yytype_uint8 yyrline[] =
454
454
  {
455
- 0, 39, 39, 41, 45, 45, 49, 51, 55, 57,
456
- 61, 63, 67, 69, 73, 73, 73, 73, 73, 73,
457
- 73
455
+ 0, 39, 39, 43, 47, 49, 53, 55, 59, 61,
456
+ 65, 67, 71, 71, 71, 71, 71, 71, 71
458
457
  };
459
458
  #endif
460
459
 
@@ -480,10 +479,10 @@ static const yytype_uint16 yytoknum[] =
480
479
  };
481
480
  # endif
482
481
 
483
- #define YYPACT_NINF -6
482
+ #define YYPACT_NINF -7
484
483
 
485
484
  #define yypact_value_is_default(Yystate) \
486
- (!!((Yystate) == (-6)))
485
+ (!!((Yystate) == (-7)))
487
486
 
488
487
  #define YYTABLE_NINF -1
489
488
 
@@ -494,10 +493,9 @@ static const yytype_uint16 yytoknum[] =
494
493
  STATE-NUM. */
495
494
  static const yytype_int8 yypact[] =
496
495
  {
497
- 11, -3, 2, 5, -6, -6, -6, -6, -6, -6,
498
- -6, -6, -6, -6, 18, -6, -6, 8, -6, 14,
499
- -6, -6, 7, 7, 15, -6, -6, -6, 12, 7,
500
- -6
496
+ 14, -7, -7, -7, -7, -7, -2, 0, 9, -7,
497
+ -7, -7, -7, -7, 17, -7, -3, -7, 1, -7,
498
+ -7, 14, 14, 18, -7, -7, -7, 11, 14, -7
501
499
  };
502
500
 
503
501
  /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
@@ -505,22 +503,21 @@ static const yytype_int8 yypact[] =
505
503
  means the default is an error. */
506
504
  static const yytype_uint8 yydefact[] =
507
505
  {
508
- 3, 0, 0, 0, 2, 4, 5, 15, 16, 17,
509
- 14, 18, 6, 20, 0, 19, 8, 0, 10, 0,
510
- 1, 7, 0, 0, 0, 11, 9, 12, 0, 0,
511
- 13
506
+ 0, 13, 14, 15, 12, 16, 0, 0, 0, 2,
507
+ 18, 17, 3, 4, 0, 6, 0, 8, 0, 1,
508
+ 5, 0, 0, 0, 9, 7, 10, 0, 0, 11
512
509
  };
513
510
 
514
511
  /* YYPGOTO[NTERM-NUM]. */
515
512
  static const yytype_int8 yypgoto[] =
516
513
  {
517
- -6, -6, -6, 30, -6, 31, -6, -5
514
+ -7, -7, -7, -7, -7, -7, -7, -6
518
515
  };
519
516
 
520
517
  /* YYDEFGOTO[NTERM-NUM]. */
521
518
  static const yytype_int8 yydefgoto[] =
522
519
  {
523
- -1, 3, 4, 13, 14, 15, 19, 16
520
+ -1, 8, 9, 10, 14, 11, 18, 12
524
521
  };
525
522
 
526
523
  /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
@@ -528,44 +525,39 @@ static const yytype_int8 yydefgoto[] =
528
525
  number is the opposite. If YYTABLE_NINF, syntax error. */
529
526
  static const yytype_uint8 yytable[] =
530
527
  {
531
- 7, 8, 9, 10, 11, 20, 1, 12, 17, 2,
532
- 7, 8, 9, 10, 11, 18, 1, 26, 27, 2,
533
- 1, 28, 23, 2, 30, 24, 29, 25, 21, 22,
534
- 5, 6
528
+ 15, 1, 2, 3, 4, 5, 16, 6, 13, 19,
529
+ 7, 22, 23, 17, 24, 25, 26, 1, 2, 3,
530
+ 4, 5, 29, 6, 27, 28, 7, 20, 21
535
531
  };
536
532
 
537
533
  static const yytype_uint8 yycheck[] =
538
534
  {
539
- 3, 4, 5, 6, 7, 0, 9, 10, 6, 12,
540
- 3, 4, 5, 6, 7, 13, 9, 22, 23, 12,
541
- 9, 6, 14, 12, 29, 11, 14, 13, 10, 11,
542
- 0, 0
535
+ 6, 3, 4, 5, 6, 7, 6, 9, 10, 0,
536
+ 12, 14, 11, 13, 13, 21, 22, 3, 4, 5,
537
+ 6, 7, 28, 9, 6, 14, 12, 10, 11
543
538
  };
544
539
 
545
540
  /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
546
541
  symbol of state STATE-NUM. */
547
542
  static const yytype_uint8 yystos[] =
548
543
  {
549
- 0, 9, 12, 16, 17, 18, 20, 3, 4, 5,
550
- 6, 7, 10, 18, 19, 20, 22, 6, 13, 21,
551
- 0, 10, 11, 14, 11, 13, 22, 22, 6, 14,
552
- 22
544
+ 0, 3, 4, 5, 6, 7, 9, 12, 16, 17,
545
+ 18, 20, 22, 10, 19, 22, 6, 13, 21, 0,
546
+ 10, 11, 14, 11, 13, 22, 22, 6, 14, 22
553
547
  };
554
548
 
555
549
  /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
556
550
  static const yytype_uint8 yyr1[] =
557
551
  {
558
- 0, 15, 16, 16, 17, 17, 18, 18, 19, 19,
559
- 20, 20, 21, 21, 22, 22, 22, 22, 22, 22,
560
- 22
552
+ 0, 15, 16, 17, 18, 18, 19, 19, 20, 20,
553
+ 21, 21, 22, 22, 22, 22, 22, 22, 22
561
554
  };
562
555
 
563
556
  /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
564
557
  static const yytype_uint8 yyr2[] =
565
558
  {
566
- 0, 2, 1, 0, 1, 1, 2, 3, 1, 3,
567
- 2, 3, 3, 5, 1, 1, 1, 1, 1, 1,
568
- 1
559
+ 0, 2, 1, 1, 2, 3, 1, 3, 2, 3,
560
+ 3, 5, 1, 1, 1, 1, 1, 1, 1
569
561
  };
570
562
 
571
563
 
@@ -1346,60 +1338,60 @@ yyreduce:
1346
1338
  {
1347
1339
  case 2:
1348
1340
  #line 39 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1349
- { *object = (yyvsp[0]); }
1350
- #line 1351 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1341
+ { *object = (yyvsp[0]); YYACCEPT; }
1342
+ #line 1343 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1351
1343
  break;
1352
1344
 
1353
- case 6:
1354
- #line 49 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1345
+ case 4:
1346
+ #line 47 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1355
1347
  { (yyval) = rb_ary_new(); }
1356
- #line 1357 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1348
+ #line 1349 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1357
1349
  break;
1358
1350
 
1359
- case 7:
1360
- #line 51 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1351
+ case 5:
1352
+ #line 49 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1361
1353
  { (yyval) = (yyvsp[-1]); }
1362
- #line 1363 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1354
+ #line 1355 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1363
1355
  break;
1364
1356
 
1365
- case 8:
1366
- #line 55 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1357
+ case 6:
1358
+ #line 53 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1367
1359
  { (yyval) = rb_ary_new(); rb_ary_push((yyval), (yyvsp[0])); }
1368
- #line 1369 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1360
+ #line 1361 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1369
1361
  break;
1370
1362
 
1371
- case 9:
1372
- #line 57 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1363
+ case 7:
1364
+ #line 55 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1373
1365
  { rb_ary_push((yyval), (yyvsp[0])); }
1374
- #line 1375 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1366
+ #line 1367 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1375
1367
  break;
1376
1368
 
1377
- case 10:
1378
- #line 61 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1369
+ case 8:
1370
+ #line 59 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1379
1371
  { (yyval) = rb_hash_new(); }
1380
- #line 1381 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1372
+ #line 1373 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1381
1373
  break;
1382
1374
 
1383
- case 11:
1384
- #line 63 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1375
+ case 9:
1376
+ #line 61 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1385
1377
  { (yyval) = (yyvsp[-1]); }
1386
- #line 1387 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1378
+ #line 1379 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1387
1379
  break;
1388
1380
 
1389
- case 12:
1390
- #line 67 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1381
+ case 10:
1382
+ #line 65 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1391
1383
  { (yyval) = rb_hash_new(); rb_hash_aset((yyval), (yyvsp[-2]), (yyvsp[0])); }
1392
- #line 1393 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1384
+ #line 1385 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1393
1385
  break;
1394
1386
 
1395
- case 13:
1396
- #line 69 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1387
+ case 11:
1388
+ #line 67 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1646 */
1397
1389
  { rb_hash_aset((yyval), (yyvsp[-2]), (yyvsp[0])); }
1398
- #line 1399 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1390
+ #line 1391 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1399
1391
  break;
1400
1392
 
1401
1393
 
1402
- #line 1403 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1394
+ #line 1395 "ext/contrived_json/ext_parser/parser.c" /* yacc.c:1646 */
1403
1395
  default: break;
1404
1396
  }
1405
1397
  /* User semantic actions sometimes alter yychar, and that requires
@@ -1634,7 +1626,7 @@ yyreturn:
1634
1626
  #endif
1635
1627
  return yyresult;
1636
1628
  }
1637
- #line 75 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1906 */
1629
+ #line 73 "etc/contrived_json/ext_parser/parser.y" /* yacc.c:1906 */
1638
1630
 
1639
1631
 
1640
1632
  void yyerror(YYLTYPE *locp, yyscan_t scanner, VALUE *object, char const *msg)
@@ -1666,6 +1658,8 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
1666
1658
  VALUE source = Qnil;
1667
1659
  VALUE opts = rb_hash_new();
1668
1660
  int retval = 0;
1661
+ VALUE input = Qnil;
1662
+ VALUE cStringIO = rb_const_get(rb_cObject, rb_intern("StringIO"));
1669
1663
 
1670
1664
  switch(rb_scan_args(argc, argv, "11", &source, &opts)){
1671
1665
  case 1:
@@ -1676,17 +1670,24 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
1676
1670
  break;
1677
1671
  }
1678
1672
 
1679
- if(rb_obj_is_kind_of(source, rb_cString) != Qtrue){
1680
-
1681
- rb_raise(rb_eTypeError, "source must be a kind of String");
1673
+ if(rb_respond_to(source, rb_intern("read"))){
1674
+
1675
+ input = source;
1676
+ }
1677
+ else if(rb_obj_is_kind_of(source, rb_cString) == Qtrue){
1678
+
1679
+ input = rb_funcall(cStringIO, rb_intern("new"), 1, source);
1680
+ }
1681
+ else{
1682
+
1683
+ rb_raise(rb_eTypeError, "no implicit conversion to String");
1682
1684
  }
1683
1685
 
1684
1686
  if(yylex_init(&scanner) == 0){
1685
1687
 
1686
- if(yy_scan_bytes((const char *)RSTRING_PTR(source), RSTRING_LEN(source), scanner)){
1687
-
1688
- retval = yyparse(scanner, &object);
1689
- }
1688
+ yyset_in((FILE*)(&input), scanner);
1689
+
1690
+ retval = yyparse(scanner, &object);
1690
1691
 
1691
1692
  yylex_destroy(scanner);
1692
1693
 
@@ -1,3 +1,3 @@
1
1
  module ContrivedJSON
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
@@ -6,86 +6,171 @@ class TestJSON < Test::Unit::TestCase
6
6
  include ContrivedJSON
7
7
 
8
8
  def test_no_input
9
- input = ''
10
- assert_nil(JSON.parse(input))
9
+ input = ''
10
+ assert_raise ParseError do
11
+ JSON.parse(input)
12
+ end
11
13
  end
12
14
 
13
15
  def test_wrong_type
14
- input = 42
15
- assert_raise TypeError do
16
- JSON.parse(input)
17
- end
16
+ input = 42
17
+ assert_raise TypeError do
18
+ JSON.parse(input)
19
+ end
18
20
  end
19
21
 
20
22
  def test_empty_object
21
- input = '{}'
22
- expected = {}
23
- assert_equal(expected, JSON.parse(input))
23
+ input = '{}'
24
+ expected = {}
25
+ assert_equal(expected, JSON.parse(input))
24
26
  end
25
27
 
26
28
  def test_empty_array
27
- input = '[]'
28
- expected = []
29
- assert_equal(expected, JSON.parse(input))
29
+ input = '[]'
30
+ expected = []
31
+ assert_equal(expected, JSON.parse(input))
32
+ end
33
+
34
+ def test_toplevel_true
35
+ input = 'true'
36
+ expected = true
37
+ assert_equal(expected, JSON.parse(input))
38
+ end
39
+
40
+ def test_toplevel_false
41
+ input = 'false'
42
+ expected = false
43
+ assert_equal(expected, JSON.parse(input))
44
+ end
45
+
46
+ def test_toplevel_number
47
+ input = '42'
48
+ expected = 42
49
+ assert_equal(expected, JSON.parse(input))
50
+ end
51
+
52
+ def test_toplevel_string
53
+ input = "\"hello world\""
54
+ expected ='hello world'
55
+ assert_equal(expected, JSON.parse(input))
56
+ end
57
+
58
+ def test_toplevel_null
59
+ input = "null"
60
+ expected = nil
61
+ assert_equal(expected, JSON.parse(input))
30
62
  end
31
63
 
32
64
  def test_unexpected_end_open_brace
33
- input = '{'
34
- assert_raise ParseError do
35
- JSON.parse(input)
36
- end
65
+ input = '{'
66
+ assert_raise ParseError do
67
+ JSON.parse(input)
68
+ end
37
69
  end
38
70
 
39
71
  def test_unexpected_end_key
40
- input = '{ "key"'
41
- assert_raise ParseError do
42
- JSON.parse(input)
43
- end
72
+ input = '{ "key"'
73
+ assert_raise ParseError do
74
+ JSON.parse(input)
75
+ end
44
76
  end
45
77
 
46
78
  def test_unexpected_end_colon
47
- input = '{ "key" :'
48
- assert_raise ParseError do
49
- JSON.parse(input)
50
- end
79
+ input = '{ "key" :'
80
+ assert_raise ParseError do
81
+ JSON.parse(input)
82
+ end
51
83
  end
52
84
 
53
85
  def test_unexpected_end_value
54
- input = '{ "key" : null'
55
- assert_raise ParseError do
56
- JSON.parse(input)
57
- end
86
+ input = '{ "key" : null'
87
+ assert_raise ParseError do
88
+ JSON.parse(input)
89
+ end
58
90
  end
59
91
 
60
92
  def test_hello_world
61
- input = <<-eos
62
- {
63
- "hello" : "hello",
64
- "world" : "world"
65
- }
66
- eos
67
- expected = {
68
- "hello" => "hello",
69
- "world" => "world"
70
- }
71
- assert_equal(expected, JSON.parse(input))
93
+ input = <<-eos
94
+ {
95
+ "hello" : "hello",
96
+ "world" : "world"
97
+ }
98
+ eos
99
+ expected = {
100
+ "hello" => "hello",
101
+ "world" => "world"
102
+ }
103
+ assert_equal(expected, JSON.parse(input))
72
104
  end
73
105
 
74
106
  def test_unknown_token
75
- input = "{ !"
76
- assert_raise ParseError do
77
- JSON.parse(input)
78
- end
107
+ input = "{ !"
108
+ assert_raise ParseError do
109
+ JSON.parse(input)
110
+ end
79
111
  end
80
112
 
81
113
  def test_unicode_string
82
- input = '{"test":"\u005C"}'
83
- JSON.parse(input)
114
+ input = '{"test":"\u005C"}'
115
+ JSON.parse(input)
84
116
  end
85
117
 
86
118
  def test_escaped_characters
87
- input = '{"test":"\"\\\/\b\f\n\r\t\u005C"}'
88
- JSON.parse(input)
119
+ input = '{"test":"\"\\\/\b\f\n\r\t\u005C"}'
120
+ JSON.parse(input)
121
+ end
122
+
123
+ def test_hello_world_stream
124
+ input = <<-eos
125
+ {
126
+ "hello" : "hello",
127
+ "world" : "world"
128
+ }
129
+
130
+ {
131
+ "hello" : "hello",
132
+ "world" : "world"
133
+ }
134
+ eos
135
+ expected = {
136
+ "hello" => "hello",
137
+ "world" => "world"
138
+ }
139
+ assert_equal(expected, JSON.parse(input))
140
+ assert_equal(expected, JSON.parse(input))
141
+ end
142
+
143
+ =begin
144
+ def test_blocking_read
145
+
146
+ rd, wr = IO.pipe
147
+
148
+ expected = {
149
+ "hello" => "hello",
150
+ "world" => "world"
151
+ }
152
+
153
+ t = Thread.new do
154
+
155
+ puts "running"
156
+
157
+ wr.write "{\"hello\" : \"hello\","
158
+
159
+ sleep 1
160
+
161
+ wr.write "\"world\" : \"world\"} "
162
+
163
+ puts "done"
164
+
165
+ end
166
+
167
+ t.run
168
+
169
+ assert_equal(expected, JSON.parse(rd))
170
+
171
+ t.join
172
+
89
173
  end
174
+ =end
90
175
 
91
176
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contrived_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Harper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-05 00:00:00.000000000 Z
11
+ date: 2018-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 2.6.11
91
+ rubygems_version: 2.7.6
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: A Flex/Bison based JSON parser