[macruby-changes] [2179] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Mon Aug 3 10:45:56 PDT 2009
Revision: 2179
http://trac.macosforge.org/projects/ruby/changeset/2179
Author: pthomson at apple.com
Date: 2009-08-03 10:45:55 -0700 (Mon, 03 Aug 2009)
Log Message:
-----------
Added inference of boolean types and made some classes static.
Modified Paths:
--------------
MacRuby/branches/experimental/ext/libyaml/rubyext.c
MacRuby/branches/experimental/lib/yaml/rubytypes.rb
Modified: MacRuby/branches/experimental/ext/libyaml/rubyext.c
===================================================================
--- MacRuby/branches/experimental/ext/libyaml/rubyext.c 2009-08-03 17:45:54 UTC (rev 2178)
+++ MacRuby/branches/experimental/ext/libyaml/rubyext.c 2009-08-03 17:45:55 UTC (rev 2179)
@@ -24,22 +24,22 @@
// struct that I can access through Data_Get_Struct();
// Nodes: Cache the tag as a Ruby string
-VALUE rb_mYAML;
-VALUE rb_mLibYAML;
-VALUE rb_cParser;
-VALUE rb_cEmitter;
-VALUE rb_cDocument;
-VALUE rb_cResolver;
-VALUE rb_cNode;
-VALUE rb_cSeqNode;
-VALUE rb_cMapNode;
-VALUE rb_cScalar;
-VALUE rb_cOut;
+static VALUE rb_mYAML;
+static VALUE rb_mLibYAML;
+static VALUE rb_cParser;
+static VALUE rb_cEmitter;
+static VALUE rb_cDocument;
+static VALUE rb_cResolver;
+static VALUE rb_cNode;
+static VALUE rb_cSeqNode;
+static VALUE rb_cMapNode;
+static VALUE rb_cScalar;
+static VALUE rb_cOut;
static ID id_plain;
static ID id_quote2;
-VALUE rb_oDefaultResolver;
+static VALUE rb_oDefaultResolver;
static VALUE
rb_yaml_parser_alloc(VALUE klass, SEL sel)
@@ -296,6 +296,16 @@
}
#endif
+static void
+rb_yaml_guess_type_of_plain_node(yaml_node_t *node)
+{
+ const unsigned char* v = node->data.scalar.value;
+ if ((strcmp(v, "true") == 0) || (strcmp(v, "false") == 0))
+ {
+ node->tag = "tag:yaml.org,2002:bool";
+ }
+}
+
static VALUE
rb_yaml_resolver_initialize(VALUE self, SEL sel)
{
@@ -310,6 +320,10 @@
{
case YAML_SCALAR_NODE:
{
+ if (node->data.scalar.style == YAML_PLAIN_SCALAR_STYLE)
+ {
+ rb_yaml_guess_type_of_plain_node(node);
+ }
VALUE tag = rb_str_new2((const char*)node->tag);
VALUE scalarval = rb_str_new((const char*)node->data.scalar.value, node->data.scalar.length);
VALUE handler = rb_hash_lookup(tags, tag);
Modified: MacRuby/branches/experimental/lib/yaml/rubytypes.rb
===================================================================
--- MacRuby/branches/experimental/lib/yaml/rubytypes.rb 2009-08-03 17:45:54 UTC (rev 2178)
+++ MacRuby/branches/experimental/lib/yaml/rubytypes.rb 2009-08-03 17:45:55 UTC (rev 2179)
@@ -140,6 +140,11 @@
end
end
+YAML::LibYAML::DEFAULT_RESOLVER.tags["tag:yaml.org,2002:bool"] = lambda {
+ |value|
+ value == "true"
+}
+
=begin
class Class
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090803/d4722d48/attachment.html>
More information about the macruby-changes
mailing list