[macruby-changes] [2244] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Aug 6 12:28:55 PDT 2009
Revision: 2244
http://trac.macosforge.org/projects/ruby/changeset/2244
Author: pthomson at apple.com
Date: 2009-08-06 12:28:53 -0700 (Thu, 06 Aug 2009)
Log Message:
-----------
Added YAML::load_documents, YAML::load_all, and enabled some more specs.
Modified Paths:
--------------
MacRuby/trunk/ext/libyaml/rubyext.c
MacRuby/trunk/lib/yaml.rb
MacRuby/trunk/spec/macruby.mspec
Modified: MacRuby/trunk/ext/libyaml/rubyext.c
===================================================================
--- MacRuby/trunk/ext/libyaml/rubyext.c 2009-08-06 18:10:30 UTC (rev 2243)
+++ MacRuby/trunk/ext/libyaml/rubyext.c 2009-08-06 19:28:53 UTC (rev 2244)
@@ -338,14 +338,17 @@
rb_yaml_parser_load(VALUE self, SEL sel)
{
rb_yaml_parser_t *parser = RYAMLParser(self);
- VALUE root;
+ VALUE root = Qnil;
+
NEXT_EVENT();
- if (parser->event.type != YAML_STREAM_START_EVENT)
+ if (parser->event.type == YAML_STREAM_END_EVENT)
{
- rb_raise(rb_eRuntimeError, "expected STREAM_START event");
+ return Qnil;
}
-
- NEXT_EVENT();
+ if (parser->event.type == YAML_STREAM_START_EVENT)
+ {
+ NEXT_EVENT();
+ }
if (parser->event.type != YAML_DOCUMENT_START_EVENT)
{
rb_raise(rb_eRuntimeError, "expected DOCUMENT_START event");
@@ -360,11 +363,6 @@
rb_raise(rb_eRuntimeError, "expected DOCUMENT_END event");
}
- NEXT_EVENT();
- if (parser->event.type != YAML_STREAM_END_EVENT)
- {
- rb_raise(rb_eRuntimeError, "expected STREAM_END event");
- }
return root;
}
Modified: MacRuby/trunk/lib/yaml.rb
===================================================================
--- MacRuby/trunk/lib/yaml.rb 2009-08-06 18:10:30 UTC (rev 2243)
+++ MacRuby/trunk/lib/yaml.rb 2009-08-06 19:28:53 UTC (rev 2244)
@@ -23,6 +23,14 @@
obj.to_yaml(io)
end
+ def YAML.dump_stream(*objs)
+ LibYAML::Emitter.new.stream do |stream|
+ objs.each do |obj|
+ stream.document { |doc| obj.to_yaml(doc) }
+ end
+ end
+ end
+
def YAML.load(io)
parsr = LibYAML::Parser.new(io)
parsr.load
@@ -32,6 +40,19 @@
File.open(path) { |f| load(f) }
end
+ def YAML.load_documents(io)
+ yparser = LibYAML::Parser.new(io)
+ until (element = yparser.load).nil?
+ yield(element)
+ end
+ end
+
+ def YAML.load_all(io)
+ elements = []
+ YAML.load_documents(io) { |e| elements << e}
+ elements
+ end
+
def YAML.parse(io)
LibYAML::Parser.new(io).load
end
@@ -49,11 +70,13 @@
end
end
end
+
end
module Kernel
def y(*objs)
objs.each { |obj| YAML::dump(obj, $stdout) }
+ nil
end
end
Modified: MacRuby/trunk/spec/macruby.mspec
===================================================================
--- MacRuby/trunk/spec/macruby.mspec 2009-08-06 18:10:30 UTC (rev 2243)
+++ MacRuby/trunk/spec/macruby.mspec 2009-08-06 19:28:53 UTC (rev 2244)
@@ -34,8 +34,10 @@
'library/stringscanner',
'library/time',
'library/tmpdir',
- 'library/yaml/load_spec.rb',
- 'library/yaml/dump_spec.rb'
+ 'library/yaml/dump_spec.rb',
+ 'library/yaml/load_documents_spec.rb',
+ 'library/yaml/load_file.spec',
+ 'library/yaml/load_spec.rb'
]
# Prepend the paths with the proper prefix
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090806/cfbee8d7/attachment-0001.html>
More information about the macruby-changes
mailing list