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

* lib/token.c: single- and double-quoted root-level fix.

* lib/yaml.rb (YAML::object_maker): can create object attributes (such as
  found in Exception class)

* lib/yaml/rubytypes.rb: roundtripping of Exception and subclasses.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
why 2003-05-22 17:56:30 +00:00
parent 3458bf4328
commit 9bb4160189
4 changed files with 100 additions and 51 deletions

View file

@ -1,3 +1,12 @@
Thu May 22 18:07:46 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
* lib/token.c: single- and double-quoted root-level fix.
* lib/yaml.rb (YAML::object_maker): can create object attributes (such as
found in Exception class)
* lib/yaml/rubytypes.rb: roundtripping of Exception and subclasses.
Fri May 23 01:26:26 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (rb_obj_clone): defer copying freezing state after

View file

@ -1,4 +1,4 @@
/* Generated by re2c 0.5 on Wed May 21 13:04:00 2003 */
/* Generated by re2c 0.5 on Thu May 22 07:19:06 2003 */
#line 1 "token.re"
/*
* token.re
@ -388,7 +388,7 @@ yy31: yych = *++YYCURSOR;
default: goto yy32;
}
yy32:
#line 336
#line 338
{ ENSURE_IOPEN(lvl, 0, 1);
goto Plain;
}
@ -564,11 +564,13 @@ yy37:
yy38: yych = *++YYCURSOR;
yy39:
#line 315
{ goto SingleQuote; }
{ ENSURE_IOPEN(lvl, 0, 1);
goto SingleQuote; }
yy40: yych = *++YYCURSOR;
yy41:
#line 317
{ goto DoubleQuote; }
#line 318
{ ENSURE_IOPEN(lvl, 0, 1);
goto DoubleQuote; }
yy42: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR);
switch(yych){
@ -588,18 +590,18 @@ yy42: yyaccept = 0;
}
yy43: yych = *++YYCURSOR;
yy44:
#line 326
#line 328
{ eat_comments( parser );
goto Document;
}
yy45: yych = *++YYCURSOR;
goto yy51;
yy46:
#line 330
#line 332
{ goto Document; }
yy47: yych = *++YYCURSOR;
yy48:
#line 332
#line 334
{ ENSURE_IEND(lvl, -1);
return 0;
}
@ -642,7 +644,7 @@ yy56: switch(yych){
default: goto yy57;
}
yy57:
#line 319
#line 321
{ if ( *( YYCURSOR - 1 ) == '\n' )
{
YYCURSOR--;
@ -888,7 +890,7 @@ yy79: switch(yych){
default: goto yy26;
}
}
#line 340
#line 342
}
@ -995,14 +997,14 @@ yy83: yyaccept = 0;
default: goto yy84;
}
yy84:
#line 353
#line 355
{ YYCURSOR = YYTOKTMP;
return DOCSEP;
}
yy85: yych = *++YYCURSOR;
goto yy89;
yy86:
#line 351
#line 353
{ goto Directive; }
yy87: yych = *++YYCURSOR;
goto yy84;
@ -1254,10 +1256,10 @@ yy94: switch(yych){
default: goto yy95;
}
yy95:
#line 349
#line 351
{ goto Directive; }
}
#line 356
#line 358
}
@ -1296,7 +1298,7 @@ yy96:
yy98: yych = *++YYCURSOR;
goto yy122;
yy99:
#line 376
#line 378
{ int indt_len;
SyckLevel *lvl;
char *tok = YYTOKTMP;
@ -1318,11 +1320,11 @@ yy100: yych = *++YYCURSOR;
default: goto yy101;
}
yy101:
#line 405
#line 407
{ goto Plain2; }
yy102: yych = *++YYCURSOR;
yy103:
#line 393
#line 395
{ if ( plvl->status != syck_lvl_inline ) goto Plain2;
RETURN_IMPLICIT(multiLine);
}
@ -1334,7 +1336,7 @@ yy104: yych = *++YYCURSOR;
}
yy105: yych = *++YYCURSOR;
yy106:
#line 397
#line 399
{ RETURN_IMPLICIT(multiLine); }
yy107: yych = *++YYCURSOR;
switch(yych){
@ -1342,13 +1344,13 @@ yy107: yych = *++YYCURSOR;
default: goto yy108;
}
yy108:
#line 403
#line 405
{ goto Plain3; }
yy109: yych = *++YYCURSOR;
goto yy101;
yy110: yych = *++YYCURSOR;
yy111:
#line 399
#line 401
{ eat_comments( parser );
RETURN_IMPLICIT(multiLine);
}
@ -1374,7 +1376,7 @@ yy117: switch(yych){
default: goto yy118;
}
yy118:
#line 391
#line 393
{ RETURN_IMPLICIT(multiLine); }
yy119: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
@ -1399,7 +1401,7 @@ yy124: switch(yych){
default: goto yy99;
}
}
#line 407
#line 409
}
@ -1429,7 +1431,7 @@ yy125:
yy127: yych = *++YYCURSOR;
goto yy137;
yy128:
#line 421
#line 423
{ int indt_len;
int nl_count = 0;
SyckLevel *lvl;
@ -1471,7 +1473,7 @@ yy129: yych = *++YYCURSOR;
default: goto yy130;
}
yy130:
#line 461
#line 463
{ SyckLevel *lvl;
SyckNode *n = syck_alloc_str();
lvl = CURRENT_LEVEL();
@ -1489,13 +1491,13 @@ yy131: yych = *++YYCURSOR;
goto yy130;
yy132: yych = *++YYCURSOR;
yy133:
#line 475
#line 477
{ QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
goto SingleQuote2;
}
yy134: yych = *++YYCURSOR;
yy135:
#line 457
#line 459
{ QUOTECAT(qstr, qcapa, qidx, '\'');
goto SingleQuote2;
}
@ -1515,7 +1517,7 @@ yy139: switch(yych){
default: goto yy128;
}
}
#line 479
#line 481
}
@ -1550,7 +1552,7 @@ yy140:
yy142: yych = *++YYCURSOR;
goto yy158;
yy143:
#line 497
#line 499
{ int indt_len;
int nl_count = 0;
SyckLevel *lvl;
@ -1601,13 +1603,13 @@ yy144: yyaccept = 0;
default: goto yy145;
}
yy145:
#line 572
#line 574
{ QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
goto DoubleQuote2;
}
yy146: yych = *++YYCURSOR;
yy147:
#line 558
#line 560
{ SyckLevel *lvl;
SyckNode *n = syck_alloc_str();
lvl = CURRENT_LEVEL();
@ -1639,14 +1641,14 @@ yy152: YYCURSOR = YYMARKER;
}
yy153: yych = *++YYCURSOR;
yy154:
#line 553
#line 555
{ keep_nl = 0;
YYCURSOR--;
goto DoubleQuote2;
}
yy155: yych = *++YYCURSOR;
yy156:
#line 537
#line 539
{ char ch = *( YYCURSOR - 1 );
switch ( ch )
{
@ -1678,7 +1680,7 @@ yy160: switch(yych){
default: goto yy143;
}
}
#line 576
#line 578
}
@ -1703,7 +1705,7 @@ yy161:
yy163:yy164: yych = *++YYCURSOR;
goto yy172;
yy165:
#line 585
#line 587
{ SyckLevel *lvl;
YYCURSOR = YYTOKTMP;
if ( YYCURSOR == YYTOKEN + 1 )
@ -1753,7 +1755,7 @@ yy166: yych = *++YYCURSOR;
goto yy170;
yy167: yych = *++YYCURSOR;
yy168:
#line 631
#line 633
{ goto TransferMethod; }
yy169: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
@ -1770,7 +1772,7 @@ yy172: switch(yych){
default: goto yy165;
}
}
#line 633
#line 635
}
@ -1828,7 +1830,7 @@ yy173:
yy175: yych = *++YYCURSOR;
goto yy184;
yy176:
#line 675
#line 677
{ int indt_len;
GOBBLE_UP_INDENT( indt_len, YYTOKTMP );
lvl = CURRENT_LEVEL();
@ -1861,7 +1863,7 @@ yy176:
}
yy177: yych = *++YYCURSOR;
yy178:
#line 707
#line 709
{ lvl = CURRENT_LEVEL();
YYCURSOR--;
yylval->nodeData = syck_new_str2( YYTOKEN, YYCURSOR - YYTOKEN );
@ -1871,7 +1873,7 @@ yy178:
}
yy179: yych = *++YYCURSOR;
yy180:
#line 715
#line 717
{ lvl = CURRENT_LEVEL();
if ( lvl->status != syck_lvl_block )
{
@ -1882,7 +1884,7 @@ yy180:
}
yy181: yych = *++YYCURSOR;
yy182:
#line 724
#line 726
{ goto ScalarBlock2; }
yy183: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
@ -1900,7 +1902,7 @@ yy186: switch(yych){
default: goto yy176;
}
}
#line 726
#line 728
}
@ -1930,7 +1932,7 @@ yy187:
}
yy189: yych = *++YYCURSOR;
yy190:
#line 742
#line 744
{ SyckLevel *lvl = CURRENT_LEVEL();
YYCURSOR = tok;
return;
@ -1939,7 +1941,7 @@ yy191: yych = *++YYCURSOR;
goto yy195;
yy192: yych = *++YYCURSOR;
yy193:
#line 747
#line 749
{ goto Comment;
}
yy194: ++YYCURSOR;
@ -1950,7 +1952,7 @@ yy195: switch(yych){
default: goto yy190;
}
}
#line 750
#line 752
}

View file

@ -124,13 +124,20 @@ module YAML
#
# Allocate blank object
#
def YAML.object_maker( obj_class, val )
def YAML.object_maker( obj_class, val, is_attr = false )
if Hash === val
name = obj_class.name
o = ::Marshal.load( sprintf( "\004\006o:%c%s\000", name.length + 5, name ))
val.each_pair { |k,v|
o.instance_eval "@#{k} = v"
}
ostr = sprintf( "\004\006o:%c%s\000", name.length + 5, name )
if is_attr
ostr[ -1, 1 ] = Marshal.dump( val ).sub( /^[^{]+\{/, '' )
p ostr
end
o = ::Marshal.load( ostr )
unless is_attr
val.each_pair { |k,v|
o.instance_eval "@#{k} = v"
}
end
o
else
raise YAML::Error, "Invalid object explicitly tagged !ruby/Object: " + val.inspect

View file

@ -1,5 +1,4 @@
require 'date'
require 'yaml/constants'
#
# Type conversions
#
@ -241,6 +240,38 @@ array_proc = Proc.new { |type, val|
YAML.add_builtin_type( 'seq', &array_proc )
YAML.add_ruby_type( 'array', &array_proc )
#
# Exception#to_yaml
#
class Exception
def is_complex_yaml?
true
end
def to_yaml_type
"!ruby/exception:#{self.class}"
end
def to_yaml( opts = {} )
YAML::quick_emit( self.object_id, opts ) { |out|
out.map( self.to_yaml_type ) { |map|
map.add( 'message', self.message )
to_yaml_properties.each { |m|
map.add( m[1..-1], instance_eval( m ) )
}
}
}
end
end
YAML.add_ruby_type( 'exception' ) { |type, val|
type, obj_class = YAML.read_type_class( type, Exception )
o = YAML.object_maker( obj_class, { 'mesg' => val.delete( 'message' ) }, true )
val.each_pair { |k,v|
o.instance_eval "@#{k} = v"
}
o
}
#
# String#to_yaml
#
@ -274,7 +305,7 @@ class String
"''"
elsif YAML.detect_implicit( self ) != 'str'
"\"#{YAML.escape( self )}\""
elsif self =~ /#{YAML::ESCAPE_CHAR}|[#{YAML::SPACE_INDICATORS}]( |\n|$)|\'/
elsif self =~ /#{YAML::ESCAPE_CHAR}|[#{YAML::SPACE_INDICATORS}] |\n|\'/
"\"#{YAML.escape( self )}\""
elsif self =~ /^[^#{YAML::WORD_CHAR}]/
"\"#{YAML.escape( self )}\""