[macruby-changes] [2243] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Aug 6 11:10:32 PDT 2009
Revision: 2243
http://trac.macosforge.org/projects/ruby/changeset/2243
Author: pthomson at apple.com
Date: 2009-08-06 11:10:30 -0700 (Thu, 06 Aug 2009)
Log Message:
-----------
Fixed a problem where tags for sequences and maps weren't being emitted and added support for dumping/loading Rational and Complex.
Modified Paths:
--------------
MacRuby/trunk/ext/libyaml/rubyext.c
MacRuby/trunk/lib/yaml/rubytypes.rb
Modified: MacRuby/trunk/ext/libyaml/rubyext.c
===================================================================
--- MacRuby/trunk/ext/libyaml/rubyext.c 2009-08-06 17:59:51 UTC (rev 2242)
+++ MacRuby/trunk/ext/libyaml/rubyext.c 2009-08-06 18:10:30 UTC (rev 2243)
@@ -414,7 +414,9 @@
(strcmp(tag, "tag:ruby.yaml.org,2002:symbol") == 0) ||
(strcmp(tag, "tag:yaml.org,2002:bool") == 0) ||
(strcmp(tag, "tag:yaml.org,2002:null") == 0) ||
- (strcmp(tag, "tag:yaml.org,2002:str") == 0))
+ (strcmp(tag, "tag:yaml.org,2002:str") == 0) ||
+ (strcmp(tag, YAML_DEFAULT_SEQUENCE_TAG) == 0) ||
+ (strcmp(tag, YAML_DEFAULT_MAPPING_TAG) == 0))
{
*can_omit_tag = 1;
return NULL;
@@ -532,8 +534,9 @@
{
yaml_event_t ev;
yaml_emitter_t *emitter = &RYAMLEmitter(self)->emitter;
- yaml_char_t *tag = (yaml_char_t*)RSTRING_PTR(taguri);
- yaml_sequence_start_event_initialize(&ev, NULL, tag, 1, YAML_ANY_SEQUENCE_STYLE);
+ int can_omit_tag = 0;
+ yaml_char_t *tag = rb_yaml_tag_or_null(taguri, &can_omit_tag);
+ yaml_sequence_start_event_initialize(&ev, NULL, tag, can_omit_tag, YAML_ANY_SEQUENCE_STYLE);
yaml_emitter_emit(emitter, &ev);
rb_yield(self);
@@ -548,8 +551,9 @@
{
yaml_event_t ev;
yaml_emitter_t *emitter = &RYAMLEmitter(self)->emitter;
- yaml_char_t *tag = (yaml_char_t*)RSTRING_PTR(taguri);
- yaml_mapping_start_event_initialize(&ev, NULL, tag, 1, YAML_ANY_MAPPING_STYLE);
+ int can_omit_tag = 0;
+ yaml_char_t *tag = rb_yaml_tag_or_null(taguri, &can_omit_tag);
+ yaml_mapping_start_event_initialize(&ev, NULL, tag, can_omit_tag, YAML_ANY_MAPPING_STYLE);
yaml_emitter_emit(emitter, &ev);
rb_yield(self);
Modified: MacRuby/trunk/lib/yaml/rubytypes.rb
===================================================================
--- MacRuby/trunk/lib/yaml/rubytypes.rb 2009-08-06 17:59:51 UTC (rev 2242)
+++ MacRuby/trunk/lib/yaml/rubytypes.rb 2009-08-06 18:10:30 UTC (rev 2243)
@@ -160,6 +160,46 @@
end
end
+class Rational
+ yaml_as "tag:ruby.yaml.org,2002:object:Rational"
+
+ def Rational.yaml_new(attrs)
+ if attrs.is_a? String
+ Rational(attrs)
+ else
+ Rational(attrs['numerator'], attrs['denominator'])
+ end
+ end
+
+ def to_yaml(output = nil)
+ YAML::quick_emit(output) do |out|
+ out.map(taguri, to_yaml_style) do |map|
+ map.add('denominator', denominator)
+ map.add('numerator', numerator)
+ end
+ end
+ end
+end
+
+class Complex
+ yaml_as "tag:ruby.yaml.org,2002:object:Complex"
+ def Complex.yaml_new(val)
+ if val.is_a? String
+ Complex(val)
+ else
+ Complex(val['real'], val['image'])
+ end
+ end
+ def to_yaml(output = nil)
+ YAML::quick_emit(output) do |out|
+ out.map(taguri, nil ) do |map|
+ map.add('image', imaginary)
+ map.add('real', real)
+ end
+ end
+ end
+end
+
class NilClass
yaml_as "tag:yaml.org,2002:null"
@@ -199,27 +239,6 @@
=begin
-class Class
- def to_yaml( opts = {} )
- raise TypeError, "can't dump anonymous class %s" % self.class
- end
-end
-
-class Object
- yaml_as "tag:ruby.yaml.org,2002:object"
- def to_yaml_style; end
- def to_yaml_properties; instance_variables.sort; end
- def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
- out.map( taguri, to_yaml_style ) do |map|
- to_yaml_properties.each do |m|
- map.add( m[1..-1], instance_variable_get( m ) )
- end
- end
- end
- end
-end
-
class Hash
yaml_as "tag:ruby.yaml.org,2002:hash"
yaml_as "tag:yaml.org,2002:map"
@@ -536,43 +555,5 @@
end
end
-class Rational
- yaml_as "tag:ruby.yaml.org,2002:object:Rational"
- def Rational.yaml_new( klass, tag, val )
- if val.is_a? String
- Rational( val )
- else
- Rational( val['numerator'], val['denominator'] )
- end
- end
- def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
- out.map( taguri, nil ) do |map|
- map.add( 'denominator', denominator )
- map.add( 'numerator', numerator )
- end
- end
- end
-end
-class Complex
- yaml_as "tag:ruby.yaml.org,2002:object:Complex"
- def Complex.yaml_new( klass, tag, val )
- if val.is_a? String
- Complex( val )
- else
- Complex( val['real'], val['image'] )
- end
- end
- def to_yaml( opts = {} )
- YAML::quick_emit( self, opts ) do |out|
- out.map( taguri, nil ) do |map|
- map.add( 'image', imaginary )
- map.add( 'real', real )
- end
- end
- end
-end
-
-
=end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090806/09e616ed/attachment.html>
More information about the macruby-changes
mailing list