diff options
author | Florian Frank <flori@ping.de> | 2015-06-15 14:15:48 +0200 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2015-06-15 14:15:48 +0200 |
commit | 68ce5b6b564f87edd1d4f005a39a230e544d15e8 (patch) | |
tree | 6ca09fc723cb6abe0885b52cefbd74775d93302a | |
parent | 6f907a9142e83141a2e01fdddfd18b2013244cd6 (diff) | |
download | json-68ce5b6b564f87edd1d4f005a39a230e544d15e8.tar.gz |
Ext parser is green now as well
-rw-r--r-- | Gemfile | 3 | ||||
-rw-r--r-- | Rakefile | 23 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.c | 543 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.h | 1 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.rl | 118 | ||||
-rw-r--r-- | ext/json/extconf.rb | 1 | ||||
-rw-r--r-- | json.gemspec | bin | 4423 -> 4594 bytes | |||
-rw-r--r-- | json_pure.gemspec | 19 |
8 files changed, 240 insertions, 468 deletions
@@ -6,6 +6,7 @@ gemspec :name => 'json' gemspec :name => 'json_pure' gemspec :name => 'json-java' -gem 'utils' +gem 'rake' +gem 'rdoc' gem 'test-unit' gem 'byebug', :platform => :mri @@ -23,10 +23,6 @@ class UndocumentedTestTask < Rake::TestTask def desc(*) end end -def skip_sdoc(src) - src.gsub(/^.*sdoc.*/) { |s| s + ' if RUBY_VERSION > "1.8.6"' } -end - MAKE = ENV['MAKE'] || %w[gmake make].find { |c| system(c, '-v') } BUNDLE = ENV['BUNDLE'] || %w[bundle].find { |c| system(c, '-v') } PKG_NAME = 'json' @@ -87,13 +83,11 @@ if defined?(Gem) and defined?(Gem::PackageTask) s.files = PKG_FILES s.require_path = 'lib' - s.add_development_dependency 'sdoc', '~>0.3.16' - s.add_development_dependency 'rake', '~>0.9.2' s.extra_rdoc_files << 'README.rdoc' s.rdoc_options << '--title' << 'JSON implemention for ruby' << '--main' << 'README.rdoc' - s.test_files.concat Dir['./tests/test_*.rb'] + s.test_files.concat Dir['./tests/*_test.rb'] s.author = "Florian Frank" s.email = "flori@ping.de" @@ -104,7 +98,7 @@ if defined?(Gem) and defined?(Gem::PackageTask) desc 'Creates a json_pure.gemspec file' task :gemspec_pure => :version do File.open('json_pure.gemspec', 'w') do |gemspec| - gemspec.write skip_sdoc(spec_pure.to_ruby) + gemspec.write spec_pure.to_ruby end end @@ -124,12 +118,11 @@ if defined?(Gem) and defined?(Gem::PackageTask) s.extensions = FileList['ext/**/extconf.rb'] s.require_path = 'lib' - s.add_development_dependency 'sdoc', '~>0.3.16' s.extra_rdoc_files << 'README.rdoc' s.rdoc_options << '--title' << 'JSON implemention for Ruby' << '--main' << 'README.rdoc' - s.test_files.concat Dir['./tests/test_*.rb'] + s.test_files.concat Dir['./tests/*_test.rb'] s.author = "Florian Frank" s.email = "flori@ping.de" @@ -140,7 +133,7 @@ if defined?(Gem) and defined?(Gem::PackageTask) desc 'Creates a json.gemspec file' task :gemspec_ext => :version do File.open('json.gemspec', 'w') do |gemspec| - gemspec.write skip_sdoc(spec_ext.to_ruby) + gemspec.write spec_ext.to_ruby end end @@ -181,7 +174,7 @@ task :test_pure => [ :clean, :check_env, :do_test_pure ] UndocumentedTestTask.new do |t| t.name = 'do_test_pure' t.libs << 'lib' << 'tests' - t.test_files = FileList['tests/test_*.rb'] + t.test_files = FileList['tests/*_test.rb'] t.verbose = true t.options = '-v' end @@ -264,7 +257,7 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby' UndocumentedTestTask.new do |t| t.name = 'do_test_ext' t.libs << 'lib' << 'tests' - t.test_files = FileList['tests/test_*.rb'] + t.test_files = FileList['tests/*_test.rb'] t.verbose = true t.options = '-v' end @@ -338,14 +331,14 @@ else UndocumentedTestTask.new do |t| t.name = 'do_test_ext' t.libs << 'ext' << 'lib' << 'tests' - t.test_files = FileList['tests/test_*.rb'] + t.test_files = FileList['tests/*_test.rb'] t.verbose = true t.options = '-v' end desc "Create RDOC documentation" task :doc => [ :version, EXT_PARSER_SRC ] do - sh "sdoc -o doc -t '#{PKG_TITLE}' -m README.rdoc README.rdoc lib/json.rb #{FileList['lib/json/**/*.rb']} #{EXT_PARSER_SRC} #{EXT_GENERATOR_SRC}" + sh "rdoc -o doc -t '#{PKG_TITLE}' -m README.rdoc README.rdoc lib/json.rb #{FileList['lib/json/**/*.rb']} #{EXT_PARSER_SRC} #{EXT_GENERATOR_SRC}" end desc "Generate parser with ragel" diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index fb7ca45..3415102 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -79,7 +79,7 @@ static VALUE mJSON, mExt, cParser, eParserError, eNestingError; static VALUE CNaN, CInfinity, CMinusInfinity; static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, - i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_quirks_mode, + i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_object_class, i_array_class, i_key_p, i_deep_const_get, i_match, i_match_string, i_aset, i_aref, i_leftshift; @@ -468,7 +468,7 @@ case 26: #line 470 "parser.c" static const int JSON_value_start = 1; -static const int JSON_value_first_final = 21; +static const int JSON_value_first_final = 29; static const int JSON_value_error = 0; static const int JSON_value_en_main = 1; @@ -495,40 +495,49 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul goto _test_eof; switch ( cs ) { +st1: + if ( ++p == pe ) + goto _test_eof1; case 1: switch( (*p) ) { - case 34: goto tr0; - case 45: goto tr2; - case 73: goto st2; - case 78: goto st9; - case 91: goto tr5; - case 102: goto st11; - case 110: goto st15; - case 116: goto st18; - case 123: goto tr9; + case 13: goto st1; + case 32: goto st1; + case 34: goto tr2; + case 45: goto tr3; + case 47: goto st6; + case 73: goto st10; + case 78: goto st17; + case 91: goto tr7; + case 102: goto st19; + case 110: goto st23; + case 116: goto st26; + case 123: goto tr11; } - if ( 48 <= (*p) && (*p) <= 57 ) - goto tr2; + if ( (*p) > 10 ) { + if ( 48 <= (*p) && (*p) <= 57 ) + goto tr3; + } else if ( (*p) >= 9 ) + goto st1; goto st0; st0: cs = 0; goto _out; -tr0: +tr2: #line 219 "parser.rl" { char *np = JSON_parse_string(json, p, pe, result); - if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;} + if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;} } - goto st21; -tr2: + goto st29; +tr3: #line 224 "parser.rl" { char *np; - if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) { + if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) { if (json->allow_nan) { *result = CMinusInfinity; {p = (( p + 10))-1;} - p--; {p++; cs = 21; goto _out;} + p--; {p++; cs = 29; goto _out;} } else { rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); } @@ -537,30 +546,30 @@ tr2: if (np != NULL) {p = (( np))-1;} np = JSON_parse_integer(json, p, pe, result); if (np != NULL) {p = (( np))-1;} - p--; {p++; cs = 21; goto _out;} + p--; {p++; cs = 29; goto _out;} } - goto st21; -tr5: + goto st29; +tr7: #line 242 "parser.rl" { char *np; json->current_nesting++; np = JSON_parse_array(json, p, pe, result); json->current_nesting--; - if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;} + if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;} } - goto st21; -tr9: + goto st29; +tr11: #line 250 "parser.rl" { char *np; json->current_nesting++; np = JSON_parse_object(json, p, pe, result); json->current_nesting--; - if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;} + if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;} } - goto st21; -tr16: + goto st29; +tr25: #line 212 "parser.rl" { if (json->allow_nan) { @@ -569,8 +578,8 @@ tr16: rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8); } } - goto st21; -tr18: + goto st29; +tr27: #line 205 "parser.rl" { if (json->allow_nan) { @@ -579,168 +588,240 @@ tr18: rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2); } } - goto st21; -tr22: + goto st29; +tr31: #line 199 "parser.rl" { *result = Qfalse; } - goto st21; -tr25: + goto st29; +tr34: #line 196 "parser.rl" { *result = Qnil; } - goto st21; -tr28: + goto st29; +tr37: #line 202 "parser.rl" { *result = Qtrue; } - goto st21; -st21: + goto st29; +st29: if ( ++p == pe ) - goto _test_eof21; -case 21: + goto _test_eof29; +case 29: #line 258 "parser.rl" - { p--; {p++; cs = 21; goto _out;} } -#line 608 "parser.c" + { p--; {p++; cs = 29; goto _out;} } +#line 617 "parser.c" + switch( (*p) ) { + case 13: goto st29; + case 32: goto st29; + case 47: goto st2; + } + if ( 9 <= (*p) && (*p) <= 10 ) + goto st29; goto st0; st2: if ( ++p == pe ) goto _test_eof2; case 2: - if ( (*p) == 110 ) - goto st3; + switch( (*p) ) { + case 42: goto st3; + case 47: goto st5; + } goto st0; st3: if ( ++p == pe ) goto _test_eof3; case 3: - if ( (*p) == 102 ) + if ( (*p) == 42 ) goto st4; - goto st0; + goto st3; st4: if ( ++p == pe ) goto _test_eof4; case 4: - if ( (*p) == 105 ) - goto st5; - goto st0; + switch( (*p) ) { + case 42: goto st4; + case 47: goto st29; + } + goto st3; st5: if ( ++p == pe ) goto _test_eof5; case 5: - if ( (*p) == 110 ) - goto st6; - goto st0; + if ( (*p) == 10 ) + goto st29; + goto st5; st6: if ( ++p == pe ) goto _test_eof6; case 6: - if ( (*p) == 105 ) - goto st7; + switch( (*p) ) { + case 42: goto st7; + case 47: goto st9; + } goto st0; st7: if ( ++p == pe ) goto _test_eof7; case 7: - if ( (*p) == 116 ) + if ( (*p) == 42 ) goto st8; - goto st0; + goto st7; st8: if ( ++p == pe ) goto _test_eof8; case 8: - if ( (*p) == 121 ) - goto tr16; - goto st0; + switch( (*p) ) { + case 42: goto st8; + case 47: goto st1; + } + goto st7; st9: if ( ++p == pe ) goto _test_eof9; case 9: - if ( (*p) == 97 ) - goto st10; - goto st0; + if ( (*p) == 10 ) + goto st1; + goto st9; st10: if ( ++p == pe ) goto _test_eof10; case 10: - if ( (*p) == 78 ) - goto tr18; + if ( (*p) == 110 ) + goto st11; goto st0; st11: if ( ++p == pe ) goto _test_eof11; case 11: - if ( (*p) == 97 ) + if ( (*p) == 102 ) goto st12; goto st0; st12: if ( ++p == pe ) goto _test_eof12; case 12: - if ( (*p) == 108 ) + if ( (*p) == 105 ) goto st13; goto st0; st13: if ( ++p == pe ) goto _test_eof13; case 13: - if ( (*p) == 115 ) + if ( (*p) == 110 ) goto st14; goto st0; st14: if ( ++p == pe ) goto _test_eof14; case 14: - if ( (*p) == 101 ) - goto tr22; + if ( (*p) == 105 ) + goto st15; goto st0; st15: if ( ++p == pe ) goto _test_eof15; case 15: - if ( (*p) == 117 ) + if ( (*p) == 116 ) goto st16; goto st0; st16: if ( ++p == pe ) goto _test_eof16; case 16: - if ( (*p) == 108 ) - goto st17; + if ( (*p) == 121 ) + goto tr25; goto st0; st17: if ( ++p == pe ) goto _test_eof17; case 17: - if ( (*p) == 108 ) - goto tr25; + if ( (*p) == 97 ) + goto st18; goto st0; st18: if ( ++p == pe ) goto _test_eof18; case 18: - if ( (*p) == 114 ) - goto st19; + if ( (*p) == 78 ) + goto tr27; goto st0; st19: if ( ++p == pe ) goto _test_eof19; case 19: - if ( (*p) == 117 ) + if ( (*p) == 97 ) goto st20; goto st0; st20: if ( ++p == pe ) goto _test_eof20; case 20: + if ( (*p) == 108 ) + goto st21; + goto st0; +st21: + if ( ++p == pe ) + goto _test_eof21; +case 21: + if ( (*p) == 115 ) + goto st22; + goto st0; +st22: + if ( ++p == pe ) + goto _test_eof22; +case 22: if ( (*p) == 101 ) - goto tr28; + goto tr31; + goto st0; +st23: + if ( ++p == pe ) + goto _test_eof23; +case 23: + if ( (*p) == 117 ) + goto st24; + goto st0; +st24: + if ( ++p == pe ) + goto _test_eof24; +case 24: + if ( (*p) == 108 ) + goto st25; + goto st0; +st25: + if ( ++p == pe ) + goto _test_eof25; +case 25: + if ( (*p) == 108 ) + goto tr34; + goto st0; +st26: + if ( ++p == pe ) + goto _test_eof26; +case 26: + if ( (*p) == 114 ) + goto st27; + goto st0; +st27: + if ( ++p == pe ) + goto _test_eof27; +case 27: + if ( (*p) == 117 ) + goto st28; + goto st0; +st28: + if ( ++p == pe ) + goto _test_eof28; +case 28: + if ( (*p) == 101 ) + goto tr37; goto st0; } - _test_eof21: cs = 21; goto _test_eof; + _test_eof1: cs = 1; goto _test_eof; + _test_eof29: cs = 29; goto _test_eof; _test_eof2: cs = 2; goto _test_eof; _test_eof3: cs = 3; goto _test_eof; _test_eof4: cs = 4; goto _test_eof; @@ -760,6 +841,14 @@ case 20: _test_eof18: cs = 18; goto _test_eof; _test_eof19: cs = 19; goto _test_eof; _test_eof20: cs = 20; goto _test_eof; + _test_eof21: cs = 21; goto _test_eof; + _test_eof22: cs = 22; goto _test_eof; + _test_eof23: cs = 23; goto _test_eof; + _test_eof24: cs = 24; goto _test_eof; + _test_eof25: cs = 25; goto _test_eof; + _test_eof26: cs = 26; goto _test_eof; + _test_eof27: cs = 27; goto _test_eof; + _test_eof28: cs = 28; goto _test_eof; _test_eof: {} _out: {} @@ -775,7 +864,7 @@ case 20: } -#line 779 "parser.c" +#line 868 "parser.c" static const int JSON_integer_start = 1; static const int JSON_integer_first_final = 3; static const int JSON_integer_error = 0; @@ -791,7 +880,7 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res int cs = EVIL; -#line 795 "parser.c" +#line 884 "parser.c" { cs = JSON_integer_start; } @@ -799,7 +888,7 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res #line 302 "parser.rl" json->memo = p; -#line 803 "parser.c" +#line 892 "parser.c" { if ( p == pe ) goto _test_eof; @@ -840,7 +929,7 @@ st4: if ( ++p == pe ) goto _test_eof4; case 4: -#line 844 "parser.c" +#line 933 "parser.c" goto st0; st5: if ( ++p == pe ) @@ -874,7 +963,7 @@ case 5: } -#line 878 "parser.c" +#line 967 "parser.c" static const int JSON_float_start = 1; static const int JSON_float_first_final = 8; static const int JSON_float_error = 0; @@ -890,7 +979,7 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul int cs = EVIL; -#line 894 "parser.c" +#line 983 "parser.c" { cs = JSON_float_start; } @@ -898,7 +987,7 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul #line 336 "parser.rl" json->memo = p; -#line 902 "parser.c" +#line 991 "parser.c" { if ( p == pe ) goto _test_eof; @@ -963,7 +1052,7 @@ st9: if ( ++p == pe ) goto _test_eof9; case 9: -#line 967 "parser.c" +#line 1056 "parser.c" goto st0; st5: if ( ++p == pe ) @@ -1040,7 +1129,7 @@ case 7: -#line 1044 "parser.c" +#line 1133 "parser.c" static const int JSON_array_start = 1; static const int JSON_array_first_final = 17; static const int JSON_array_error = 0; @@ -1062,14 +1151,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class); -#line 1066 "parser.c" +#line 1155 "parser.c" { cs = JSON_array_start; } #line 394 "parser.rl" -#line 1073 "parser.c" +#line 1162 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1128,7 +1217,7 @@ st3: if ( ++p == pe ) goto _test_eof3; case 3: -#line 1132 "parser.c" +#line 1221 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; @@ -1235,7 +1324,7 @@ st17: if ( ++p == pe ) goto _test_eof17; case 17: -#line 1239 "parser.c" +#line 1328 "parser.c" goto st0; st13: if ( ++p == pe ) @@ -1372,7 +1461,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd) } -#line 1376 "parser.c" +#line 1465 "parser.c" static const int JSON_string_start = 1; static const int JSON_string_first_final = 8; static const int JSON_string_error = 0; @@ -1402,7 +1491,7 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu *result = rb_str_buf_new(0); -#line 1406 "parser.c" +#line 1495 "parser.c" { cs = JSON_string_start; } @@ -1410,7 +1499,7 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu #line 515 "parser.rl" json->memo = p; -#line 1414 "parser.c" +#line 1503 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1453,7 +1542,7 @@ st8: if ( ++p == pe ) goto _test_eof8; case 8: -#line 1457 "parser.c" +#line 1546 "parser.c" goto st0; st3: if ( ++p == pe ) @@ -1566,8 +1655,6 @@ case 7: static VALUE convert_encoding(VALUE source) { - char *ptr = RSTRING_PTR(source); - long len = RSTRING_LEN(source); #ifdef HAVE_RUBY_ENCODING_H { source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8); @@ -1640,13 +1727,6 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } else { json->symbolize_names = 0; } - tmp = ID2SYM(i_quirks_mode); - if (option_given_p(opts, tmp)) { - VALUE quirks_mode = rb_hash_aref(opts, tmp); - json->quirks_mode = RTEST(quirks_mode) ? 1 : 0; - } else { - json->quirks_mode = 0; - } tmp = ID2SYM(i_create_additions); if (option_given_p(opts, tmp)) { json->create_additions = RTEST(rb_hash_aref(opts, tmp)); @@ -1688,9 +1768,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) json->array_class = Qnil; } source = rb_convert_type(source, T_STRING, "String", "to_str"); - if (!json->quirks_mode) { - source = convert_encoding(StringValue(source)); - } + source = convert_encoding(StringValue(source)); json->current_nesting = 0; StringValue(source); json->len = RSTRING_LEN(source); @@ -1700,7 +1778,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } -#line 1704 "parser.c" +#line 1782 "parser.c" static const int JSON_start = 1; static const int JSON_first_final = 10; static const int JSON_error = 0; @@ -1708,201 +1786,33 @@ static const int JSON_error = 0; static const int JSON_en_main = 1; -#line 711 "parser.rl" +#line 690 "parser.rl" -static VALUE cParser_parse_strict(VALUE self) +/* + * call-seq: parse() + * + * Parses the current JSON text _source_ and returns the complete data + * structure as a result. + */ +static VALUE cParser_parse(VALUE self) { - char *p, *pe; - int cs = EVIL; - VALUE result = Qnil; - GET_PARSER; + char *p, *pe; + int cs = EVIL; + VALUE result = Qnil; + GET_PARSER; -#line 1723 "parser.c" +#line 1807 "parser.c" { cs = JSON_start; } -#line 721 "parser.rl" - p = json->source; - pe = p + json->len; +#line 706 "parser.rl" + p = json->source; + pe = p + json->len; -#line 1732 "parser.c" - { - if ( p == pe ) - goto _test_eof; - switch ( cs ) - { -st1: - if ( ++p == pe ) - goto _test_eof1; -case 1: - switch( (*p) ) { - case 13: goto st1; - case 32: goto st1; - case 47: goto st2; - case 91: goto tr3; - case 123: goto tr4; - } - if ( 9 <= (*p) && (*p) <= 10 ) - goto st1; - goto st0; -st0: -cs = 0; - goto _out; -st2: - if ( ++p == pe ) - goto _test_eof2; -case 2: - switch( (*p) ) { - case 42: goto st3; - case 47: goto st5; - } - goto st0; -st3: - if ( ++p == pe ) - goto _test_eof3; -case 3: - if ( (*p) == 42 ) - goto st4; - goto st3; -st4: - if ( ++p == pe ) - goto _test_eof4; -case 4: - switch( (*p) ) { - case 42: goto st4; - case 47: goto st1; - } - goto st3; -st5: - if ( ++p == pe ) - goto _test_eof5; -case 5: - if ( (*p) == 10 ) - goto st1; - goto st5; -tr3: -#line 700 "parser.rl" - { - char *np; - json->current_nesting = 1; - np = JSON_parse_array(json, p, pe, &result); - if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} - } - goto st10; -tr4: -#line 693 "parser.rl" - { - char *np; - json->current_nesting = 1; - np = JSON_parse_object(json, p, pe, &result); - if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} - } - goto st10; -st10: - if ( ++p == pe ) - goto _test_eof10; -case 10: -#line 1809 "parser.c" - switch( (*p) ) { - case 13: goto st10; - case 32: goto st10; - case 47: goto st6; - } - if ( 9 <= (*p) && (*p) <= 10 ) - goto st10; - goto st0; -st6: - if ( ++p == pe ) - goto _test_eof6; -case 6: - switch( (*p) ) { - case 42: goto st7; - case 47: goto st9; - } - goto st0; -st7: - if ( ++p == pe ) - goto _test_eof7; -case 7: - if ( (*p) == 42 ) - goto st8; - goto st7; -st8: - if ( ++p == pe ) - goto _test_eof8; -case 8: - switch( (*p) ) { - case 42: goto st8; - case 47: goto st10; - } - goto st7; -st9: - if ( ++p == pe ) - goto _test_eof9; -case 9: - if ( (*p) == 10 ) - goto st10; - goto st9; - } - _test_eof1: cs = 1; goto _test_eof; - _test_eof2: cs = 2; goto _test_eof; - _test_eof3: cs = 3; goto _test_eof; - _test_eof4: cs = 4; goto _test_eof; - _test_eof5: cs = 5; goto _test_eof; - _test_eof10: cs = 10; goto _test_eof; - _test_eof6: cs = 6; goto _test_eof; - _test_eof7: cs = 7; goto _test_eof; - _test_eof8: cs = 8; goto _test_eof; - _test_eof9: cs = 9; goto _test_eof; - - _test_eof: {} - _out: {} - } - -#line 724 "parser.rl" - - if (cs >= JSON_first_final && p == pe) { - return result; - } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); - return Qnil; - } -} - - - -#line 1878 "parser.c" -static const int JSON_quirks_mode_start = 1; -static const int JSON_quirks_mode_first_final = 10; -static const int JSON_quirks_mode_error = 0; - -static const int JSON_quirks_mode_en_main = 1; - - -#line 749 "parser.rl" - - -static VALUE cParser_parse_quirks_mode(VALUE self) -{ - char *p, *pe; - int cs = EVIL; - VALUE result = Qnil; - GET_PARSER; - - -#line 1897 "parser.c" - { - cs = JSON_quirks_mode_start; - } - -#line 759 "parser.rl" - p = json->source; - pe = p + json->len; - -#line 1906 "parser.c" +#line 1816 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1936,7 +1846,7 @@ st0: cs = 0; goto _out; tr2: -#line 741 "parser.rl" +#line 682 "parser.rl" { char *np = JSON_parse_value(json, p, pe, &result); if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} @@ -1946,7 +1856,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1950 "parser.c" +#line 1860 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -2035,30 +1945,13 @@ case 9: _out: {} } -#line 762 "parser.rl" - - if (cs >= JSON_quirks_mode_first_final && p == pe) { - return result; - } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); - return Qnil; - } -} - -/* - * call-seq: parse() - * - * Parses the current JSON text _source_ and returns the complete data - * structure as a result. - */ -static VALUE cParser_parse(VALUE self) -{ - GET_PARSER; +#line 709 "parser.rl" - if (json->quirks_mode) { - return cParser_parse_quirks_mode(self); + if (cs >= JSON_first_final && p == pe) { + return result; } else { - return cParser_parse_strict(self); + rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); + return Qnil; } } @@ -2116,18 +2009,6 @@ static VALUE cParser_source(VALUE self) return rb_str_dup(json->Vsource); } -/* - * call-seq: quirks_mode?() - * - * Returns a true, if this parser is in quirks_mode, false otherwise. - */ -static VALUE cParser_quirks_mode_p(VALUE self) -{ - GET_PARSER; - return json->quirks_mode ? Qtrue : Qfalse; -} - - void Init_parser(void) { rb_require("json/common"); @@ -2140,7 +2021,6 @@ void Init_parser(void) rb_define_method(cParser, "initialize", cParser_initialize, -1); rb_define_method(cParser, "parse", cParser_parse, 0); rb_define_method(cParser, "source", cParser_source, 0); - rb_define_method(cParser, "quirks_mode?", cParser_quirks_mode_p, 0); CNaN = rb_const_get(mJSON, rb_intern("NaN")); CInfinity = rb_const_get(mJSON, rb_intern("Infinity")); @@ -2154,7 +2034,6 @@ void Init_parser(void) i_max_nesting = rb_intern("max_nesting"); i_allow_nan = rb_intern("allow_nan"); i_symbolize_names = rb_intern("symbolize_names"); - i_quirks_mode = rb_intern("quirks_mode"); i_object_class = rb_intern("object_class"); i_array_class = rb_intern("array_class"); i_match = rb_intern("match"); diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h index abcc257..ec26e85 100644 --- a/ext/json/ext/parser/parser.h +++ b/ext/json/ext/parser/parser.h @@ -38,7 +38,6 @@ typedef struct JSON_ParserStruct { int allow_nan; int parsing_name; int symbolize_names; - int quirks_mode; VALUE object_class; VALUE array_class; int create_additions; diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index a34245e..5d6933d 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -77,7 +77,7 @@ static VALUE mJSON, mExt, cParser, eParserError, eNestingError; static VALUE CNaN, CInfinity, CMinusInfinity; static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, - i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_quirks_mode, + i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_object_class, i_array_class, i_key_p, i_deep_const_get, i_match, i_match_string, i_aset, i_aref, i_leftshift; @@ -223,7 +223,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu action parse_number { char *np; - if(pe > fpc + 9 - json->quirks_mode && !strncmp(MinusInfinity, fpc, 9)) { + if(pe > fpc + 8 && !strncmp(MinusInfinity, fpc, 9)) { if (json->allow_nan) { *result = CMinusInfinity; fexec p + 10; @@ -257,7 +257,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu action exit { fhold; fbreak; } -main := ( +main := ignore* ( Vnull @parse_null | Vfalse @parse_false | Vtrue @parse_true | @@ -267,7 +267,7 @@ main := ( begin_string >parse_string | begin_array >parse_array | begin_object >parse_object - ) %*exit; + ) ignore* %*exit; }%% static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -550,8 +550,6 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu static VALUE convert_encoding(VALUE source) { - char *ptr = RSTRING_PTR(source); - long len = RSTRING_LEN(source); #ifdef HAVE_RUBY_ENCODING_H { source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8); @@ -624,13 +622,6 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } else { json->symbolize_names = 0; } - tmp = ID2SYM(i_quirks_mode); - if (option_given_p(opts, tmp)) { - VALUE quirks_mode = rb_hash_aref(opts, tmp); - json->quirks_mode = RTEST(quirks_mode) ? 1 : 0; - } else { - json->quirks_mode = 0; - } tmp = ID2SYM(i_create_additions); if (option_given_p(opts, tmp)) { json->create_additions = RTEST(rb_hash_aref(opts, tmp)); @@ -672,9 +663,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) json->array_class = Qnil; } source = rb_convert_type(source, T_STRING, "String", "to_str"); - if (!json->quirks_mode) { - source = convert_encoding(StringValue(source)); - } + source = convert_encoding(StringValue(source)); json->current_nesting = 0; StringValue(source); json->len = RSTRING_LEN(source); @@ -690,54 +679,6 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) include JSON_common; - action parse_object { - char *np; - json->current_nesting = 1; - np = JSON_parse_object(json, fpc, pe, &result); - if (np == NULL) { fhold; fbreak; } else fexec np; - } - - action parse_array { - char *np; - json->current_nesting = 1; - np = JSON_parse_array(json, fpc, pe, &result); - if (np == NULL) { fhold; fbreak; } else fexec np; - } - - main := ignore* ( - begin_object >parse_object | - begin_array >parse_array - ) ignore*; -}%% - -static VALUE cParser_parse_strict(VALUE self) -{ - char *p, *pe; - int cs = EVIL; - VALUE result = Qnil; - GET_PARSER; - - %% write init; - p = json->source; - pe = p + json->len; - %% write exec; - - if (cs >= JSON_first_final && p == pe) { - return result; - } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); - return Qnil; - } -} - - -%%{ - machine JSON_quirks_mode; - - write data; - - include JSON_common; - action parse_value { char *np = JSON_parse_value(json, fpc, pe, &result); if (np == NULL) { fhold; fbreak; } else fexec np; @@ -748,26 +689,6 @@ static VALUE cParser_parse_strict(VALUE self) ) ignore*; }%% -static VALUE cParser_parse_quirks_mode(VALUE self) -{ - char *p, *pe; - int cs = EVIL; - VALUE result = Qnil; - GET_PARSER; - - %% write init; - p = json->source; - pe = p + json->len; - %% write exec; - - if (cs >= JSON_quirks_mode_first_final && p == pe) { - return result; - } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); - return Qnil; - } -} - /* * call-seq: parse() * @@ -776,12 +697,21 @@ static VALUE cParser_parse_quirks_mode(VALUE self) */ static VALUE cParser_parse(VALUE self) { + char *p, *pe; + int cs = EVIL; + VALUE result = Qnil; GET_PARSER; - if (json->quirks_mode) { - return cParser_parse_quirks_mode(self); + %% write init; + p = json->source; + pe = p + json->len; + %% write exec; + + if (cs >= JSON_first_final && p == pe) { + return result; } else { - return cParser_parse_strict(self); + rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); + return Qnil; } } @@ -839,18 +769,6 @@ static VALUE cParser_source(VALUE self) return rb_str_dup(json->Vsource); } -/* - * call-seq: quirks_mode?() - * - * Returns a true, if this parser is in quirks_mode, false otherwise. - */ -static VALUE cParser_quirks_mode_p(VALUE self) -{ - GET_PARSER; - return json->quirks_mode ? Qtrue : Qfalse; -} - - void Init_parser(void) { rb_require("json/common"); @@ -863,7 +781,6 @@ void Init_parser(void) rb_define_method(cParser, "initialize", cParser_initialize, -1); rb_define_method(cParser, "parse", cParser_parse, 0); rb_define_method(cParser, "source", cParser_source, 0); - rb_define_method(cParser, "quirks_mode?", cParser_quirks_mode_p, 0); CNaN = rb_const_get(mJSON, rb_intern("NaN")); CInfinity = rb_const_get(mJSON, rb_intern("Infinity")); @@ -877,7 +794,6 @@ void Init_parser(void) i_max_nesting = rb_intern("max_nesting"); i_allow_nan = rb_intern("allow_nan"); i_symbolize_names = rb_intern("symbolize_names"); - i_quirks_mode = rb_intern("quirks_mode"); i_object_class = rb_intern("object_class"); i_array_class = rb_intern("array_class"); i_match = rb_intern("match"); diff --git a/ext/json/extconf.rb b/ext/json/extconf.rb index 850798c..7595d58 100644 --- a/ext/json/extconf.rb +++ b/ext/json/extconf.rb @@ -1,3 +1,2 @@ require 'mkmf' create_makefile('json') - diff --git a/json.gemspec b/json.gemspec Binary files differindex 75f1ae9..5bd9463 100644 --- a/json.gemspec +++ b/json.gemspec diff --git a/json_pure.gemspec b/json_pure.gemspec index 9b2fe03..843fe6d 100644 --- a/json_pure.gemspec +++ b/json_pure.gemspec @@ -12,26 +12,11 @@ Gem::Specification.new do |s| s.description = "This is a JSON implementation in pure Ruby." s.email = "flori@ping.de" s.extra_rdoc_files = ["README.rdoc"] - s.files = ["./tests/test_helper.rb", ".gitignore", ".travis.yml", "CHANGES", "COPYING", "COPYING-json-jruby", "GPL", "Gemfile", "README-json-jruby.markdown", "README.rdoc", "Rakefile", "TODO", "VERSION", "data/example.json", "data/index.html", "data/prototype.js", "diagrams/.keep", "ext/json/ext/fbuffer/fbuffer.h", "ext/json/ext/generator/depend", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/generator.h", "ext/json/ext/parser/depend", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.c", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/parser.rl", "ext/json/extconf.rb", "install.rb", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/GeneratorMethods.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/Parser.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/ParserService.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/Utils.java", "json-java.gemspec", "json.gemspec", "json_pure.gemspec", "lib/json.rb", "lib/json/add/bigdecimal.rb", "lib/json/add/complex.rb", "lib/json/add/core.rb", "lib/json/add/date.rb", "lib/json/add/date_time.rb", "lib/json/add/exception.rb", "lib/json/add/ostruct.rb", "lib/json/add/range.rb", "lib/json/add/rational.rb", "lib/json/add/regexp.rb", "lib/json/add/struct.rb", "lib/json/add/symbol.rb", "lib/json/add/time.rb", "lib/json/common.rb", "lib/json/ext.rb", "lib/json/ext/.keep", "lib/json/generic_object.rb", "lib/json/pure.rb", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/version.rb", "tests/fixtures/fail10.json", "tests/fixtures/fail11.json", "tests/fixtures/fail12.json", "tests/fixtures/fail13.json", "tests/fixtures/fail14.json", "tests/fixtures/fail18.json", "tests/fixtures/fail19.json", "tests/fixtures/fail2.json", "tests/fixtures/fail20.json", "tests/fixtures/fail21.json", "tests/fixtures/fail22.json", "tests/fixtures/fail23.json", "tests/fixtures/fail24.json", "tests/fixtures/fail25.json", "tests/fixtures/fail27.json", "tests/fixtures/fail28.json", "tests/fixtures/fail3.json", "tests/fixtures/fail4.json", "tests/fixtures/fail5.json", "tests/fixtures/fail6.json", "tests/fixtures/fail7.json", "tests/fixtures/fail8.json", "tests/fixtures/fail9.json", "tests/fixtures/obsolete_fail1.json", "tests/fixtures/pass1.json", "tests/fixtures/pass15.json", "tests/fixtures/pass16.json", "tests/fixtures/pass17.json", "tests/fixtures/pass2.json", "tests/fixtures/pass26.json", "tests/fixtures/pass3.json", "tests/json_addition_test.rb", "tests/json_common_interface_test.rb", "tests/json_encoding_test.rb", "tests/json_ext_parser_test.rb", "tests/json_fixtures_test.rb", "tests/json_generator_test.rb", "tests/json_generic_object_test.rb", "tests/json_parser_test.rb", "tests/json_string_matching_test.rb", "tests/test_helper.rb", "tools/fuzz.rb", "tools/server.rb"] + s.files = ["./tests/json_addition_test.rb", "./tests/json_common_interface_test.rb", "./tests/json_encoding_test.rb", "./tests/json_ext_parser_test.rb", "./tests/json_fixtures_test.rb", "./tests/json_generator_test.rb", "./tests/json_generic_object_test.rb", "./tests/json_parser_test.rb", "./tests/json_string_matching_test.rb", ".gitignore", ".travis.yml", "CHANGES", "COPYING", "COPYING-json-jruby", "GPL", "Gemfile", "README-json-jruby.markdown", "README.rdoc", "Rakefile", "TODO", "VERSION", "data/example.json", "data/index.html", "data/prototype.js", "diagrams/.keep", "ext/json/ext/fbuffer/fbuffer.h", "ext/json/ext/generator/depend", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/generator.h", "ext/json/ext/parser/depend", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.c", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/parser.rl", "ext/json/extconf.rb", "install.rb", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/GeneratorMethods.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/Parser.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/ParserService.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/Utils.java", "json-java.gemspec", "json.gemspec", "json_pure.gemspec", "lib/json.rb", "lib/json/add/bigdecimal.rb", "lib/json/add/complex.rb", "lib/json/add/core.rb", "lib/json/add/date.rb", "lib/json/add/date_time.rb", "lib/json/add/exception.rb", "lib/json/add/ostruct.rb", "lib/json/add/range.rb", "lib/json/add/rational.rb", "lib/json/add/regexp.rb", "lib/json/add/struct.rb", "lib/json/add/symbol.rb", "lib/json/add/time.rb", "lib/json/common.rb", "lib/json/ext.rb", "lib/json/ext/.keep", "lib/json/generic_object.rb", "lib/json/pure.rb", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/version.rb", "tests/fixtures/fail10.json", "tests/fixtures/fail11.json", "tests/fixtures/fail12.json", "tests/fixtures/fail13.json", "tests/fixtures/fail14.json", "tests/fixtures/fail18.json", "tests/fixtures/fail19.json", "tests/fixtures/fail2.json", "tests/fixtures/fail20.json", "tests/fixtures/fail21.json", "tests/fixtures/fail22.json", "tests/fixtures/fail23.json", "tests/fixtures/fail24.json", "tests/fixtures/fail25.json", "tests/fixtures/fail27.json", "tests/fixtures/fail28.json", "tests/fixtures/fail3.json", "tests/fixtures/fail4.json", "tests/fixtures/fail5.json", "tests/fixtures/fail6.json", "tests/fixtures/fail7.json", "tests/fixtures/fail8.json", "tests/fixtures/fail9.json", "tests/fixtures/obsolete_fail1.json", "tests/fixtures/pass1.json", "tests/fixtures/pass15.json", "tests/fixtures/pass16.json", "tests/fixtures/pass17.json", "tests/fixtures/pass2.json", "tests/fixtures/pass26.json", "tests/fixtures/pass3.json", "tests/json_addition_test.rb", "tests/json_common_interface_test.rb", "tests/json_encoding_test.rb", "tests/json_ext_parser_test.rb", "tests/json_fixtures_test.rb", "tests/json_generator_test.rb", "tests/json_generic_object_test.rb", "tests/json_parser_test.rb", "tests/json_string_matching_test.rb", "tests/test_helper.rb", "tools/fuzz.rb", "tools/server.rb"] s.homepage = "http://flori.github.com/json" s.licenses = ["Ruby"] s.rdoc_options = ["--title", "JSON implemention for ruby", "--main", "README.rdoc"] s.rubygems_version = "2.4.6" s.summary = "JSON Implementation for Ruby" - s.test_files = ["./tests/test_helper.rb"] - - if s.respond_to? :specification_version then - s.specification_version = 4 - - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_development_dependency(%q<sdoc>, ["~> 0.3.16"]) if RUBY_VERSION > "1.8.6" - s.add_development_dependency(%q<rake>, ["~> 0.9.2"]) - else - s.add_dependency(%q<sdoc>, ["~> 0.3.16"]) if RUBY_VERSION > "1.8.6" - s.add_dependency(%q<rake>, ["~> 0.9.2"]) - end - else - s.add_dependency(%q<sdoc>, ["~> 0.3.16"]) if RUBY_VERSION > "1.8.6" - s.add_dependency(%q<rake>, ["~> 0.9.2"]) - end + s.test_files = ["./tests/json_addition_test.rb", "./tests/json_common_interface_test.rb", "./tests/json_encoding_test.rb", "./tests/json_ext_parser_test.rb", "./tests/json_fixtures_test.rb", "./tests/json_generator_test.rb", "./tests/json_generic_object_test.rb", "./tests/json_parser_test.rb", "./tests/json_string_matching_test.rb"] end |