2005-04-30 08:50:34 -04:00
|
|
|
/* -*- indent-tabs-mode: nil -*- */
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* rubyext.c
|
|
|
|
*
|
|
|
|
* $Author$
|
|
|
|
*
|
2005-09-12 23:58:33 -04:00
|
|
|
* Copyright (C) 2003-2005 why the lucky stiff
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2007-06-09 23:06:15 -04:00
|
|
|
#include "ruby/ruby.h"
|
2008-06-16 17:25:17 -04:00
|
|
|
#include "ruby/encoding.h"
|
2003-05-09 17:25:50 -04:00
|
|
|
#include "syck.h"
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2003-06-17 12:55:54 -04:00
|
|
|
typedef struct RVALUE {
|
|
|
|
union {
|
2004-05-14 23:11:28 -04:00
|
|
|
#if 0
|
2005-09-12 23:58:33 -04:00
|
|
|
struct {
|
|
|
|
unsigned long flags; /* always 0 for freed obj */
|
|
|
|
struct RVALUE *next;
|
|
|
|
} free;
|
2004-05-14 23:11:28 -04:00
|
|
|
#endif
|
2005-09-12 23:58:33 -04:00
|
|
|
struct RBasic basic;
|
|
|
|
struct RObject object;
|
|
|
|
struct RClass klass;
|
|
|
|
/*struct RFloat flonum;*/
|
|
|
|
/*struct RString string;*/
|
|
|
|
struct RArray array;
|
|
|
|
/*struct RRegexp regexp;*/
|
|
|
|
struct RHash hash;
|
|
|
|
/*struct RData data;*/
|
|
|
|
struct RStruct rstruct;
|
|
|
|
/*struct RBignum bignum;*/
|
|
|
|
/*struct RFile file;*/
|
2003-06-17 12:55:54 -04:00
|
|
|
} as;
|
|
|
|
} RVALUE;
|
|
|
|
|
2003-10-17 16:53:39 -04:00
|
|
|
typedef struct {
|
|
|
|
long hash;
|
|
|
|
char *buffer;
|
|
|
|
long length;
|
|
|
|
long remaining;
|
|
|
|
int printed;
|
|
|
|
} bytestring_t;
|
|
|
|
|
2003-05-10 15:55:18 -04:00
|
|
|
#define RUBY_DOMAIN "ruby.yaml.org,2002"
|
|
|
|
|
2003-07-28 15:27:42 -04:00
|
|
|
/*
|
|
|
|
* symbols and constants
|
|
|
|
*/
|
2006-02-03 05:28:27 -05:00
|
|
|
static ID s_new, s_utc, s_at, s_to_f, s_to_i, s_read, s_binmode, s_call, s_cmp, s_transfer, s_update, s_dup, s_haskey, s_match, s_keys, s_unpack, s_tr_bang, s_default_set, s_tag_read_class, s_tag_subclasses, s_resolver, s_push, s_emitter, s_level, s_detect_implicit, s_node_import, s_out, s_input, s_intern, s_transform, s_yaml_new, s_yaml_initialize, s_node_export, s_to_yaml, s_write, s_set_resolver, s_each;
|
2008-11-19 03:49:51 -05:00
|
|
|
static ID s_tags, s_kind, s_name, s_options, s_type_id, s_type_id_set, s_style, s_style_set, s_value, s_value_set, s_parse;
|
2003-10-14 19:15:19 -04:00
|
|
|
static VALUE sym_model, sym_generic, sym_input, sym_bytecode;
|
2003-05-09 17:25:50 -04:00
|
|
|
static VALUE sym_scalar, sym_seq, sym_map;
|
2005-09-12 23:58:33 -04:00
|
|
|
static VALUE sym_1quote, sym_2quote, sym_fold, sym_literal, sym_plain, sym_inline;
|
2008-11-19 03:49:51 -05:00
|
|
|
static VALUE cDate, cNode, cMap, cSeq, cScalar, cOut, cParser, cResolver, cPrivateType, cDomainType, cYObject, cBadAlias, cDefaultKey, cMergeKey, cEmitter, cDateTime;
|
2005-09-12 23:58:33 -04:00
|
|
|
static VALUE oDefaultResolver, oGenericResolver;
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* my private collection of numerical oddities.
|
|
|
|
*/
|
2007-03-18 23:58:57 -04:00
|
|
|
static double S_zero(void) { return 0.0; }
|
|
|
|
static double S_one(void) { return 1.0; }
|
|
|
|
static double S_inf(void) { return S_one() / S_zero(); }
|
|
|
|
static double S_nan(void) { return S_zero() / S_zero(); }
|
2003-05-09 17:25:50 -04:00
|
|
|
|
|
|
|
static VALUE syck_node_transform( VALUE );
|
|
|
|
|
2003-07-28 15:27:42 -04:00
|
|
|
/*
|
|
|
|
* handler prototypes
|
|
|
|
*/
|
2003-05-14 06:57:42 -04:00
|
|
|
SYMID rb_syck_load_handler _((SyckParser *, SyckNode *));
|
2008-07-22 14:02:12 -04:00
|
|
|
void rb_syck_err_handler _((SyckParser *, const char *));
|
2003-06-17 12:55:54 -04:00
|
|
|
SyckNode * rb_syck_bad_anchor_handler _((SyckParser *, char *));
|
2003-07-11 18:52:14 -04:00
|
|
|
void rb_syck_output_handler _((SyckEmitter *, char *, long));
|
2005-09-12 23:58:33 -04:00
|
|
|
void rb_syck_emitter_handler _((SyckEmitter *, st_data_t));
|
2005-12-19 09:13:27 -05:00
|
|
|
int syck_parser_assign_io _((SyckParser *, VALUE *));
|
2005-09-27 18:57:53 -04:00
|
|
|
VALUE syck_scalar_alloc _((VALUE class));
|
|
|
|
VALUE syck_seq_alloc _((VALUE class));
|
|
|
|
VALUE syck_map_alloc _((VALUE class));
|
2003-05-14 06:57:42 -04:00
|
|
|
|
2003-06-05 01:40:03 -04:00
|
|
|
struct parser_xtra {
|
2003-07-04 08:51:42 -04:00
|
|
|
VALUE data; /* Borrowed this idea from marshal.c to fix [ruby-core:8067] problem */
|
2003-06-05 01:40:03 -04:00
|
|
|
VALUE proc;
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE resolver;
|
2003-08-19 12:38:02 -04:00
|
|
|
int taint;
|
2003-06-05 01:40:03 -04:00
|
|
|
};
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
struct emitter_xtra {
|
|
|
|
VALUE oid;
|
|
|
|
VALUE data;
|
|
|
|
VALUE port;
|
|
|
|
};
|
|
|
|
|
2003-10-17 16:53:39 -04:00
|
|
|
/*
|
|
|
|
* Convert YAML to bytecode
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
rb_syck_compile(VALUE self, VALUE port)
|
2003-10-17 16:53:39 -04:00
|
|
|
{
|
|
|
|
SYMID oid;
|
|
|
|
int taint;
|
|
|
|
char *ret;
|
|
|
|
VALUE bc;
|
2008-07-22 17:12:00 -04:00
|
|
|
bytestring_t *sav = NULL;
|
2008-07-30 13:22:16 -04:00
|
|
|
void *data = NULL;
|
2003-10-17 16:53:39 -04:00
|
|
|
|
|
|
|
SyckParser *parser = syck_new_parser();
|
2005-12-19 09:13:27 -05:00
|
|
|
taint = syck_parser_assign_io(parser, &port);
|
2003-10-17 16:53:39 -04:00
|
|
|
syck_parser_handler( parser, syck_yaml2byte_handler );
|
|
|
|
syck_parser_error_handler( parser, NULL );
|
|
|
|
syck_parser_implicit_typing( parser, 0 );
|
|
|
|
syck_parser_taguri_expansion( parser, 0 );
|
|
|
|
oid = syck_parse( parser );
|
2008-07-30 22:30:46 -04:00
|
|
|
if (!syck_lookup_sym( parser, oid, &data )) {
|
2010-11-11 07:30:39 -05:00
|
|
|
rb_raise(rb_eSyntaxError, "root node <%p> not found", (void *)oid);
|
2008-07-30 22:30:46 -04:00
|
|
|
}
|
2008-07-30 13:22:16 -04:00
|
|
|
sav = data;
|
2003-10-17 16:53:39 -04:00
|
|
|
|
2006-01-09 23:54:10 -05:00
|
|
|
ret = S_ALLOCA_N( char, strlen( sav->buffer ) + 3 );
|
2003-10-17 16:53:39 -04:00
|
|
|
ret[0] = '\0';
|
|
|
|
strcat( ret, "D\n" );
|
|
|
|
strcat( ret, sav->buffer );
|
|
|
|
|
|
|
|
syck_free_parser( parser );
|
|
|
|
|
2006-01-09 23:54:10 -05:00
|
|
|
bc = rb_str_new2( ret );
|
2003-10-17 16:53:39 -04:00
|
|
|
if ( taint ) OBJ_TAINT( bc );
|
|
|
|
return bc;
|
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* read from io.
|
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
long
|
|
|
|
rb_syck_io_str_read( char *buf, SyckIoStr *str, long max_size, long skip )
|
|
|
|
{
|
|
|
|
long len = 0;
|
|
|
|
|
|
|
|
ASSERT( str != NULL );
|
|
|
|
max_size -= skip;
|
|
|
|
|
2003-11-25 14:51:38 -05:00
|
|
|
if ( max_size <= 0 ) max_size = 0;
|
|
|
|
else
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-07-04 08:51:42 -04:00
|
|
|
/*
|
|
|
|
* call io#read.
|
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
VALUE src = (VALUE)str->ptr;
|
|
|
|
VALUE n = LONG2NUM(max_size);
|
2003-11-25 14:51:38 -05:00
|
|
|
VALUE str2 = rb_funcall2(src, s_read, 1, &n);
|
|
|
|
if (!NIL_P(str2))
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2004-12-15 11:01:11 -05:00
|
|
|
StringValue(str2);
|
2006-08-31 06:30:33 -04:00
|
|
|
len = RSTRING_LEN(str2);
|
|
|
|
memcpy( buf + skip, RSTRING_PTR(str2), len );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
len += skip;
|
|
|
|
buf[len] = '\0';
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* determine: are we reading from a string or io?
|
2003-08-19 12:38:02 -04:00
|
|
|
* (returns tainted? boolean)
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2003-08-19 12:38:02 -04:00
|
|
|
int
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_parser_assign_io(SyckParser *parser, VALUE *pport)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-08-19 12:38:02 -04:00
|
|
|
int taint = Qtrue;
|
2005-12-19 09:13:27 -05:00
|
|
|
VALUE tmp, port = *pport;
|
2004-12-23 12:23:02 -05:00
|
|
|
if (!NIL_P(tmp = rb_check_string_type(port))) {
|
|
|
|
taint = OBJ_TAINTED(port); /* original taintedness */
|
|
|
|
port = tmp;
|
2006-08-31 06:30:33 -04:00
|
|
|
syck_parser_str( parser, RSTRING_PTR(port), RSTRING_LEN(port), NULL );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
else if (rb_respond_to(port, s_read)) {
|
|
|
|
if (rb_respond_to(port, s_binmode)) {
|
|
|
|
rb_funcall2(port, s_binmode, 0, 0);
|
|
|
|
}
|
2003-07-04 08:51:42 -04:00
|
|
|
syck_parser_str( parser, (char *)port, 0, rb_syck_io_str_read );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_raise(rb_eTypeError, "instance of IO needed");
|
|
|
|
}
|
2005-12-19 09:13:27 -05:00
|
|
|
*pport = port;
|
2003-08-19 12:38:02 -04:00
|
|
|
return taint;
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* Get value in hash by key, forcing an empty hash if nil.
|
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_get_hash_aref(VALUE hsh, VALUE key)
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
|
|
|
VALUE val = rb_hash_aref( hsh, key );
|
2010-04-22 04:04:13 -04:00
|
|
|
if ( NIL_P( val ) )
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
|
|
|
val = rb_hash_new();
|
|
|
|
rb_hash_aset(hsh, key, val);
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* creating timestamps
|
|
|
|
*/
|
2008-11-19 03:49:51 -05:00
|
|
|
struct mktime_arg {
|
2010-10-12 11:21:20 -04:00
|
|
|
const char *str;
|
2008-11-19 03:49:51 -05:00
|
|
|
long len;
|
|
|
|
};
|
|
|
|
|
2010-10-12 11:21:20 -04:00
|
|
|
VALUE
|
|
|
|
mktime_do(VALUE varg)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2010-10-12 11:21:20 -04:00
|
|
|
struct mktime_arg *arg = (struct mktime_arg *)varg;
|
2003-05-09 17:25:50 -04:00
|
|
|
VALUE time;
|
2010-10-12 11:21:20 -04:00
|
|
|
const char *str = arg->str;
|
2008-11-19 03:49:51 -05:00
|
|
|
long len = arg->len;
|
2010-10-12 11:21:20 -04:00
|
|
|
const char *ptr = str;
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE year = INT2FIX(0);
|
|
|
|
VALUE mon = INT2FIX(0);
|
|
|
|
VALUE day = INT2FIX(0);
|
|
|
|
VALUE hour = INT2FIX(0);
|
|
|
|
VALUE min = INT2FIX(0);
|
|
|
|
VALUE sec = INT2FIX(0);
|
2011-05-06 09:36:02 -04:00
|
|
|
long usec;
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Year*/
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( ptr[0] != '\0' && len > 0 ) {
|
|
|
|
year = INT2FIX(strtol(ptr, NULL, 10));
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Month*/
|
2003-05-09 17:25:50 -04:00
|
|
|
ptr += 4;
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( ptr[0] != '\0' && len > ptr - str ) {
|
|
|
|
while ( !ISDIGIT( *ptr ) ) ptr++;
|
|
|
|
mon = INT2FIX(strtol(ptr, NULL, 10));
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Day*/
|
2003-05-09 17:25:50 -04:00
|
|
|
ptr += 2;
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( ptr[0] != '\0' && len > ptr - str ) {
|
|
|
|
while ( !ISDIGIT( *ptr ) ) ptr++;
|
|
|
|
day = INT2FIX(strtol(ptr, NULL, 10));
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Hour*/
|
2003-05-09 17:25:50 -04:00
|
|
|
ptr += 2;
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( ptr[0] != '\0' && len > ptr - str ) {
|
|
|
|
while ( !ISDIGIT( *ptr ) ) ptr++;
|
|
|
|
hour = INT2FIX(strtol(ptr, NULL, 10));
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Minute */
|
2003-05-09 17:25:50 -04:00
|
|
|
ptr += 2;
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( ptr[0] != '\0' && len > ptr - str ) {
|
|
|
|
while ( !ISDIGIT( *ptr ) ) ptr++;
|
|
|
|
min = INT2FIX(strtol(ptr, NULL, 10));
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Second */
|
2003-05-09 17:25:50 -04:00
|
|
|
ptr += 2;
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( ptr[0] != '\0' && len > ptr - str ) {
|
|
|
|
while ( !ISDIGIT( *ptr ) ) ptr++;
|
|
|
|
sec = INT2FIX(strtol(ptr, NULL, 10));
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Millisecond */
|
2003-05-15 03:38:10 -04:00
|
|
|
ptr += 2;
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( len > ptr - str && *ptr == '.' )
|
2003-05-30 19:09:54 -04:00
|
|
|
{
|
2011-05-06 09:36:02 -04:00
|
|
|
char padded[] = "000000";
|
|
|
|
const int padding = (int)(sizeof(padded) - 1);
|
2010-10-12 11:21:20 -04:00
|
|
|
const char *end = ptr + 1;
|
2011-05-06 02:19:12 -04:00
|
|
|
const char *begin = end;
|
2011-05-06 09:36:02 -04:00
|
|
|
ptrdiff_t length;
|
2004-01-28 11:59:00 -05:00
|
|
|
while ( isdigit( *end ) ) end++;
|
2011-05-06 09:36:02 -04:00
|
|
|
if ((length = (end - begin)) > padding) length = padding;
|
2011-05-06 02:19:12 -04:00
|
|
|
MEMCPY(padded, begin, char, length);
|
2011-05-06 09:36:02 -04:00
|
|
|
usec = strtol(padded, NULL, 10);
|
2003-05-30 19:09:54 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-06 09:36:02 -04:00
|
|
|
usec = 0;
|
2003-05-30 19:09:54 -04:00
|
|
|
}
|
2003-05-15 03:38:10 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Time Zone*/
|
2005-09-12 23:58:33 -04:00
|
|
|
while ( len > ptr - str && *ptr != 'Z' && *ptr != '+' && *ptr != '-' && *ptr != '\0' ) ptr++;
|
|
|
|
if ( len > ptr - str && ( *ptr == '-' || *ptr == '+' ) )
|
2003-05-15 03:38:10 -04:00
|
|
|
{
|
2004-12-23 12:23:02 -05:00
|
|
|
time_t tz_offset = strtol(ptr, NULL, 10) * 3600;
|
2009-04-21 10:56:59 -04:00
|
|
|
VALUE tmp;
|
2003-05-15 03:38:10 -04:00
|
|
|
|
|
|
|
while ( *ptr != ':' && *ptr != '\0' ) ptr++;
|
|
|
|
if ( *ptr == ':' )
|
|
|
|
{
|
|
|
|
ptr += 1;
|
|
|
|
if ( tz_offset < 0 )
|
|
|
|
{
|
2004-01-28 11:59:00 -05:00
|
|
|
tz_offset -= strtol(ptr, NULL, 10) * 60;
|
2003-05-15 03:38:10 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-28 11:59:00 -05:00
|
|
|
tz_offset += strtol(ptr, NULL, 10) * 60;
|
2003-05-15 03:38:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Make TZ time*/
|
2004-12-23 12:23:02 -05:00
|
|
|
time = rb_funcall(rb_cTime, s_utc, 6, year, mon, day, hour, min, sec);
|
2009-04-21 10:56:59 -04:00
|
|
|
tmp = rb_funcall(time, s_to_i, 0);
|
|
|
|
tmp = rb_funcall(tmp, '-', 1, LONG2FIX(tz_offset));
|
2011-05-06 09:36:02 -04:00
|
|
|
return rb_funcall(rb_cTime, s_at, 2, tmp, LONG2NUM(usec));
|
2004-12-23 12:23:02 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Make UTC time*/
|
2011-05-06 09:36:02 -04:00
|
|
|
return rb_funcall(rb_cTime, s_utc, 7, year, mon, day, hour, min, sec, LONG2NUM(usec));
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 11:21:20 -04:00
|
|
|
VALUE
|
|
|
|
mktime_r(VALUE varg)
|
2008-11-19 03:49:51 -05:00
|
|
|
{
|
2010-10-12 11:21:20 -04:00
|
|
|
struct mktime_arg *arg = (struct mktime_arg *)varg;
|
|
|
|
|
2008-11-19 03:49:51 -05:00
|
|
|
if (!cDateTime) {
|
|
|
|
/*
|
|
|
|
* Load Date module
|
|
|
|
*/
|
|
|
|
rb_require("date");
|
|
|
|
cDateTime = rb_const_get(rb_cObject, rb_intern("DateTime"));
|
|
|
|
}
|
|
|
|
return rb_funcall(cDateTime, s_parse, 1, rb_str_new(arg->str, arg->len));
|
|
|
|
}
|
|
|
|
|
2010-10-12 11:21:20 -04:00
|
|
|
VALUE
|
|
|
|
rb_syck_mktime(const char *str, long len)
|
2008-11-19 03:49:51 -05:00
|
|
|
{
|
|
|
|
struct mktime_arg a;
|
|
|
|
|
|
|
|
a.str = str;
|
|
|
|
a.len = len;
|
|
|
|
return rb_rescue2(mktime_do, (VALUE)&a, mktime_r, (VALUE)&a, rb_eArgError, NULL);
|
|
|
|
}
|
|
|
|
|
2003-06-17 21:06:00 -04:00
|
|
|
/*
|
|
|
|
* handles merging of an array of hashes
|
|
|
|
* (see http://www.yaml.org/type/merge/)
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_merge_i(VALUE entry, VALUE hsh )
|
2003-06-17 21:06:00 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE tmp;
|
|
|
|
if ( !NIL_P(tmp = rb_check_convert_type(entry, T_HASH, "Hash", "to_hash")) )
|
2004-12-23 12:23:02 -05:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
entry = tmp;
|
2004-12-23 12:23:02 -05:00
|
|
|
rb_funcall( hsh, s_update, 1, entry );
|
|
|
|
}
|
2003-06-17 21:06:00 -04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-08-21 17:16:58 -04:00
|
|
|
/*
|
|
|
|
* default handler for ruby.yaml.org types
|
|
|
|
*/
|
|
|
|
int
|
2006-06-20 14:02:17 -04:00
|
|
|
yaml_org_handler( SyckNode *n, VALUE *ref )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-08-21 17:16:58 -04:00
|
|
|
char *type_id = n->type_id;
|
|
|
|
int transferred = 0;
|
|
|
|
long i = 0;
|
2003-07-28 15:27:42 -04:00
|
|
|
VALUE obj = Qnil;
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( type_id != NULL && strncmp( type_id, "tag:yaml.org,2002:", 18 ) == 0 )
|
|
|
|
{
|
|
|
|
type_id += 18;
|
|
|
|
}
|
|
|
|
|
2003-05-09 17:25:50 -04:00
|
|
|
switch (n->kind)
|
|
|
|
{
|
|
|
|
case syck_str_kind:
|
2003-08-21 17:16:58 -04:00
|
|
|
transferred = 1;
|
2004-01-12 17:55:09 -05:00
|
|
|
if ( type_id == NULL )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
|
|
|
obj = rb_str_new( n->data.str->ptr, n->data.str->len );
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "null" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
|
|
|
obj = Qnil;
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "binary" ) == 0 )
|
|
|
|
{
|
|
|
|
VALUE arr;
|
|
|
|
obj = rb_str_new( n->data.str->ptr, n->data.str->len );
|
|
|
|
rb_funcall( obj, s_tr_bang, 2, rb_str_new2( "\n\t " ), rb_str_new2( "" ) );
|
|
|
|
arr = rb_funcall( obj, s_unpack, 1, rb_str_new2( "m" ) );
|
|
|
|
obj = rb_ary_shift( arr );
|
|
|
|
}
|
|
|
|
else if ( strcmp( type_id, "bool#yes" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
|
|
|
obj = Qtrue;
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "bool#no" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
|
|
|
obj = Qfalse;
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "int#hex" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2004-01-12 17:55:09 -05:00
|
|
|
syck_str_blow_away_commas( n );
|
2003-05-09 17:25:50 -04:00
|
|
|
obj = rb_cstr2inum( n->data.str->ptr, 16 );
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "int#oct" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2004-01-12 17:55:09 -05:00
|
|
|
syck_str_blow_away_commas( n );
|
2003-05-09 17:25:50 -04:00
|
|
|
obj = rb_cstr2inum( n->data.str->ptr, 8 );
|
|
|
|
}
|
2004-01-12 17:55:09 -05:00
|
|
|
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--;
|
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( colon >= ptr && *colon == ':' ) *colon = '\0';
|
2004-01-12 17:55:09 -05:00
|
|
|
|
|
|
|
bnum = strtol( colon + 1, NULL, 10 );
|
|
|
|
total += bnum * sixty;
|
|
|
|
sixty *= 60;
|
|
|
|
end = colon;
|
|
|
|
}
|
|
|
|
obj = INT2FIX(total);
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strncmp( type_id, "int", 3 ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
|
|
|
syck_str_blow_away_commas( n );
|
|
|
|
obj = rb_cstr2inum( n->data.str->ptr, 10 );
|
|
|
|
}
|
2004-08-07 11:34:39 -04:00
|
|
|
else if ( strcmp( type_id, "float#base60" ) == 0 )
|
|
|
|
{
|
|
|
|
char *ptr, *end;
|
|
|
|
long sixty = 1;
|
|
|
|
double total = 0.0;
|
|
|
|
syck_str_blow_away_commas( n );
|
|
|
|
ptr = n->data.str->ptr;
|
|
|
|
end = n->data.str->ptr + n->data.str->len;
|
|
|
|
while ( end > ptr )
|
|
|
|
{
|
|
|
|
double bnum = 0;
|
|
|
|
char *colon = end - 1;
|
|
|
|
while ( colon >= ptr && *colon != ':' )
|
|
|
|
{
|
|
|
|
colon--;
|
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( colon >= ptr && *colon == ':' ) *colon = '\0';
|
2004-08-07 11:34:39 -04:00
|
|
|
|
|
|
|
bnum = strtod( colon + 1, NULL );
|
|
|
|
total += bnum * sixty;
|
|
|
|
sixty *= 60;
|
|
|
|
end = colon;
|
|
|
|
}
|
|
|
|
obj = rb_float_new( total );
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "float#nan" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
|
|
|
obj = rb_float_new( S_nan() );
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "float#inf" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
|
|
|
obj = rb_float_new( S_inf() );
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "float#neginf" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
|
|
|
obj = rb_float_new( -S_inf() );
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strncmp( type_id, "float", 5 ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
|
|
|
double f;
|
|
|
|
syck_str_blow_away_commas( n );
|
|
|
|
f = strtod( n->data.str->ptr, NULL );
|
|
|
|
obj = rb_float_new( f );
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "timestamp#iso8601" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
obj = rb_syck_mktime( n->data.str->ptr, n->data.str->len );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "timestamp#spaced" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
obj = rb_syck_mktime( n->data.str->ptr, n->data.str->len );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strcmp( type_id, "timestamp#ymd" ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-06-17 12:55:54 -04:00
|
|
|
char *ptr = n->data.str->ptr;
|
|
|
|
VALUE year, mon, day;
|
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Year*/
|
2003-06-17 12:55:54 -04:00
|
|
|
ptr[4] = '\0';
|
|
|
|
year = INT2FIX(strtol(ptr, NULL, 10));
|
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Month*/
|
2003-06-17 12:55:54 -04:00
|
|
|
ptr += 4;
|
2003-12-10 21:39:59 -05:00
|
|
|
while ( !ISDIGIT( *ptr ) ) ptr++;
|
2003-06-17 12:55:54 -04:00
|
|
|
mon = INT2FIX(strtol(ptr, NULL, 10));
|
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/* Day*/
|
2003-06-17 12:55:54 -04:00
|
|
|
ptr += 2;
|
2003-12-10 21:39:59 -05:00
|
|
|
while ( !ISDIGIT( *ptr ) ) ptr++;
|
2003-06-17 12:55:54 -04:00
|
|
|
day = INT2FIX(strtol(ptr, NULL, 10));
|
2004-05-14 23:11:28 -04:00
|
|
|
|
2004-01-13 02:57:33 -05:00
|
|
|
if ( !cDate ) {
|
|
|
|
/*
|
|
|
|
* Load Date module
|
|
|
|
*/
|
|
|
|
rb_require( "date" );
|
|
|
|
cDate = rb_const_get( rb_cObject, rb_intern("Date") );
|
|
|
|
}
|
2003-06-17 12:55:54 -04:00
|
|
|
|
|
|
|
obj = rb_funcall( cDate, s_new, 3, year, mon, day );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
else if ( strncmp( type_id, "timestamp", 9 ) == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
obj = rb_syck_mktime( n->data.str->ptr, n->data.str->len );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
2004-12-23 12:23:02 -05:00
|
|
|
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 );
|
|
|
|
}
|
2004-05-14 23:11:28 -04:00
|
|
|
else if ( n->data.str->style == scalar_plain &&
|
2010-04-22 04:04:13 -04:00
|
|
|
n->data.str->len > 1 &&
|
2004-05-14 23:11:28 -04:00
|
|
|
strncmp( n->data.str->ptr, ":", 1 ) == 0 )
|
2004-01-07 18:46:18 -05:00
|
|
|
{
|
2010-04-22 04:04:13 -04:00
|
|
|
obj = rb_funcall( oDefaultResolver, s_transfer, 2,
|
|
|
|
rb_str_new2( "tag:ruby.yaml.org,2002:sym" ),
|
2004-05-06 02:29:56 -04:00
|
|
|
rb_str_new( n->data.str->ptr + 1, n->data.str->len - 1 ) );
|
2004-01-07 18:46:18 -05:00
|
|
|
}
|
2004-01-12 17:55:09 -05:00
|
|
|
else if ( strcmp( type_id, "str" ) == 0 )
|
2004-01-07 18:46:18 -05:00
|
|
|
{
|
2004-01-12 17:55:09 -05:00
|
|
|
obj = rb_str_new( n->data.str->ptr, n->data.str->len );
|
2008-06-15 05:42:32 -04:00
|
|
|
rb_enc_associate(obj, rb_utf8_encoding());
|
2004-01-07 18:46:18 -05:00
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
else
|
|
|
|
{
|
2003-08-21 17:16:58 -04:00
|
|
|
transferred = 0;
|
2003-05-09 17:25:50 -04:00
|
|
|
obj = rb_str_new( n->data.str->ptr, n->data.str->len );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case syck_seq_kind:
|
2003-10-14 19:15:19 -04:00
|
|
|
if ( type_id == NULL || strcmp( type_id, "seq" ) == 0 )
|
|
|
|
{
|
|
|
|
transferred = 1;
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
obj = rb_ary_new2( n->data.list->idx );
|
|
|
|
for ( i = 0; i < n->data.list->idx; i++ )
|
|
|
|
{
|
|
|
|
rb_ary_store( obj, i, syck_seq_read( n, i ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case syck_map_kind:
|
2003-10-14 19:15:19 -04:00
|
|
|
if ( type_id == NULL || strcmp( type_id, "map" ) == 0 )
|
|
|
|
{
|
|
|
|
transferred = 1;
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
obj = rb_hash_new();
|
|
|
|
for ( i = 0; i < n->data.pairs->idx; i++ )
|
|
|
|
{
|
2004-12-23 12:23:02 -05:00
|
|
|
VALUE k = syck_map_read( n, map_key, i );
|
|
|
|
VALUE v = syck_map_read( n, map_value, i );
|
|
|
|
int skip_aset = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle merge keys
|
|
|
|
*/
|
|
|
|
if ( rb_obj_is_kind_of( k, cMergeKey ) )
|
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE tmp;
|
|
|
|
if ( !NIL_P(tmp = rb_check_convert_type(v, T_HASH, "Hash", "to_hash")) )
|
2004-12-23 12:23:02 -05:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE dup = rb_funcall( tmp, s_dup, 0 );
|
2004-12-23 12:23:02 -05:00
|
|
|
rb_funcall( dup, s_update, 1, obj );
|
|
|
|
obj = dup;
|
|
|
|
skip_aset = 1;
|
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( !NIL_P(tmp = rb_check_array_type(v)) )
|
2004-12-23 12:23:02 -05:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE end = rb_ary_pop( tmp );
|
|
|
|
VALUE tmph = rb_check_convert_type(end, T_HASH, "Hash", "to_hash");
|
|
|
|
if ( !NIL_P(tmph) )
|
2004-12-23 12:23:02 -05:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE dup = rb_funcall( tmph, s_dup, 0 );
|
|
|
|
tmp = rb_ary_reverse( tmp );
|
|
|
|
rb_ary_push( tmp, obj );
|
2006-02-03 05:28:27 -05:00
|
|
|
rb_block_call( tmp, s_each, 0, 0, syck_merge_i, dup );
|
2004-12-23 12:23:02 -05:00
|
|
|
obj = dup;
|
|
|
|
skip_aset = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-03 15:51:25 -04:00
|
|
|
else if ( rb_obj_is_kind_of( k, cDefaultKey ) )
|
|
|
|
{
|
|
|
|
rb_funcall( obj, s_default_set, 1, v );
|
|
|
|
skip_aset = 1;
|
|
|
|
}
|
2003-06-17 21:06:00 -04:00
|
|
|
|
2004-12-23 12:23:02 -05:00
|
|
|
if ( ! skip_aset )
|
|
|
|
{
|
|
|
|
rb_hash_aset( obj, k, v );
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-05-11 02:32:13 -04:00
|
|
|
|
2003-08-21 17:16:58 -04:00
|
|
|
*ref = obj;
|
|
|
|
return transferred;
|
|
|
|
}
|
|
|
|
|
2005-12-06 02:52:18 -05:00
|
|
|
static void syck_node_mark( SyckNode *n );
|
|
|
|
|
2003-08-21 17:16:58 -04:00
|
|
|
/*
|
|
|
|
* {native mode} node handler
|
|
|
|
* - Converts data into native Ruby types
|
|
|
|
*/
|
|
|
|
SYMID
|
2006-06-20 14:02:17 -04:00
|
|
|
rb_syck_load_handler(SyckParser *p, SyckNode *n)
|
2003-08-21 17:16:58 -04:00
|
|
|
{
|
|
|
|
VALUE obj = Qnil;
|
2005-09-12 23:58:33 -04:00
|
|
|
struct parser_xtra *bonus = (struct parser_xtra *)p->bonus;
|
|
|
|
VALUE resolver = bonus->resolver;
|
|
|
|
if ( NIL_P( resolver ) )
|
|
|
|
{
|
|
|
|
resolver = oDefaultResolver;
|
|
|
|
}
|
2003-08-21 17:16:58 -04:00
|
|
|
|
|
|
|
/*
|
2010-04-22 04:04:13 -04:00
|
|
|
* Create node,
|
2003-08-21 17:16:58 -04:00
|
|
|
*/
|
2005-12-17 07:57:05 -05:00
|
|
|
obj = rb_funcall( resolver, s_node_import, 1, Data_Wrap_Struct( cNode, NULL, NULL, n ) );
|
2003-08-21 17:16:58 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/*
|
|
|
|
* ID already set, let's alter the symbol table to accept the new object
|
|
|
|
*/
|
2004-05-06 02:29:56 -04:00
|
|
|
if (n->id > 0 && !NIL_P(obj))
|
2003-06-17 12:55:54 -04:00
|
|
|
{
|
|
|
|
MEMCPY((void *)n->id, (void *)obj, RVALUE, 1);
|
|
|
|
MEMZERO((void *)obj, RVALUE, 1);
|
|
|
|
obj = n->id;
|
|
|
|
}
|
|
|
|
|
2003-08-19 12:38:02 -04:00
|
|
|
if ( bonus->taint) OBJ_TAINT( obj );
|
2004-12-23 12:23:02 -05:00
|
|
|
if ( bonus->proc != 0 ) rb_funcall(bonus->proc, s_call, 1, obj);
|
2003-05-11 02:32:13 -04:00
|
|
|
|
2007-08-29 19:12:21 -04:00
|
|
|
rb_hash_aset(bonus->data, INT2FIX(RHASH_SIZE(bonus->data)), obj);
|
2003-05-09 17:25:50 -04:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* friendly errors.
|
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
void
|
2008-07-22 14:02:12 -04:00
|
|
|
rb_syck_err_handler(SyckParser *p, const char *msg)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
|
|
|
char *endl = p->cursor;
|
|
|
|
|
|
|
|
while ( *endl != '\0' && *endl != '\n' )
|
|
|
|
endl++;
|
|
|
|
|
|
|
|
endl[0] = '\0';
|
2008-07-30 21:51:44 -04:00
|
|
|
rb_raise(rb_eArgError, "%s on line %d, col %"PRIdPTRDIFF": `%s'",
|
2005-09-12 23:58:33 -04:00
|
|
|
msg,
|
|
|
|
p->linect,
|
2010-04-22 04:04:13 -04:00
|
|
|
p->cursor - p->lineptr,
|
|
|
|
p->lineptr);
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2003-07-28 15:27:42 -04:00
|
|
|
/*
|
|
|
|
* provide bad anchor object to the parser.
|
|
|
|
*/
|
2003-06-17 12:55:54 -04:00
|
|
|
SyckNode *
|
2006-06-20 14:02:17 -04:00
|
|
|
rb_syck_bad_anchor_handler(SyckParser *p, char *a)
|
2003-06-17 12:55:54 -04:00
|
|
|
{
|
2003-11-25 14:51:38 -05:00
|
|
|
VALUE anchor_name = rb_str_new2( a );
|
|
|
|
SyckNode *badanc = syck_new_map( rb_str_new2( "name" ), anchor_name );
|
2003-10-14 19:15:19 -04:00
|
|
|
badanc->type_id = syck_strndup( "tag:ruby.yaml.org,2002:object:YAML::Syck::BadAlias", 53 );
|
2003-06-17 12:55:54 -04:00
|
|
|
return badanc;
|
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* data loaded based on the model requested.
|
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
void
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_set_model(VALUE p, VALUE input, VALUE model)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
SyckParser *parser;
|
|
|
|
Data_Get_Struct(p, SyckParser, parser);
|
|
|
|
syck_parser_handler( parser, rb_syck_load_handler );
|
|
|
|
/* WARN: gonna be obsoleted soon!! */
|
2004-12-23 12:23:02 -05:00
|
|
|
if ( model == sym_generic )
|
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_funcall( p, s_set_resolver, 1, oGenericResolver );
|
2004-12-23 12:23:02 -05:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
syck_parser_implicit_typing( parser, 1 );
|
|
|
|
syck_parser_taguri_expansion( parser, 1 );
|
|
|
|
|
|
|
|
if ( NIL_P( input ) )
|
2004-12-23 12:23:02 -05:00
|
|
|
{
|
2010-04-22 04:04:13 -04:00
|
|
|
input = rb_ivar_get( p, s_input );
|
2004-12-23 12:23:02 -05:00
|
|
|
}
|
2003-10-14 19:15:19 -04:00
|
|
|
if ( input == sym_bytecode )
|
|
|
|
{
|
|
|
|
syck_parser_set_input_type( parser, syck_bytecode_utf8 );
|
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
syck_parser_set_input_type( parser, syck_yaml_utf8 );
|
|
|
|
}
|
2003-06-17 12:55:54 -04:00
|
|
|
syck_parser_error_handler( parser, rb_syck_err_handler );
|
|
|
|
syck_parser_bad_anchor_handler( parser, rb_syck_bad_anchor_handler );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2005-12-17 07:57:05 -05:00
|
|
|
static int
|
|
|
|
syck_st_mark_nodes( char *key, SyckNode *n, char *arg )
|
|
|
|
{
|
|
|
|
if ( n != (void *)1 ) syck_node_mark( n );
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2003-07-28 15:27:42 -04:00
|
|
|
* mark parser nodes
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2003-06-05 00:43:05 -04:00
|
|
|
static void
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_mark_parser(SyckParser *parser)
|
2003-06-05 00:43:05 -04:00
|
|
|
{
|
2005-12-19 09:13:27 -05:00
|
|
|
struct parser_xtra *bonus = (struct parser_xtra *)parser->bonus;
|
2005-12-06 02:52:18 -05:00
|
|
|
rb_gc_mark_maybe(parser->root);
|
|
|
|
rb_gc_mark_maybe(parser->root_on_error);
|
2005-12-19 09:13:27 -05:00
|
|
|
rb_gc_mark( bonus->data );
|
|
|
|
rb_gc_mark( bonus->proc );
|
|
|
|
rb_gc_mark( bonus->resolver );
|
|
|
|
|
2005-12-17 07:57:05 -05:00
|
|
|
if ( parser->anchors != NULL )
|
|
|
|
{
|
|
|
|
st_foreach( parser->anchors, syck_st_mark_nodes, 0 );
|
|
|
|
}
|
|
|
|
if ( parser->bad_anchors != NULL )
|
|
|
|
{
|
|
|
|
st_foreach( parser->bad_anchors, syck_st_mark_nodes, 0 );
|
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the parser and any bonus attachment.
|
|
|
|
*/
|
|
|
|
void
|
2006-06-20 14:02:17 -04:00
|
|
|
rb_syck_free_parser(SyckParser *p)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
2005-12-19 09:13:27 -05:00
|
|
|
S_FREE( p->bonus );
|
2005-09-12 23:58:33 -04:00
|
|
|
syck_free_parser(p);
|
2003-06-05 00:43:05 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Parser.allocate
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2005-02-22 09:51:53 -05:00
|
|
|
VALUE syck_parser_s_alloc _((VALUE));
|
2010-04-22 04:04:13 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_parser_s_alloc(VALUE class)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2004-12-23 12:23:02 -05:00
|
|
|
VALUE pobj;
|
2003-05-09 17:25:50 -04:00
|
|
|
SyckParser *parser = syck_new_parser();
|
|
|
|
|
2005-12-19 09:13:27 -05:00
|
|
|
parser->bonus = S_ALLOC( struct parser_xtra );
|
|
|
|
S_MEMZERO( parser->bonus, struct parser_xtra, 1 );
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
pobj = Data_Wrap_Struct( class, syck_mark_parser, rb_syck_free_parser, parser );
|
|
|
|
|
2003-05-15 17:46:47 -04:00
|
|
|
syck_parser_set_root_on_error( parser, Qnil );
|
|
|
|
|
2004-12-23 12:23:02 -05:00
|
|
|
return pobj;
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Parser.initialize( resolver, options )
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
static VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_parser_initialize(int argc, VALUE *argv, VALUE self)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2004-12-23 12:23:02 -05:00
|
|
|
VALUE options;
|
|
|
|
if (rb_scan_args(argc, argv, "01", &options) == 0)
|
|
|
|
{
|
|
|
|
options = rb_hash_new();
|
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else
|
|
|
|
{
|
2004-12-23 12:23:02 -05:00
|
|
|
Check_Type(options, T_HASH);
|
|
|
|
}
|
2004-03-03 18:08:45 -05:00
|
|
|
rb_ivar_set(self, s_options, options);
|
2005-11-01 08:04:35 -05:00
|
|
|
rb_ivar_set(self, s_input, Qnil);
|
2004-12-23 12:23:02 -05:00
|
|
|
return self;
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2003-11-25 14:51:38 -05:00
|
|
|
/*
|
|
|
|
* YAML::Syck::Parser.bufsize = Integer
|
|
|
|
*/
|
|
|
|
static VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_parser_bufsize_set(VALUE self, VALUE size)
|
2003-11-25 14:51:38 -05:00
|
|
|
{
|
2004-12-23 12:23:02 -05:00
|
|
|
SyckParser *parser;
|
2003-11-25 14:51:38 -05:00
|
|
|
|
|
|
|
if ( rb_respond_to( size, s_to_i ) ) {
|
2005-01-20 10:39:22 -05:00
|
|
|
int n = NUM2INT(rb_funcall(size, s_to_i, 0));
|
2004-12-23 12:23:02 -05:00
|
|
|
Data_Get_Struct(self, SyckParser, parser);
|
2005-01-20 10:39:22 -05:00
|
|
|
parser->bufsize = n;
|
2003-11-25 14:51:38 -05:00
|
|
|
}
|
2004-12-23 12:23:02 -05:00
|
|
|
return self;
|
2003-11-25 14:51:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Parser.bufsize => Integer
|
|
|
|
*/
|
|
|
|
static VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_parser_bufsize_get(VALUE self)
|
2003-11-25 14:51:38 -05:00
|
|
|
{
|
2004-12-23 12:23:02 -05:00
|
|
|
SyckParser *parser;
|
2003-11-25 14:51:38 -05:00
|
|
|
|
2004-12-23 12:23:02 -05:00
|
|
|
Data_Get_Struct(self, SyckParser, parser);
|
|
|
|
return INT2FIX( parser->bufsize );
|
2003-11-25 14:51:38 -05:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* YAML::Syck::Parser.load( IO or String )
|
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_parser_load(int argc, VALUE *argv, VALUE self)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-10-14 19:15:19 -04:00
|
|
|
VALUE port, proc, model, input;
|
2004-12-23 12:23:02 -05:00
|
|
|
SyckParser *parser;
|
2005-12-19 09:13:27 -05:00
|
|
|
struct parser_xtra *bonus;
|
2003-05-09 17:25:50 -04:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &port, &proc);
|
|
|
|
|
2004-03-03 18:08:45 -05:00
|
|
|
input = rb_hash_aref( rb_attr_get( self, s_options ), sym_input );
|
|
|
|
model = rb_hash_aref( rb_attr_get( self, s_options ), sym_model );
|
2004-12-23 12:23:02 -05:00
|
|
|
Data_Get_Struct(self, SyckParser, parser);
|
2005-09-12 23:58:33 -04:00
|
|
|
syck_set_model( self, input, model );
|
2004-12-23 12:23:02 -05:00
|
|
|
|
2005-12-19 09:13:27 -05:00
|
|
|
bonus = (struct parser_xtra *)parser->bonus;
|
|
|
|
bonus->taint = syck_parser_assign_io(parser, &port);
|
2009-08-22 02:23:48 -04:00
|
|
|
bonus->data = rb_hash_new();
|
2005-09-12 23:58:33 -04:00
|
|
|
bonus->resolver = rb_attr_get( self, s_resolver );
|
|
|
|
if ( NIL_P( proc ) ) bonus->proc = 0;
|
|
|
|
else bonus->proc = proc;
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-05-22 01:41:06 -04:00
|
|
|
return syck_parse( parser );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* YAML::Syck::Parser.load_documents( IO or String ) { |doc| }
|
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_parser_load_documents(int argc, VALUE *argv, VALUE self)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-10-14 19:15:19 -04:00
|
|
|
VALUE port, proc, v, input, model;
|
2004-12-23 12:23:02 -05:00
|
|
|
SyckParser *parser;
|
2005-12-19 09:13:27 -05:00
|
|
|
struct parser_xtra *bonus;
|
2003-05-09 17:25:50 -04:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "1&", &port, &proc);
|
|
|
|
|
2004-03-03 18:08:45 -05:00
|
|
|
input = rb_hash_aref( rb_attr_get( self, s_options ), sym_input );
|
|
|
|
model = rb_hash_aref( rb_attr_get( self, s_options ), sym_model );
|
2004-12-23 12:23:02 -05:00
|
|
|
Data_Get_Struct(self, SyckParser, parser);
|
2005-09-12 23:58:33 -04:00
|
|
|
syck_set_model( self, input, model );
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2005-12-19 09:13:27 -05:00
|
|
|
bonus = (struct parser_xtra *)parser->bonus;
|
|
|
|
bonus->taint = syck_parser_assign_io(parser, &port);
|
2005-09-12 23:58:33 -04:00
|
|
|
bonus->resolver = rb_attr_get( self, s_resolver );
|
|
|
|
bonus->proc = 0;
|
2004-12-23 12:23:02 -05:00
|
|
|
|
2003-05-09 17:25:50 -04:00
|
|
|
while ( 1 )
|
2004-12-23 12:23:02 -05:00
|
|
|
{
|
2003-06-05 01:40:03 -04:00
|
|
|
/* Reset hash for tracking nodes */
|
2009-08-22 02:23:48 -04:00
|
|
|
bonus->data = rb_hash_new();
|
2003-06-05 01:40:03 -04:00
|
|
|
|
|
|
|
/* Parse a document */
|
2004-12-23 12:23:02 -05:00
|
|
|
v = syck_parse( parser );
|
2003-05-09 17:25:50 -04:00
|
|
|
if ( parser->eof == 1 )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2003-06-05 01:40:03 -04:00
|
|
|
|
|
|
|
/* Pass document to block */
|
2004-12-23 12:23:02 -05:00
|
|
|
rb_funcall( proc, s_call, 1, v );
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Parser#set_resolver
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_parser_set_resolver(VALUE self, VALUE resolver)
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_ivar_set( self, s_resolver, resolver );
|
2004-06-29 13:34:08 -04:00
|
|
|
return self;
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Resolver.initialize
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2005-09-12 23:58:33 -04:00
|
|
|
static VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_resolver_initialize(VALUE self)
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_ivar_set(self, s_tags, rb_hash_new());
|
|
|
|
return self;
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Resolver#add_type
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_resolver_add_type(VALUE self, VALUE taguri, VALUE cls)
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE tags = rb_attr_get(self, s_tags);
|
|
|
|
rb_hash_aset( tags, taguri, cls );
|
2003-05-13 02:34:18 -04:00
|
|
|
return Qnil;
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Resolver#use_types_at
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_resolver_use_types_at(VALUE self, VALUE hsh)
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_ivar_set( self, s_tags, hsh );
|
2003-05-13 02:34:18 -04:00
|
|
|
return Qnil;
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2010-04-22 04:04:13 -04:00
|
|
|
* YAML::Syck::Resolver#detect_implicit
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_resolver_detect_implicit(VALUE self, VALUE val)
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
return rb_str_new2( "" );
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Resolver#node_import
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_resolver_node_import(VALUE self, VALUE node)
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
SyckNode *n;
|
2008-07-22 10:04:10 -04:00
|
|
|
VALUE obj = Qnil;
|
2005-09-12 23:58:33 -04:00
|
|
|
int i = 0;
|
|
|
|
Data_Get_Struct(node, SyckNode, n);
|
|
|
|
|
|
|
|
switch (n->kind)
|
|
|
|
{
|
|
|
|
case syck_str_kind:
|
|
|
|
obj = rb_str_new( n->data.str->ptr, n->data.str->len );
|
|
|
|
break;
|
2003-05-10 15:55:18 -04:00
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
case syck_seq_kind:
|
|
|
|
obj = rb_ary_new2( n->data.list->idx );
|
|
|
|
for ( i = 0; i < n->data.list->idx; i++ )
|
|
|
|
{
|
|
|
|
rb_ary_store( obj, i, syck_seq_read( n, i ) );
|
|
|
|
}
|
|
|
|
break;
|
2003-05-10 15:55:18 -04:00
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
case syck_map_kind:
|
|
|
|
obj = rb_hash_new();
|
|
|
|
for ( i = 0; i < n->data.pairs->idx; i++ )
|
|
|
|
{
|
|
|
|
VALUE k = syck_map_read( n, map_key, i );
|
|
|
|
VALUE v = syck_map_read( n, map_value, i );
|
|
|
|
int skip_aset = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle merge keys
|
|
|
|
*/
|
|
|
|
if ( rb_obj_is_kind_of( k, cMergeKey ) )
|
|
|
|
{
|
|
|
|
if ( rb_obj_is_kind_of( v, rb_cHash ) )
|
|
|
|
{
|
|
|
|
VALUE dup = rb_funcall( v, s_dup, 0 );
|
|
|
|
rb_funcall( dup, s_update, 1, obj );
|
|
|
|
obj = dup;
|
|
|
|
skip_aset = 1;
|
|
|
|
}
|
|
|
|
else if ( rb_obj_is_kind_of( v, rb_cArray ) )
|
|
|
|
{
|
|
|
|
VALUE end = rb_ary_pop( v );
|
|
|
|
if ( rb_obj_is_kind_of( end, rb_cHash ) )
|
|
|
|
{
|
|
|
|
VALUE dup = rb_funcall( end, s_dup, 0 );
|
|
|
|
v = rb_ary_reverse( v );
|
|
|
|
rb_ary_push( v, obj );
|
2006-02-03 05:28:27 -05:00
|
|
|
rb_block_call( v, s_each, 0, 0, syck_merge_i, dup );
|
2005-09-12 23:58:33 -04:00
|
|
|
obj = dup;
|
|
|
|
skip_aset = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( rb_obj_is_kind_of( k, cDefaultKey ) )
|
|
|
|
{
|
|
|
|
rb_funcall( obj, s_default_set, 1, v );
|
|
|
|
skip_aset = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! skip_aset )
|
|
|
|
{
|
|
|
|
rb_hash_aset( obj, k, v );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( n->type_id != NULL )
|
|
|
|
{
|
|
|
|
obj = rb_funcall( self, s_transfer, 2, rb_str_new2( n->type_id ), obj );
|
|
|
|
}
|
|
|
|
return obj;
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* Set instance variables
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_set_ivars(VALUE vars, VALUE obj)
|
2003-05-13 02:34:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE ivname = rb_ary_entry( vars, 0 );
|
|
|
|
char *ivn;
|
|
|
|
StringValue( ivname );
|
2006-08-31 06:30:33 -04:00
|
|
|
ivn = S_ALLOCA_N( char, RSTRING_LEN(ivname) + 2 );
|
2005-12-31 05:57:06 -05:00
|
|
|
ivn[0] = '@';
|
|
|
|
ivn[1] = '\0';
|
2006-08-31 06:30:33 -04:00
|
|
|
strncat( ivn, RSTRING_PTR(ivname), RSTRING_LEN(ivname) );
|
2005-12-31 05:57:06 -05:00
|
|
|
rb_iv_set( obj, ivn, rb_ary_entry( vars, 1 ) );
|
2005-09-12 23:58:33 -04:00
|
|
|
return Qnil;
|
2003-05-13 02:34:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Resolver#const_find
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_const_find(VALUE const_name)
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE tclass = rb_cObject;
|
|
|
|
VALUE tparts = rb_str_split( const_name, "::" );
|
|
|
|
int i = 0;
|
2006-09-02 10:42:08 -04:00
|
|
|
for ( i = 0; i < RARRAY_LEN(tparts); i++ ) {
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE tpart = rb_to_id( rb_ary_entry( tparts, i ) );
|
|
|
|
if ( !rb_const_defined( tclass, tpart ) ) return Qnil;
|
|
|
|
tclass = rb_const_get( tclass, tpart );
|
2004-12-23 12:23:02 -05:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
return tclass;
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Resolver#transfer
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_resolver_transfer(VALUE self, VALUE type, VALUE val)
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2010-04-22 04:04:13 -04:00
|
|
|
if (NIL_P(type) || RSTRING_LEN(StringValue(type)) == 0)
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
type = rb_funcall( self, s_detect_implicit, 1, val );
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2006-08-31 06:30:33 -04:00
|
|
|
if ( ! (NIL_P(type) || RSTRING_LEN(StringValue(type)) == 0) )
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE str_xprivate = rb_str_new2( "x-private" );
|
|
|
|
VALUE colon = rb_str_new2( ":" );
|
|
|
|
VALUE tags = rb_attr_get(self, s_tags);
|
|
|
|
VALUE target_class = rb_hash_aref( tags, type );
|
|
|
|
VALUE subclass = target_class;
|
|
|
|
VALUE obj = Qnil;
|
2003-05-10 15:55:18 -04:00
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
/*
|
|
|
|
* Should no tag match exactly, check for subclass format
|
|
|
|
*/
|
|
|
|
if ( NIL_P( target_class ) )
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE subclass_parts = rb_ary_new();
|
|
|
|
VALUE parts = rb_str_split( type, ":" );
|
|
|
|
|
2006-09-02 10:42:08 -04:00
|
|
|
while ( RARRAY_LEN(parts) > 1 )
|
2003-08-21 17:16:58 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE partial;
|
|
|
|
rb_ary_unshift( subclass_parts, rb_ary_pop( parts ) );
|
|
|
|
partial = rb_ary_join( parts, colon );
|
|
|
|
target_class = rb_hash_aref( tags, partial );
|
|
|
|
if ( NIL_P( target_class ) )
|
2003-08-21 17:16:58 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_str_append( partial, colon );
|
|
|
|
target_class = rb_hash_aref( tags, partial );
|
2003-08-21 17:16:58 -04:00
|
|
|
}
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
/*
|
|
|
|
* Possible subclass found, see if it supports subclassing
|
|
|
|
*/
|
|
|
|
if ( ! NIL_P( target_class ) )
|
|
|
|
{
|
|
|
|
subclass = target_class;
|
2006-09-02 10:42:08 -04:00
|
|
|
if ( RARRAY_LEN(subclass_parts) > 0 && rb_respond_to( target_class, s_tag_subclasses ) &&
|
2005-09-12 23:58:33 -04:00
|
|
|
RTEST( rb_funcall( target_class, s_tag_subclasses, 0 ) ) )
|
|
|
|
{
|
|
|
|
VALUE subclass_v;
|
|
|
|
subclass = rb_ary_join( subclass_parts, colon );
|
|
|
|
subclass = rb_funcall( target_class, s_tag_read_class, 1, subclass );
|
|
|
|
subclass_v = syck_const_find( subclass );
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
if ( subclass_v != Qnil )
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
subclass = subclass_v;
|
|
|
|
}
|
|
|
|
else if ( rb_cObject == target_class && subclass_v == Qnil )
|
|
|
|
{
|
|
|
|
target_class = cYObject;
|
|
|
|
type = subclass;
|
|
|
|
subclass = cYObject;
|
|
|
|
}
|
2006-01-30 10:13:11 -05:00
|
|
|
else /* workaround for SEGV. real fix please */
|
|
|
|
{
|
|
|
|
rb_raise( rb_eTypeError, "invalid subclass" );
|
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
/* rb_raise(rb_eTypeError, "invalid typing scheme: %s given",
|
|
|
|
* scheme);
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( rb_respond_to( target_class, s_call ) )
|
|
|
|
{
|
|
|
|
obj = rb_funcall( target_class, s_call, 2, type, val );
|
|
|
|
}
|
|
|
|
else
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( rb_respond_to( target_class, s_yaml_new ) )
|
2003-05-10 15:55:18 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
obj = rb_funcall( target_class, s_yaml_new, 3, subclass, type, val );
|
|
|
|
}
|
|
|
|
else if ( !NIL_P( target_class ) )
|
|
|
|
{
|
2006-01-09 23:38:23 -05:00
|
|
|
if ( subclass == rb_cBignum )
|
|
|
|
{
|
|
|
|
obj = rb_str2inum( val, 10 ); /* for yaml dumped by 1.8.3 [ruby-core:6159] */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
obj = rb_obj_alloc( subclass );
|
|
|
|
}
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( rb_respond_to( obj, s_yaml_initialize ) )
|
|
|
|
{
|
|
|
|
rb_funcall( obj, s_yaml_initialize, 2, type, val );
|
|
|
|
}
|
|
|
|
else if ( !NIL_P( obj ) && rb_obj_is_instance_of( val, rb_cHash ) )
|
2003-08-21 17:16:58 -04:00
|
|
|
{
|
2006-02-03 05:28:27 -05:00
|
|
|
rb_block_call( val, s_each, 0, 0, syck_set_ivars, obj );
|
2003-08-21 17:16:58 -04:00
|
|
|
}
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
2010-04-22 04:04:13 -04:00
|
|
|
else
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
VALUE parts = rb_str_split( type, ":" );
|
|
|
|
VALUE scheme = rb_ary_shift( parts );
|
|
|
|
if ( rb_str_cmp( scheme, str_xprivate ) == 0 )
|
|
|
|
{
|
|
|
|
VALUE name = rb_ary_join( parts, colon );
|
|
|
|
obj = rb_funcall( cPrivateType, s_new, 2, name, val );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VALUE domain = rb_ary_shift( parts );
|
|
|
|
VALUE name = rb_ary_join( parts, colon );
|
|
|
|
obj = rb_funcall( cDomainType, s_new, 3, domain, name, val );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val = obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
2003-05-10 15:55:18 -04:00
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
/*
|
|
|
|
* YAML::Syck::Resolver#tagurize
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_resolver_tagurize(VALUE self, VALUE val)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
VALUE tmp = rb_check_string_type(val);
|
|
|
|
|
|
|
|
if ( !NIL_P(tmp) )
|
|
|
|
{
|
2006-08-31 06:30:33 -04:00
|
|
|
char *taguri = syck_type_id_to_uri( RSTRING_PTR(tmp) );
|
2005-12-15 21:45:35 -05:00
|
|
|
val = rb_str_new2( taguri );
|
|
|
|
S_FREE( taguri );
|
2005-09-12 23:58:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-04-22 04:04:13 -04:00
|
|
|
* YAML::Syck::DefaultResolver#detect_implicit
|
2005-09-12 23:58:33 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_defaultresolver_detect_implicit(VALUE self, VALUE val)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
2008-07-22 14:02:12 -04:00
|
|
|
const char *type_id;
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE tmp = rb_check_string_type(val);
|
|
|
|
|
|
|
|
if ( !NIL_P(tmp) )
|
|
|
|
{
|
|
|
|
val = tmp;
|
2006-08-31 06:30:33 -04:00
|
|
|
type_id = syck_match_implicit( RSTRING_PTR(val), RSTRING_LEN(val) );
|
2005-09-12 23:58:33 -04:00
|
|
|
return rb_str_new2( type_id );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rb_str_new2( "" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::DefaultResolver#node_import
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_defaultresolver_node_import(VALUE self, VALUE node)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *n;
|
|
|
|
VALUE obj;
|
|
|
|
Data_Get_Struct( node, SyckNode, n );
|
|
|
|
if ( !yaml_org_handler( n, &obj ) )
|
|
|
|
{
|
|
|
|
obj = rb_funcall( self, s_transfer, 2, rb_str_new2( n->type_id ), obj );
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::GenericResolver#node_import
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_genericresolver_node_import(VALUE self, VALUE node)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *n;
|
|
|
|
int i = 0;
|
|
|
|
VALUE t = Qnil, obj = Qnil, v = Qnil, style = Qnil;
|
|
|
|
Data_Get_Struct(node, SyckNode, n);
|
|
|
|
|
|
|
|
if ( n->type_id != NULL )
|
|
|
|
{
|
|
|
|
t = rb_str_new2(n->type_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (n->kind)
|
|
|
|
{
|
|
|
|
case syck_str_kind:
|
|
|
|
{
|
|
|
|
v = rb_str_new( n->data.str->ptr, n->data.str->len );
|
2008-06-15 05:42:32 -04:00
|
|
|
rb_enc_associate(v, rb_utf8_encoding());
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( n->data.str->style == scalar_1quote )
|
|
|
|
{
|
|
|
|
style = sym_1quote;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( n->data.str->style == scalar_2quote )
|
2003-08-21 17:16:58 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
style = sym_2quote;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( n->data.str->style == scalar_fold )
|
|
|
|
{
|
|
|
|
style = sym_fold;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( n->data.str->style == scalar_literal )
|
|
|
|
{
|
|
|
|
style = sym_literal;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( n->data.str->style == scalar_plain )
|
|
|
|
{
|
|
|
|
style = sym_plain;
|
2003-08-21 17:16:58 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
obj = rb_funcall( cScalar, s_new, 3, t, v, style );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case syck_seq_kind:
|
|
|
|
v = rb_ary_new2( syck_seq_count( n ) );
|
|
|
|
for ( i = 0; i < syck_seq_count( n ); i++ )
|
2003-08-21 17:16:58 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_ary_store( v, i, syck_seq_read( n, i ) );
|
2003-08-21 17:16:58 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( n->data.list->style == seq_inline )
|
2003-08-21 17:16:58 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
style = sym_inline;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
obj = rb_funcall( cSeq, s_new, 3, t, v, style );
|
2007-12-22 07:14:37 -05:00
|
|
|
rb_iv_set(obj, "@kind", sym_seq);
|
2005-09-12 23:58:33 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case syck_map_kind:
|
|
|
|
v = rb_hash_new();
|
|
|
|
for ( i = 0; i < syck_map_count( n ); i++ )
|
|
|
|
{
|
|
|
|
rb_hash_aset( v, syck_map_read( n, map_key, i ), syck_map_read( n, map_value, i ) );
|
2003-08-21 17:16:58 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( n->data.pairs->style == map_inline )
|
|
|
|
{
|
|
|
|
style = sym_inline;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
obj = rb_funcall( cMap, s_new, 3, t, v, style );
|
2007-12-22 07:14:37 -05:00
|
|
|
rb_iv_set(obj, "@kind", sym_map);
|
2005-09-12 23:58:33 -04:00
|
|
|
break;
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
return obj;
|
2003-05-10 15:55:18 -04:00
|
|
|
}
|
|
|
|
|
2003-06-17 12:55:54 -04:00
|
|
|
/*
|
|
|
|
* YAML::Syck::BadAlias.initialize
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_badalias_initialize(VALUE self, VALUE val)
|
2003-06-17 12:55:54 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_iv_set( self, "@name", val );
|
2003-06-17 12:55:54 -04:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-05-06 02:29:56 -04:00
|
|
|
/*
|
|
|
|
* YAML::Syck::BadAlias.<=>
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_badalias_cmp(VALUE alias1, VALUE alias2)
|
2004-05-06 02:29:56 -04:00
|
|
|
{
|
2010-04-22 04:04:13 -04:00
|
|
|
VALUE str1 = rb_ivar_get( alias1, s_name );
|
|
|
|
VALUE str2 = rb_ivar_get( alias2, s_name );
|
2004-05-06 02:29:56 -04:00
|
|
|
VALUE val = rb_funcall( str1, s_cmp, 1, str2 );
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2003-06-17 12:55:54 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::DomainType.initialize
|
2003-06-17 12:55:54 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_domaintype_initialize(VALUE self, VALUE domain, VALUE type_id, VALUE val)
|
2003-06-17 12:55:54 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_iv_set( self, "@domain", domain );
|
|
|
|
rb_iv_set( self, "@type_id", type_id );
|
|
|
|
rb_iv_set( self, "@value", val );
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Object.initialize
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_yobject_initialize(VALUE self, VALUE klass, VALUE ivars)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
rb_iv_set( self, "@class", klass );
|
|
|
|
rb_iv_set( self, "@ivars", ivars );
|
2003-06-17 12:55:54 -04:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::PrivateType.initialize
|
2003-06-17 12:55:54 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_privatetype_initialize(VALUE self, VALUE type_id, VALUE val)
|
2003-06-17 12:55:54 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_iv_set( self, "@type_id", type_id );
|
|
|
|
rb_iv_set( self, "@value", val );
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark node contents.
|
|
|
|
*/
|
|
|
|
static void
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_node_mark(SyckNode *n)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
int i;
|
2005-12-06 02:52:18 -05:00
|
|
|
rb_gc_mark_maybe( n->id );
|
2005-09-12 23:58:33 -04:00
|
|
|
switch ( n->kind )
|
|
|
|
{
|
|
|
|
case syck_seq_kind:
|
|
|
|
for ( i = 0; i < n->data.list->idx; i++ )
|
|
|
|
{
|
|
|
|
rb_gc_mark( syck_seq_read( n, i ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case syck_map_kind:
|
|
|
|
for ( i = 0; i < n->data.pairs->idx; i++ )
|
|
|
|
{
|
|
|
|
rb_gc_mark( syck_map_read( n, map_key, i ) );
|
|
|
|
rb_gc_mark( syck_map_read( n, map_value, i ) );
|
|
|
|
}
|
|
|
|
break;
|
2008-07-22 10:04:10 -04:00
|
|
|
|
|
|
|
case syck_str_kind:
|
2008-07-25 01:48:32 -04:00
|
|
|
default:
|
2008-07-22 10:04:10 -04:00
|
|
|
/* nothing */
|
|
|
|
break;
|
2005-09-12 23:58:33 -04:00
|
|
|
}
|
2005-12-15 21:45:35 -05:00
|
|
|
#if 0 /* maybe needed */
|
|
|
|
if ( n->shortcut ) syck_node_mark( n->shortcut ); /* caution: maybe cyclic */
|
|
|
|
#endif
|
2005-09-12 23:58:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Scalar.allocate
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_scalar_alloc(VALUE class)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node = syck_alloc_str();
|
2005-12-19 09:13:27 -05:00
|
|
|
VALUE obj = Data_Wrap_Struct( class, syck_node_mark, syck_free_node, node );
|
2005-09-12 23:58:33 -04:00
|
|
|
node->id = obj;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Scalar.initialize
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_scalar_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
rb_iv_set( self, "@kind", sym_scalar );
|
|
|
|
rb_funcall( self, s_type_id_set, 1, type_id );
|
|
|
|
rb_funcall( self, s_value_set, 1, val );
|
|
|
|
rb_funcall( self, s_style_set, 1, style );
|
2003-06-17 12:55:54 -04:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Scalar.style=
|
2003-05-13 02:34:18 -04:00
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_scalar_style_set(VALUE self, VALUE style)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
SyckNode *node;
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
|
|
|
if ( NIL_P( style ) )
|
|
|
|
{
|
|
|
|
node->data.str->style = scalar_none;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( style == sym_1quote )
|
|
|
|
{
|
|
|
|
node->data.str->style = scalar_1quote;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( style == sym_2quote )
|
|
|
|
{
|
|
|
|
node->data.str->style = scalar_2quote;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( style == sym_fold )
|
|
|
|
{
|
|
|
|
node->data.str->style = scalar_fold;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( style == sym_literal )
|
|
|
|
{
|
|
|
|
node->data.str->style = scalar_literal;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( style == sym_plain )
|
|
|
|
{
|
|
|
|
node->data.str->style = scalar_plain;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_iv_set( self, "@style", style );
|
2003-05-13 02:34:18 -04:00
|
|
|
return self;
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
/*
|
|
|
|
* YAML::Syck::Scalar.value=
|
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_scalar_value_set(VALUE self, VALUE val)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
SyckNode *node;
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
|
|
|
StringValue( val );
|
2006-08-31 06:30:33 -04:00
|
|
|
node->data.str->ptr = syck_strndup( RSTRING_PTR(val), RSTRING_LEN(val) );
|
|
|
|
node->data.str->len = RSTRING_LEN(val);
|
2005-09-12 23:58:33 -04:00
|
|
|
node->data.str->style = scalar_none;
|
|
|
|
|
|
|
|
rb_iv_set( self, "@value", val );
|
|
|
|
return val;
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
/*
|
|
|
|
* YAML::Syck::Seq.allocate
|
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_seq_alloc(VALUE class)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
SyckNode *node;
|
|
|
|
VALUE obj;
|
|
|
|
node = syck_alloc_seq();
|
2005-12-19 09:13:27 -05:00
|
|
|
obj = Data_Wrap_Struct( class, syck_node_mark, syck_free_node, node );
|
2005-09-12 23:58:33 -04:00
|
|
|
node->id = obj;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Seq.initialize
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_seq_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node;
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
|
|
|
rb_iv_set( self, "@kind", sym_seq );
|
|
|
|
rb_funcall( self, s_type_id_set, 1, type_id );
|
|
|
|
rb_funcall( self, s_value_set, 1, val );
|
|
|
|
rb_funcall( self, s_style_set, 1, style );
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Seq.value=
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_seq_value_set(VALUE self, VALUE val)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node;
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
|
|
|
val = rb_check_array_type( val );
|
|
|
|
if ( !NIL_P( val ) ) {
|
|
|
|
int i;
|
|
|
|
syck_seq_empty( node );
|
2006-09-02 10:42:08 -04:00
|
|
|
for ( i = 0; i < RARRAY_LEN( val ); i++ )
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
syck_seq_add( node, rb_ary_entry(val, i) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_iv_set( self, "@value", val );
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Seq.add
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_seq_add_m(VALUE self, VALUE val)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node;
|
|
|
|
VALUE emitter = rb_ivar_get( self, s_emitter );
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
|
|
|
if ( rb_respond_to( emitter, s_node_export ) ) {
|
|
|
|
val = rb_funcall( emitter, s_node_export, 1, val );
|
|
|
|
}
|
|
|
|
syck_seq_add( node, val );
|
|
|
|
rb_ary_push( rb_ivar_get( self, s_value ), val );
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Seq.style=
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_seq_style_set(VALUE self, VALUE style)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node;
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
|
|
|
if ( style == sym_inline )
|
|
|
|
{
|
|
|
|
node->data.list->style = seq_inline;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
node->data.list->style = seq_none;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_iv_set( self, "@style", style );
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Map.allocate
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_map_alloc(VALUE class)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node;
|
|
|
|
VALUE obj;
|
|
|
|
node = syck_alloc_map();
|
2005-12-19 09:13:27 -05:00
|
|
|
obj = Data_Wrap_Struct( class, syck_node_mark, syck_free_node, node );
|
2005-09-12 23:58:33 -04:00
|
|
|
node->id = obj;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Map.initialize
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_map_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node;
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
|
|
|
if ( !NIL_P( val ) )
|
|
|
|
{
|
|
|
|
VALUE hsh = rb_check_convert_type(val, T_HASH, "Hash", "to_hash");
|
|
|
|
VALUE keys;
|
|
|
|
int i;
|
|
|
|
if ( NIL_P(hsh) )
|
|
|
|
{
|
|
|
|
rb_raise( rb_eTypeError, "wrong argument type" );
|
|
|
|
}
|
|
|
|
|
|
|
|
keys = rb_funcall( hsh, s_keys, 0 );
|
2006-09-02 10:42:08 -04:00
|
|
|
for ( i = 0; i < RARRAY_LEN(keys); i++ )
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
VALUE key = rb_ary_entry(keys, i);
|
|
|
|
syck_map_add( node, key, rb_hash_aref(hsh, key) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_iv_set( self, "@kind", sym_seq );
|
|
|
|
rb_funcall( self, s_type_id_set, 1, type_id );
|
|
|
|
rb_funcall( self, s_value_set, 1, val );
|
|
|
|
rb_funcall( self, s_style_set, 1, style );
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Map.value=
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_map_value_set(VALUE self, VALUE val)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node;
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
|
|
|
if ( !NIL_P( val ) )
|
|
|
|
{
|
|
|
|
VALUE hsh = rb_check_convert_type(val, T_HASH, "Hash", "to_hash");
|
|
|
|
VALUE keys;
|
|
|
|
int i;
|
|
|
|
if ( NIL_P(hsh) )
|
|
|
|
{
|
|
|
|
rb_raise( rb_eTypeError, "wrong argument type" );
|
|
|
|
}
|
|
|
|
|
|
|
|
syck_map_empty( node );
|
|
|
|
keys = rb_funcall( hsh, s_keys, 0 );
|
2006-09-02 10:42:08 -04:00
|
|
|
for ( i = 0; i < RARRAY_LEN(keys); i++ )
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
VALUE key = rb_ary_entry(keys, i);
|
|
|
|
syck_map_add( node, key, rb_hash_aref(hsh, key) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_iv_set( self, "@value", val );
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Map.add
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_map_add_m(VALUE self, VALUE key, VALUE val)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node;
|
|
|
|
VALUE emitter = rb_ivar_get( self, s_emitter );
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
|
|
|
if ( rb_respond_to( emitter, s_node_export ) ) {
|
|
|
|
key = rb_funcall( emitter, s_node_export, 1, key );
|
|
|
|
val = rb_funcall( emitter, s_node_export, 1, val );
|
|
|
|
}
|
|
|
|
syck_map_add( node, key, val );
|
|
|
|
rb_hash_aset( rb_ivar_get( self, s_value ), key, val );
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Map.style=
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_map_style_set(VALUE self, VALUE style)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node;
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
|
|
|
if ( style == sym_inline )
|
|
|
|
{
|
|
|
|
node->data.pairs->style = map_inline;
|
2010-04-22 04:04:13 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
node->data.pairs->style = map_none;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_iv_set( self, "@style", style );
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-02-04 22:05:35 -05:00
|
|
|
#if 0
|
2005-09-12 23:58:33 -04:00
|
|
|
/*
|
|
|
|
* Cloning method for all node types
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_node_init_copy(VALUE copy, VALUE orig)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *copy_n;
|
|
|
|
SyckNode *orig_n;
|
|
|
|
|
|
|
|
if ( copy == orig )
|
|
|
|
return copy;
|
|
|
|
|
2005-12-19 09:13:27 -05:00
|
|
|
if ( TYPE( orig ) != T_DATA )
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
rb_raise( rb_eTypeError, "wrong argument type" );
|
|
|
|
}
|
|
|
|
|
|
|
|
Data_Get_Struct( orig, SyckNode, orig_n );
|
|
|
|
Data_Get_Struct( copy, SyckNode, copy_n );
|
|
|
|
MEMCPY( copy_n, orig_n, SyckNode, 1 );
|
|
|
|
return copy;
|
|
|
|
}
|
2011-02-04 22:05:35 -05:00
|
|
|
#endif
|
2005-09-12 23:58:33 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Node#type_id=
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_node_type_id_set(VALUE self, VALUE type_id)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *node;
|
|
|
|
Data_Get_Struct( self, SyckNode, node );
|
|
|
|
|
2005-12-19 09:13:27 -05:00
|
|
|
S_FREE( node->type_id );
|
|
|
|
|
|
|
|
if ( !NIL_P( type_id ) ) {
|
|
|
|
StringValue( type_id );
|
2006-08-31 06:30:33 -04:00
|
|
|
node->type_id = syck_strndup( RSTRING_PTR(type_id), RSTRING_LEN(type_id) );
|
2005-09-12 23:58:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
rb_iv_set( self, "@type_id", type_id );
|
|
|
|
return type_id;
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* YAML::Syck::Node.transform
|
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_node_transform(VALUE self)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE t;
|
2008-07-22 10:04:10 -04:00
|
|
|
SyckNode *n = NULL;
|
2005-09-12 23:58:33 -04:00
|
|
|
SyckNode *orig_n;
|
|
|
|
Data_Get_Struct(self, SyckNode, orig_n);
|
2005-12-19 22:34:39 -05:00
|
|
|
t = Data_Wrap_Struct( cNode, syck_node_mark, syck_free_node, 0 );
|
2005-09-12 23:58:33 -04:00
|
|
|
|
|
|
|
switch (orig_n->kind)
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
case syck_map_kind:
|
|
|
|
{
|
|
|
|
int i;
|
2005-12-06 02:52:18 -05:00
|
|
|
DATA_PTR(t) = n = syck_alloc_map();
|
2005-09-12 23:58:33 -04:00
|
|
|
for ( i = 0; i < orig_n->data.pairs->idx; i++ )
|
|
|
|
{
|
|
|
|
syck_map_add( n, rb_funcall( syck_map_read( orig_n, map_key, i ), s_transform, 0 ),
|
|
|
|
rb_funcall( syck_map_read( orig_n, map_value, i ), s_transform, 0 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case syck_seq_kind:
|
|
|
|
{
|
|
|
|
int i;
|
2005-12-06 02:52:18 -05:00
|
|
|
DATA_PTR(t) = n = syck_alloc_seq();
|
2005-09-12 23:58:33 -04:00
|
|
|
for ( i = 0; i < orig_n->data.list->idx; i++ )
|
|
|
|
{
|
|
|
|
syck_seq_add( n, rb_funcall( syck_seq_read( orig_n, i ), s_transform, 0 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case syck_str_kind:
|
2005-12-06 02:52:18 -05:00
|
|
|
DATA_PTR(t) = n = syck_new_str2( orig_n->data.str->ptr, orig_n->data.str->len, orig_n->data.str->style );
|
2005-09-12 23:58:33 -04:00
|
|
|
break;
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
|
|
|
|
if ( orig_n->type_id != NULL )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
n->type_id = syck_strndup( orig_n->type_id, strlen( orig_n->type_id ) );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
if ( orig_n->anchor != NULL )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
n->anchor = syck_strndup( orig_n->anchor, strlen( orig_n->anchor ) );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
n->id = t;
|
2005-12-19 22:34:39 -05:00
|
|
|
return rb_funcall( oDefaultResolver, s_node_import, 1, t );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2003-07-11 18:52:14 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* Emitter callback: assembles YAML document events from
|
|
|
|
* Ruby symbols. This is a brilliant way to do it.
|
|
|
|
* No one could possibly object.
|
2003-07-11 18:52:14 -04:00
|
|
|
*/
|
2004-12-23 12:23:02 -05:00
|
|
|
void
|
2006-06-20 14:02:17 -04:00
|
|
|
rb_syck_emitter_handler(SyckEmitter *e, st_data_t data)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckNode *n;
|
|
|
|
Data_Get_Struct((VALUE)data, SyckNode, n);
|
|
|
|
|
|
|
|
switch (n->kind)
|
|
|
|
{
|
|
|
|
case syck_map_kind:
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
syck_emit_map( e, n->type_id, n->data.pairs->style );
|
|
|
|
for ( i = 0; i < n->data.pairs->idx; i++ )
|
|
|
|
{
|
|
|
|
syck_emit_item( e, syck_map_read( n, map_key, i ) );
|
|
|
|
syck_emit_item( e, syck_map_read( n, map_value, i ) );
|
|
|
|
}
|
|
|
|
syck_emit_end( e );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case syck_seq_kind:
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
syck_emit_seq( e, n->type_id, n->data.list->style );
|
|
|
|
for ( i = 0; i < n->data.list->idx; i++ )
|
|
|
|
{
|
|
|
|
syck_emit_item( e, syck_seq_read( n, i ) );
|
|
|
|
}
|
|
|
|
syck_emit_end( e );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case syck_str_kind:
|
|
|
|
{
|
|
|
|
syck_emit_scalar( e, n->type_id, n->data.str->style, 0, 0, 0, n->data.str->ptr, n->data.str->len );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle output from the emitter
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
void
|
2006-06-20 14:02:17 -04:00
|
|
|
rb_syck_output_handler(SyckEmitter * emitter, char *str, long len)
|
2003-07-11 18:52:14 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
struct emitter_xtra *bonus = (struct emitter_xtra *)emitter->bonus;
|
|
|
|
VALUE dest = bonus->port;
|
2004-12-23 12:23:02 -05:00
|
|
|
if (TYPE(dest) == T_STRING) {
|
2003-07-24 12:30:43 -04:00
|
|
|
rb_str_cat( dest, str, len );
|
|
|
|
} else {
|
|
|
|
rb_io_write( dest, rb_str_new( str, len ) );
|
|
|
|
}
|
2003-07-11 18:52:14 -04:00
|
|
|
}
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
/*
|
|
|
|
* Helper function for marking nodes in the anchor
|
|
|
|
* symbol table.
|
|
|
|
*/
|
|
|
|
void
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_out_mark(VALUE emitter, VALUE node)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
SyckEmitter *emitterPtr;
|
|
|
|
struct emitter_xtra *bonus;
|
|
|
|
Data_Get_Struct(emitter, SyckEmitter, emitterPtr);
|
|
|
|
bonus = (struct emitter_xtra *)emitterPtr->bonus;
|
|
|
|
rb_ivar_set( node, s_emitter, emitter );
|
|
|
|
/* syck_emitter_mark_node( emitterPtr, (st_data_t)node ); */
|
|
|
|
if ( !NIL_P( bonus->oid ) ) {
|
|
|
|
rb_hash_aset( bonus->data, bonus->oid, node );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-11 18:52:14 -04:00
|
|
|
/*
|
|
|
|
* Mark emitter values.
|
|
|
|
*/
|
|
|
|
static void
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_mark_emitter(SyckEmitter *emitter)
|
2003-07-11 18:52:14 -04:00
|
|
|
{
|
2005-12-19 09:13:27 -05:00
|
|
|
struct emitter_xtra *bonus = (struct emitter_xtra *)emitter->bonus;
|
|
|
|
rb_gc_mark( bonus->oid );
|
|
|
|
rb_gc_mark( bonus->data );
|
|
|
|
rb_gc_mark( bonus->port );
|
2003-07-11 18:52:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* Free the emitter and any bonus attachment.
|
|
|
|
*/
|
|
|
|
void
|
2006-06-20 14:02:17 -04:00
|
|
|
rb_syck_free_emitter(SyckEmitter *e)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
2005-12-19 09:13:27 -05:00
|
|
|
S_FREE( e->bonus );
|
2005-09-12 23:58:33 -04:00
|
|
|
syck_free_emitter(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* YAML::Syck::Emitter.allocate
|
2003-07-11 18:52:14 -04:00
|
|
|
*/
|
2005-02-22 09:51:53 -05:00
|
|
|
VALUE syck_emitter_s_alloc _((VALUE));
|
2010-04-22 04:04:13 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_emitter_s_alloc(VALUE class)
|
2003-07-11 18:52:14 -04:00
|
|
|
{
|
2004-12-23 12:23:02 -05:00
|
|
|
VALUE pobj;
|
2003-07-11 18:52:14 -04:00
|
|
|
SyckEmitter *emitter = syck_new_emitter();
|
2004-06-29 13:34:08 -04:00
|
|
|
|
2005-12-19 09:13:27 -05:00
|
|
|
emitter->bonus = S_ALLOC( struct emitter_xtra );
|
|
|
|
S_MEMZERO( emitter->bonus, struct emitter_xtra, 1 );
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
pobj = Data_Wrap_Struct( class, syck_mark_emitter, rb_syck_free_emitter, emitter );
|
|
|
|
syck_emitter_handler( emitter, rb_syck_emitter_handler );
|
|
|
|
syck_output_handler( emitter, rb_syck_output_handler );
|
2003-07-11 18:52:14 -04:00
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_ivar_set( pobj, s_out, rb_funcall( cOut, s_new, 1, pobj ) );
|
2004-12-23 12:23:02 -05:00
|
|
|
return pobj;
|
2003-07-11 18:52:14 -04:00
|
|
|
}
|
|
|
|
|
2009-08-22 02:23:48 -04:00
|
|
|
static VALUE
|
|
|
|
id_hash_new(void)
|
|
|
|
{
|
|
|
|
VALUE hash;
|
|
|
|
hash = rb_hash_new();
|
|
|
|
rb_funcall(hash, rb_intern("compare_by_identity"), 0);
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2003-07-11 18:52:14 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Emitter.reset( options )
|
2003-07-11 18:52:14 -04:00
|
|
|
*/
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_emitter_reset(int argc, VALUE *argv, VALUE self)
|
2003-07-11 18:52:14 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE options, tmp;
|
|
|
|
SyckEmitter *emitter;
|
|
|
|
struct emitter_xtra *bonus;
|
|
|
|
|
|
|
|
Data_Get_Struct(self, SyckEmitter, emitter);
|
|
|
|
bonus = (struct emitter_xtra *)emitter->bonus;
|
|
|
|
|
2005-12-17 07:57:05 -05:00
|
|
|
bonus->oid = Qnil;
|
2005-09-12 23:58:33 -04:00
|
|
|
bonus->port = rb_str_new2( "" );
|
2009-08-22 00:52:09 -04:00
|
|
|
bonus->data = id_hash_new();
|
2004-12-23 12:23:02 -05:00
|
|
|
|
|
|
|
if (rb_scan_args(argc, argv, "01", &options) == 0)
|
|
|
|
{
|
|
|
|
options = rb_hash_new();
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_ivar_set(self, s_options, options);
|
2004-12-23 12:23:02 -05:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
else if ( !NIL_P(tmp = rb_check_string_type(options)) )
|
|
|
|
{
|
|
|
|
bonus->port = tmp;
|
|
|
|
}
|
|
|
|
else if ( rb_respond_to( options, s_write ) )
|
|
|
|
{
|
|
|
|
bonus->port = options;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-23 12:23:02 -05:00
|
|
|
Check_Type(options, T_HASH);
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_ivar_set(self, s_options, options);
|
2004-12-23 12:23:02 -05:00
|
|
|
}
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2005-12-19 23:25:48 -05:00
|
|
|
emitter->headless = 0;
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_ivar_set(self, s_level, INT2FIX(0));
|
|
|
|
rb_ivar_set(self, s_resolver, Qnil);
|
2004-12-23 12:23:02 -05:00
|
|
|
return self;
|
2003-07-11 18:52:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Emitter.emit( object_id ) { |out| ... }
|
2003-07-11 18:52:14 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_emitter_emit(int argc, VALUE *argv, VALUE self)
|
2003-07-11 18:52:14 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE oid, proc;
|
2003-07-11 18:52:14 -04:00
|
|
|
SyckEmitter *emitter;
|
2005-09-12 23:58:33 -04:00
|
|
|
struct emitter_xtra *bonus;
|
|
|
|
SYMID symple;
|
|
|
|
int level = FIX2INT(rb_ivar_get(self, s_level)) + 1;
|
|
|
|
rb_ivar_set(self, s_level, INT2FIX(level));
|
2003-07-11 18:52:14 -04:00
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_scan_args(argc, argv, "1&", &oid, &proc);
|
2004-12-23 12:23:02 -05:00
|
|
|
Data_Get_Struct(self, SyckEmitter, emitter);
|
2005-09-12 23:58:33 -04:00
|
|
|
bonus = (struct emitter_xtra *)emitter->bonus;
|
|
|
|
|
|
|
|
/* Calculate anchors, normalize nodes, build a simpler symbol table */
|
|
|
|
bonus->oid = oid;
|
|
|
|
if ( !NIL_P( oid ) && RTEST( rb_funcall( bonus->data, s_haskey, 1, oid ) ) ) {
|
|
|
|
symple = rb_hash_aref( bonus->data, oid );
|
|
|
|
} else {
|
|
|
|
symple = rb_funcall( proc, s_call, 1, rb_ivar_get( self, s_out ) );
|
|
|
|
}
|
|
|
|
syck_emitter_mark_node( emitter, (st_data_t)symple );
|
|
|
|
|
|
|
|
/* Second pass, build emitted string */
|
|
|
|
level -= 1;
|
|
|
|
rb_ivar_set(self, s_level, INT2FIX(level));
|
2010-04-22 04:04:13 -04:00
|
|
|
if ( level == 0 )
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
syck_emit(emitter, (st_data_t)symple);
|
|
|
|
syck_emitter_flush(emitter, 0);
|
|
|
|
|
|
|
|
return bonus->port;
|
|
|
|
}
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
return symple;
|
2003-07-11 18:52:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Emitter#node_export
|
2003-07-11 18:52:14 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_emitter_node_export(VALUE self, VALUE node)
|
2003-07-11 18:52:14 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
return rb_funcall( node, s_to_yaml, 1, self );
|
2003-07-11 18:52:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Emitter#set_resolver
|
2003-07-11 18:52:14 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_emitter_set_resolver(VALUE self, VALUE resolver)
|
2003-07-11 18:52:14 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_ivar_set( self, s_resolver, resolver );
|
2003-07-11 18:52:14 -04:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Out::initialize
|
2003-07-11 18:52:14 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_out_initialize(VALUE self, VALUE emitter)
|
2003-07-11 18:52:14 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_ivar_set( self, s_emitter, emitter );
|
2003-07-11 18:52:14 -04:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Out::map
|
2003-07-11 18:52:14 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_out_map(int argc, VALUE *argv, VALUE self)
|
2003-07-11 18:52:14 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE type_id, style, map;
|
|
|
|
if (rb_scan_args(argc, argv, "11", &type_id, &style) == 1) {
|
|
|
|
style = Qnil;
|
2003-07-11 18:52:14 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
map = rb_funcall( cMap, s_new, 3, type_id, rb_hash_new(), style );
|
|
|
|
syck_out_mark( rb_ivar_get( self, s_emitter ), map );
|
|
|
|
rb_yield( map );
|
|
|
|
return map;
|
2003-07-11 18:52:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* YAML::Syck::Out::seq
|
2003-07-11 18:52:14 -04:00
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_out_seq(int argc, VALUE *argv, VALUE self)
|
2003-07-11 18:52:14 -04:00
|
|
|
{
|
2005-09-12 23:58:33 -04:00
|
|
|
VALUE type_id, style, seq;
|
|
|
|
if (rb_scan_args(argc, argv, "11", &type_id, &style) == 1) {
|
|
|
|
style = Qnil;
|
|
|
|
}
|
|
|
|
seq = rb_funcall( cSeq, s_new, 3, type_id, rb_ary_new(), style );
|
|
|
|
syck_out_mark( rb_ivar_get( self, s_emitter ), seq );
|
|
|
|
rb_yield( seq );
|
|
|
|
return seq;
|
|
|
|
}
|
2003-07-11 18:52:14 -04:00
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
/*
|
|
|
|
* YAML::Syck::Out::scalar
|
|
|
|
syck_out_scalar( self, type_id, str, style )
|
|
|
|
VALUE self, type_id, str, style;
|
|
|
|
*/
|
|
|
|
VALUE
|
2006-06-20 14:02:17 -04:00
|
|
|
syck_out_scalar(int argc, VALUE *argv, VALUE self)
|
2005-09-12 23:58:33 -04:00
|
|
|
{
|
|
|
|
VALUE type_id, str, style, scalar;
|
2008-07-22 17:12:00 -04:00
|
|
|
rb_scan_args(argc, argv, "21", &type_id, &str, &style);
|
2005-09-12 23:58:33 -04:00
|
|
|
scalar = rb_funcall( cScalar, s_new, 3, type_id, str, style );
|
|
|
|
syck_out_mark( rb_ivar_get( self, s_emitter ), scalar );
|
|
|
|
return scalar;
|
2003-07-11 18:52:14 -04:00
|
|
|
}
|
|
|
|
|
2003-05-13 02:34:18 -04:00
|
|
|
/*
|
|
|
|
* Initialize Syck extension
|
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
void
|
|
|
|
Init_syck()
|
|
|
|
{
|
2010-04-03 17:50:47 -04:00
|
|
|
VALUE rb_syck = rb_define_module_under( rb_cObject, "Syck" );
|
2003-10-17 16:53:39 -04:00
|
|
|
rb_define_module_function( rb_syck, "compile", rb_syck_compile, 1 );
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2004-12-23 12:23:02 -05:00
|
|
|
/*
|
|
|
|
* Global symbols
|
|
|
|
*/
|
2003-06-17 12:55:54 -04:00
|
|
|
s_new = rb_intern("new");
|
2003-05-09 17:25:50 -04:00
|
|
|
s_utc = rb_intern("utc");
|
2003-05-15 03:38:10 -04:00
|
|
|
s_at = rb_intern("at");
|
|
|
|
s_to_f = rb_intern("to_f");
|
2003-11-25 14:51:38 -05:00
|
|
|
s_to_i = rb_intern("to_i");
|
2003-05-09 17:25:50 -04:00
|
|
|
s_read = rb_intern("read");
|
|
|
|
s_binmode = rb_intern("binmode");
|
2003-06-17 12:55:54 -04:00
|
|
|
s_transfer = rb_intern("transfer");
|
|
|
|
s_call = rb_intern("call");
|
2004-05-06 02:29:56 -04:00
|
|
|
s_cmp = rb_intern("<=>");
|
2005-09-12 23:58:33 -04:00
|
|
|
s_intern = rb_intern("intern");
|
2004-12-23 12:23:02 -05:00
|
|
|
s_update = rb_intern("update");
|
2005-09-12 23:58:33 -04:00
|
|
|
s_detect_implicit = rb_intern("detect_implicit");
|
2004-12-23 12:23:02 -05:00
|
|
|
s_dup = rb_intern("dup");
|
2003-10-03 15:51:25 -04:00
|
|
|
s_default_set = rb_intern("default=");
|
2004-12-23 12:23:02 -05:00
|
|
|
s_match = rb_intern("match");
|
2005-09-12 23:58:33 -04:00
|
|
|
s_push = rb_intern("push");
|
|
|
|
s_haskey = rb_intern("has_key?");
|
2004-12-23 12:23:02 -05:00
|
|
|
s_keys = rb_intern("keys");
|
2005-09-12 23:58:33 -04:00
|
|
|
s_node_import = rb_intern("node_import");
|
2004-12-23 12:23:02 -05:00
|
|
|
s_tr_bang = rb_intern("tr!");
|
2003-08-21 17:16:58 -04:00
|
|
|
s_unpack = rb_intern("unpack");
|
2005-09-12 23:58:33 -04:00
|
|
|
s_write = rb_intern("write");
|
|
|
|
s_tag_read_class = rb_intern( "yaml_tag_read_class" );
|
|
|
|
s_tag_subclasses = rb_intern( "yaml_tag_subclasses?" );
|
|
|
|
s_emitter = rb_intern( "emitter" );
|
|
|
|
s_set_resolver = rb_intern( "set_resolver" );
|
|
|
|
s_node_export = rb_intern( "node_export" );
|
|
|
|
s_to_yaml = rb_intern( "to_yaml" );
|
|
|
|
s_transform = rb_intern( "transform" );
|
|
|
|
s_yaml_new = rb_intern("yaml_new");
|
|
|
|
s_yaml_initialize = rb_intern("yaml_initialize");
|
2006-02-03 05:28:27 -05:00
|
|
|
s_each = rb_intern("each");
|
2008-11-19 03:49:51 -05:00
|
|
|
s_parse = rb_intern("parse");
|
2005-09-12 23:58:33 -04:00
|
|
|
|
|
|
|
s_tags = rb_intern("@tags");
|
2004-03-03 18:08:45 -05:00
|
|
|
s_name = rb_intern("@name");
|
|
|
|
s_options = rb_intern("@options");
|
2005-09-12 23:58:33 -04:00
|
|
|
s_kind = rb_intern("@kind");
|
2004-03-03 18:08:45 -05:00
|
|
|
s_type_id = rb_intern("@type_id");
|
2005-09-12 23:58:33 -04:00
|
|
|
s_type_id_set = rb_intern("type_id=");
|
|
|
|
s_resolver = rb_intern("@resolver");
|
|
|
|
s_level = rb_intern( "@level" );
|
|
|
|
s_style = rb_intern("@style");
|
|
|
|
s_style_set = rb_intern("style=");
|
2004-03-03 18:08:45 -05:00
|
|
|
s_value = rb_intern("@value");
|
2005-09-12 23:58:33 -04:00
|
|
|
s_value_set = rb_intern("value=");
|
|
|
|
s_out = rb_intern("@out");
|
|
|
|
s_input = rb_intern("@input");
|
2004-03-03 18:08:45 -05:00
|
|
|
|
2004-12-23 12:23:02 -05:00
|
|
|
sym_model = ID2SYM(rb_intern("Model"));
|
|
|
|
sym_generic = ID2SYM(rb_intern("Generic"));
|
2005-09-12 23:58:33 -04:00
|
|
|
sym_bytecode = ID2SYM(rb_intern("bytecode"));
|
2003-05-09 17:25:50 -04:00
|
|
|
sym_map = ID2SYM(rb_intern("map"));
|
|
|
|
sym_scalar = ID2SYM(rb_intern("scalar"));
|
|
|
|
sym_seq = ID2SYM(rb_intern("seq"));
|
2005-09-12 23:58:33 -04:00
|
|
|
sym_1quote = ID2SYM(rb_intern("quote1"));
|
|
|
|
sym_2quote = ID2SYM(rb_intern("quote2"));
|
|
|
|
sym_fold = ID2SYM(rb_intern("fold"));
|
|
|
|
sym_literal = ID2SYM(rb_intern("literal"));
|
|
|
|
sym_plain = ID2SYM(rb_intern("plain"));
|
|
|
|
sym_inline = ID2SYM(rb_intern("inline"));
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* Define YAML::Syck::Resolver class
|
2003-07-04 08:51:42 -04:00
|
|
|
*/
|
2005-09-12 23:58:33 -04:00
|
|
|
cResolver = rb_define_class_under( rb_syck, "Resolver", rb_cObject );
|
|
|
|
rb_define_attr( cResolver, "tags", 1, 1 );
|
|
|
|
rb_define_method( cResolver, "initialize", syck_resolver_initialize, 0 );
|
|
|
|
rb_define_method( cResolver, "add_type", syck_resolver_add_type, 2 );
|
|
|
|
rb_define_method( cResolver, "use_types_at", syck_resolver_use_types_at, 1 );
|
|
|
|
rb_define_method( cResolver, "detect_implicit", syck_resolver_detect_implicit, 1 );
|
|
|
|
rb_define_method( cResolver, "transfer", syck_resolver_transfer, 2 );
|
|
|
|
rb_define_method( cResolver, "node_import", syck_resolver_node_import, 1 );
|
|
|
|
rb_define_method( cResolver, "tagurize", syck_resolver_tagurize, 1 );
|
|
|
|
|
2005-12-16 03:56:09 -05:00
|
|
|
rb_global_variable( &oDefaultResolver );
|
2005-09-12 23:58:33 -04:00
|
|
|
oDefaultResolver = rb_funcall( cResolver, rb_intern( "new" ), 0 );
|
|
|
|
rb_define_singleton_method( oDefaultResolver, "node_import", syck_defaultresolver_node_import, 1 );
|
|
|
|
rb_define_singleton_method( oDefaultResolver, "detect_implicit", syck_defaultresolver_detect_implicit, 1 );
|
|
|
|
rb_define_const( rb_syck, "DefaultResolver", oDefaultResolver );
|
2005-12-16 03:56:09 -05:00
|
|
|
rb_global_variable( &oGenericResolver );
|
2005-09-12 23:58:33 -04:00
|
|
|
oGenericResolver = rb_funcall( cResolver, rb_intern( "new" ), 0 );
|
|
|
|
rb_define_singleton_method( oGenericResolver, "node_import", syck_genericresolver_node_import, 1 );
|
|
|
|
rb_define_const( rb_syck, "GenericResolver", oGenericResolver );
|
2003-05-10 15:55:18 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/*
|
|
|
|
* Define YAML::Syck::Parser class
|
|
|
|
*/
|
2003-05-10 15:55:18 -04:00
|
|
|
cParser = rb_define_class_under( rb_syck, "Parser", rb_cObject );
|
2003-05-09 17:25:50 -04:00
|
|
|
rb_define_attr( cParser, "options", 1, 1 );
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_define_attr( cParser, "resolver", 1, 1 );
|
|
|
|
rb_define_attr( cParser, "input", 1, 1 );
|
2004-12-23 12:23:02 -05:00
|
|
|
rb_define_alloc_func( cParser, syck_parser_s_alloc );
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_define_method(cParser, "initialize", syck_parser_initialize, -1 );
|
|
|
|
rb_define_method(cParser, "bufsize=", syck_parser_bufsize_set, 1 );
|
|
|
|
rb_define_method(cParser, "bufsize", syck_parser_bufsize_get, 0 );
|
2003-05-09 17:25:50 -04:00
|
|
|
rb_define_method(cParser, "load", syck_parser_load, -1);
|
|
|
|
rb_define_method(cParser, "load_documents", syck_parser_load_documents, -1);
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_define_method(cParser, "set_resolver", syck_parser_set_resolver, 1);
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/*
|
|
|
|
* Define YAML::Syck::Node class
|
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
cNode = rb_define_class_under( rb_syck, "Node", rb_cObject );
|
2011-02-04 22:05:35 -05:00
|
|
|
rb_undef( cNode, rb_intern("initialize_copy") );
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_define_attr( cNode, "emitter", 1, 1 );
|
|
|
|
rb_define_attr( cNode, "resolver", 1, 1 );
|
|
|
|
rb_define_attr( cNode, "kind", 1, 0 );
|
|
|
|
rb_define_attr( cNode, "type_id", 1, 0 );
|
|
|
|
rb_define_attr( cNode, "value", 1, 0 );
|
|
|
|
rb_define_method( cNode, "type_id=", syck_node_type_id_set, 1 );
|
2003-05-09 17:25:50 -04:00
|
|
|
rb_define_method( cNode, "transform", syck_node_transform, 0);
|
2003-06-17 12:55:54 -04:00
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* Define YAML::Syck::Scalar, YAML::Syck::Seq, YAML::Syck::Map --
|
|
|
|
* all are the publicly usable variants of YAML::Syck::Node
|
|
|
|
*/
|
|
|
|
cScalar = rb_define_class_under( rb_syck, "Scalar", cNode );
|
|
|
|
rb_define_alloc_func( cScalar, syck_scalar_alloc );
|
|
|
|
rb_define_method( cScalar, "initialize", syck_scalar_initialize, 3 );
|
|
|
|
rb_define_method( cScalar, "value=", syck_scalar_value_set, 1 );
|
|
|
|
rb_define_method( cScalar, "style=", syck_scalar_style_set, 1 );
|
|
|
|
cSeq = rb_define_class_under( rb_syck, "Seq", cNode );
|
|
|
|
rb_define_alloc_func( cSeq, syck_seq_alloc );
|
|
|
|
rb_define_method( cSeq, "initialize", syck_seq_initialize, 3 );
|
|
|
|
rb_define_method( cSeq, "value=", syck_seq_value_set, 1 );
|
|
|
|
rb_define_method( cSeq, "add", syck_seq_add_m, 1 );
|
|
|
|
rb_define_method( cSeq, "style=", syck_seq_style_set, 1 );
|
|
|
|
cMap = rb_define_class_under( rb_syck, "Map", cNode );
|
|
|
|
rb_define_alloc_func( cMap, syck_map_alloc );
|
|
|
|
rb_define_method( cMap, "initialize", syck_map_initialize, 3 );
|
|
|
|
rb_define_method( cMap, "value=", syck_map_value_set, 1 );
|
|
|
|
rb_define_method( cMap, "add", syck_map_add_m, 2 );
|
|
|
|
rb_define_method( cMap, "style=", syck_map_style_set, 1 );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define YAML::PrivateType class
|
2003-07-04 08:51:42 -04:00
|
|
|
*/
|
2010-04-03 17:50:47 -04:00
|
|
|
cPrivateType = rb_define_class_under( rb_syck, "PrivateType", rb_cObject );
|
2003-06-17 12:55:54 -04:00
|
|
|
rb_define_attr( cPrivateType, "type_id", 1, 1 );
|
|
|
|
rb_define_attr( cPrivateType, "value", 1, 1 );
|
|
|
|
rb_define_method( cPrivateType, "initialize", syck_privatetype_initialize, 2);
|
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/*
|
2005-09-12 23:58:33 -04:00
|
|
|
* Define YAML::DomainType class
|
2003-07-04 08:51:42 -04:00
|
|
|
*/
|
2010-04-03 17:50:47 -04:00
|
|
|
cDomainType = rb_define_class_under( rb_syck, "DomainType", rb_cObject );
|
2003-06-17 12:55:54 -04:00
|
|
|
rb_define_attr( cDomainType, "domain", 1, 1 );
|
|
|
|
rb_define_attr( cDomainType, "type_id", 1, 1 );
|
|
|
|
rb_define_attr( cDomainType, "value", 1, 1 );
|
|
|
|
rb_define_method( cDomainType, "initialize", syck_domaintype_initialize, 3);
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
/*
|
|
|
|
* Define YAML::Object class
|
|
|
|
*/
|
2010-04-03 17:50:47 -04:00
|
|
|
cYObject = rb_define_class_under( rb_syck, "Object", rb_cObject );
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_define_attr( cYObject, "class", 1, 1 );
|
|
|
|
rb_define_attr( cYObject, "ivars", 1, 1 );
|
|
|
|
rb_define_method( cYObject, "initialize", syck_yobject_initialize, 2);
|
|
|
|
rb_define_method( cYObject, "yaml_initialize", syck_yobject_initialize, 2);
|
|
|
|
|
2003-07-04 08:51:42 -04:00
|
|
|
/*
|
|
|
|
* Define YAML::Syck::BadAlias class
|
|
|
|
*/
|
2003-06-17 12:55:54 -04:00
|
|
|
cBadAlias = rb_define_class_under( rb_syck, "BadAlias", rb_cObject );
|
|
|
|
rb_define_attr( cBadAlias, "name", 1, 1 );
|
|
|
|
rb_define_method( cBadAlias, "initialize", syck_badalias_initialize, 1);
|
2004-05-06 02:29:56 -04:00
|
|
|
rb_define_method( cBadAlias, "<=>", syck_badalias_cmp, 1);
|
|
|
|
rb_include_module( cBadAlias, rb_const_get( rb_cObject, rb_intern("Comparable") ) );
|
2003-06-17 21:06:00 -04:00
|
|
|
|
2004-12-23 12:23:02 -05:00
|
|
|
/*
|
|
|
|
* Define YAML::Syck::MergeKey class
|
|
|
|
*/
|
|
|
|
cMergeKey = rb_define_class_under( rb_syck, "MergeKey", rb_cObject );
|
2003-07-11 18:52:14 -04:00
|
|
|
|
2004-12-23 12:23:02 -05:00
|
|
|
/*
|
|
|
|
* Define YAML::Syck::DefaultKey class
|
|
|
|
*/
|
|
|
|
cDefaultKey = rb_define_class_under( rb_syck, "DefaultKey", rb_cObject );
|
2003-10-03 15:51:25 -04:00
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
/*
|
|
|
|
* Define YAML::Syck::Out classes
|
|
|
|
*/
|
|
|
|
cOut = rb_define_class_under( rb_syck, "Out", rb_cObject );
|
|
|
|
rb_define_attr( cOut, "emitter", 1, 1 );
|
|
|
|
rb_define_method( cOut, "initialize", syck_out_initialize, 1 );
|
|
|
|
rb_define_method( cOut, "map", syck_out_map, -1 );
|
|
|
|
rb_define_method( cOut, "seq", syck_out_seq, -1 );
|
|
|
|
rb_define_method( cOut, "scalar", syck_out_scalar, -1 );
|
|
|
|
|
2003-07-11 18:52:14 -04:00
|
|
|
/*
|
|
|
|
* Define YAML::Syck::Emitter class
|
|
|
|
*/
|
|
|
|
cEmitter = rb_define_class_under( rb_syck, "Emitter", rb_cObject );
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_define_attr( cEmitter, "level", 1, 1 );
|
2004-12-23 12:23:02 -05:00
|
|
|
rb_define_alloc_func( cEmitter, syck_emitter_s_alloc );
|
2005-09-12 23:58:33 -04:00
|
|
|
rb_define_method( cEmitter, "initialize", syck_emitter_reset, -1 );
|
|
|
|
rb_define_method( cEmitter, "reset", syck_emitter_reset, -1 );
|
|
|
|
rb_define_method( cEmitter, "emit", syck_emitter_emit, -1 );
|
|
|
|
rb_define_method( cEmitter, "set_resolver", syck_emitter_set_resolver, 1);
|
|
|
|
rb_define_method( cEmitter, "node_export", syck_emitter_node_export, 1);
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|