1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/syck/bytecode.c: turn off default implicit typing.

* ext/syck/implicit.c: detect base60 integers.

* ext/syck/rubyext.c: handle base60, as well as hex and octal
  with commas.  implicit typing of ruby symbols.

* test/yaml/test_yaml.rb: add test.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
why 2004-01-12 22:55:09 +00:00
parent 84c0dcfca2
commit 52e0ab245a
5 changed files with 1253 additions and 1153 deletions

View file

@ -1,3 +1,14 @@
Tue Jan 13 07:52:40 2004 why the lucky stiff <why@ruby-lang.org>
* ext/syck/bytecode.c: turn off default implicit typing.
* ext/syck/implicit.c: detect base60 integers.
* ext/syck/rubyext.c: handle base60, as well as hex and octal
with commas. implicit typing of ruby symbols.
* test/yaml/test_yaml.rb: add test.
Tue Jan 13 04:29:52 2004 Dave Thomas <dave@pragprog.com> Tue Jan 13 04:29:52 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/ri/ri_driver.rb (RiDriver::report_method_stuff): * lib/rdoc/ri/ri_driver.rb (RiDriver::report_method_stuff):

View file

@ -1,4 +1,4 @@
/* Generated by re2c 0.5 on Sun Nov 23 14:51:02 2003 */ /* Generated by re2c 0.5 on Mon Jan 12 11:40:10 2004 */
#line 1 "bytecode.re" #line 1 "bytecode.re"
/* /*
* bytecode.re * bytecode.re
@ -510,7 +510,7 @@ yy44: yych = *++YYCURSOR;
Directive: Directive:
{ {
YYTOKTMP = YYCURSOR; YYTOKEN = YYCURSOR;
{ {
YYCTYPE yych; YYCTYPE yych;
@ -611,7 +611,7 @@ yy48: yyaccept = 0;
} }
yy49: yy49:
#line 400 #line 400
{ YYCURSOR = YYTOKTMP; { YYCURSOR = YYTOKEN;
return YAML_DOCSEP; return YAML_DOCSEP;
} }
yy50: yych = *++YYCURSOR; yy50: yych = *++YYCURSOR;
@ -876,7 +876,7 @@ yy58: yych = *++YYCURSOR;
Comment: Comment:
{ {
YYTOKTMP = YYCURSOR; YYTOKEN = YYCURSOR;
{ {
YYCTYPE yych; YYCTYPE yych;

File diff suppressed because it is too large Load diff

View file

@ -412,7 +412,7 @@ yaml_org_handler( n, ref )
{ {
case syck_str_kind: case syck_str_kind:
transferred = 1; transferred = 1;
if ( type_id == NULL || strcmp( type_id, "str" ) == 0 ) if ( type_id == NULL )
{ {
obj = rb_str_new( n->data.str->ptr, n->data.str->len ); obj = rb_str_new( n->data.str->ptr, n->data.str->len );
} }
@ -438,12 +438,39 @@ yaml_org_handler( n, ref )
} }
else if ( strcmp( type_id, "int#hex" ) == 0 ) else if ( strcmp( type_id, "int#hex" ) == 0 )
{ {
syck_str_blow_away_commas( n );
obj = rb_cstr2inum( n->data.str->ptr, 16 ); obj = rb_cstr2inum( n->data.str->ptr, 16 );
} }
else if ( strcmp( type_id, "int#oct" ) == 0 ) else if ( strcmp( type_id, "int#oct" ) == 0 )
{ {
syck_str_blow_away_commas( n );
obj = rb_cstr2inum( n->data.str->ptr, 8 ); obj = rb_cstr2inum( n->data.str->ptr, 8 );
} }
else if ( strcmp( type_id, "int#base60" ) == 0 )
{
char *ptr, *end;
long sixty = 1;
long total = 0;
syck_str_blow_away_commas( n );
ptr = n->data.str->ptr;
end = n->data.str->ptr + n->data.str->len;
while ( end > ptr )
{
long bnum = 0;
char *colon = end - 1;
while ( colon >= ptr && *colon != ':' )
{
colon--;
}
if ( *colon == ':' ) *colon = '\0';
bnum = strtol( colon + 1, NULL, 10 );
total += bnum * sixty;
sixty *= 60;
end = colon;
}
obj = INT2FIX(total);
}
else if ( strncmp( type_id, "int", 3 ) == 0 ) else if ( strncmp( type_id, "int", 3 ) == 0 )
{ {
syck_str_blow_away_commas( n ); syck_str_blow_away_commas( n );
@ -495,27 +522,30 @@ yaml_org_handler( n, ref )
while ( !ISDIGIT( *ptr ) ) ptr++; while ( !ISDIGIT( *ptr ) ) ptr++;
day = INT2FIX(strtol(ptr, NULL, 10)); day = INT2FIX(strtol(ptr, NULL, 10));
if ( !cDate ) {
/*
* Load Date module
*/
rb_require( "date" );
cDate = rb_const_get( rb_cObject, rb_intern("Date") );
}
obj = rb_funcall( cDate, s_new, 3, year, mon, day ); obj = rb_funcall( cDate, s_new, 3, year, mon, day );
} }
else if ( strncmp( type_id, "timestamp", 9 ) == 0 ) else if ( strncmp( type_id, "timestamp", 9 ) == 0 )
{ {
obj = rb_syck_mktime( n->data.str->ptr ); obj = rb_syck_mktime( n->data.str->ptr );
} }
else if ( strncmp( type_id, "merge", 5 ) == 0 ) else if ( strncmp( type_id, "merge", 5 ) == 0 )
{
obj = rb_funcall( cMergeKey, s_new, 0 );
}
else if ( strncmp( type_id, "default", 7 ) == 0 )
{
obj = rb_funcall( cDefaultKey, s_new, 0 );
}
else if ( strncmp( n->data.str->ptr, ":", 1 ) == 0 )
{ {
obj = rb_funcall( cMergeKey, s_new, 0 ); char *tmp;
tmp = syck_strndup( n->data.str->ptr + 1, n->data.str->len - 1 );
obj = ID2SYM( rb_intern( tmp ) );
free( tmp );
} }
else if ( strncmp( type_id, "default", 7 ) == 0 ) else if ( strcmp( type_id, "str" ) == 0 )
{ {
obj = rb_funcall( cDefaultKey, s_new, 0 ); obj = rb_str_new( n->data.str->ptr, n->data.str->len );
} }
else else
{ {
@ -544,46 +574,46 @@ yaml_org_handler( n, ref )
obj = rb_hash_new(); obj = rb_hash_new();
for ( i = 0; i < n->data.pairs->idx; i++ ) for ( i = 0; i < n->data.pairs->idx; i++ )
{ {
VALUE k = syck_map_read( n, map_key, i ); VALUE k = syck_map_read( n, map_key, i );
VALUE v = syck_map_read( n, map_value, i ); VALUE v = syck_map_read( n, map_value, i );
int skip_aset = 0; int skip_aset = 0;
/* /*
* Handle merge keys * Handle merge keys
*/ */
if ( rb_obj_is_kind_of( k, cMergeKey ) ) if ( rb_obj_is_kind_of( k, cMergeKey ) )
{ {
if ( rb_obj_is_kind_of( v, rb_cHash ) ) if ( rb_obj_is_kind_of( v, rb_cHash ) )
{ {
VALUE dup = rb_funcall( v, s_dup, 0 ); VALUE dup = rb_funcall( v, s_dup, 0 );
rb_funcall( dup, s_update, 1, obj ); rb_funcall( dup, s_update, 1, obj );
obj = dup; obj = dup;
skip_aset = 1; skip_aset = 1;
} }
else if ( rb_obj_is_kind_of( v, rb_cArray ) ) else if ( rb_obj_is_kind_of( v, rb_cArray ) )
{ {
VALUE end = rb_ary_pop( v ); VALUE end = rb_ary_pop( v );
if ( rb_obj_is_kind_of( end, rb_cHash ) ) if ( rb_obj_is_kind_of( end, rb_cHash ) )
{ {
VALUE dup = rb_funcall( end, s_dup, 0 ); VALUE dup = rb_funcall( end, s_dup, 0 );
v = rb_ary_reverse( v ); v = rb_ary_reverse( v );
rb_ary_push( v, obj ); rb_ary_push( v, obj );
rb_iterate( rb_each, v, syck_merge_i, dup ); rb_iterate( rb_each, v, syck_merge_i, dup );
obj = dup; obj = dup;
skip_aset = 1; skip_aset = 1;
} }
} }
} }
else if ( rb_obj_is_kind_of( k, cDefaultKey ) ) else if ( rb_obj_is_kind_of( k, cDefaultKey ) )
{ {
rb_funcall( obj, s_default_set, 1, v ); rb_funcall( obj, s_default_set, 1, v );
skip_aset = 1; skip_aset = 1;
} }
if ( ! skip_aset ) if ( ! skip_aset )
{ {
rb_hash_aset( obj, k, v ); rb_hash_aset( obj, k, v );
} }
} }
break; break;
} }

View file

@ -442,6 +442,14 @@ octal: 014
hexadecimal: 0xC hexadecimal: 0xC
EOY EOY
) )
assert_parse_only(
{ 'canonical' => 685230, 'decimal' => 685230, 'octal' => '02472256'.oct, 'hexadecimal' => '0x0A74AE'.hex, 'sexagesimal' => 685230 }, <<EOY
canonical: 685230
decimal: +685,230
octal: 02472256
hexadecimal: 0x0A,74,AE
sexagesimal: 190:20:30
EOY
end end
def test_spec_type_float def test_spec_type_float