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

* ext/syck/rubyext.c: refactoring of the transfer method

dispatch.  added yaml_org_handler for faster dispatch of
  transfers to base types.

* lib/yaml/rubytypes.rb: removed handling of builtins from
  Ruby library.

* ext/syck/token.c: quoted and block scalars are now implicit !str

* ext/syck/implicit.c: empty string detected as !null.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
why 2003-08-21 21:16:58 +00:00
parent 52e6a899ea
commit 7cca6c25f0
5 changed files with 989 additions and 941 deletions

View file

@ -1,3 +1,16 @@
Fri Aug 22 06:13:22 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
* ext/syck/rubyext.c: refactoring of the transfer method
dispatch. added yaml_org_handler for faster dispatch of
transfers to base types.
* lib/yaml/rubytypes.rb: removed handling of builtins from
Ruby library.
* ext/syck/token.c: quoted and block scalars are now implicit !str
* ext/syck/implicit.c: empty string detected as !null.
Fri Aug 22 01:00:31 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Aug 22 01:00:31 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (block_pass): improve passing current block. * eval.c (block_pass): improve passing current block.

File diff suppressed because it is too large Load diff

View file

@ -40,7 +40,7 @@ typedef struct RVALUE {
/* /*
* symbols and constants * symbols and constants
*/ */
static ID s_new, s_utc, s_at, s_to_f, s_read, s_binmode, s_call, s_transfer, s_update, s_dup, s_match; static ID s_new, s_utc, s_at, s_to_f, s_read, s_binmode, s_call, s_transfer, s_update, s_dup, s_match, s_keys, s_to_str, s_unpack, s_tr_bang;
static VALUE sym_model, sym_generic; static VALUE sym_model, sym_generic;
static VALUE sym_scalar, sym_seq, sym_map; static VALUE sym_scalar, sym_seq, sym_map;
VALUE cDate, cParser, cLoader, cNode, cPrivateType, cDomainType, cBadAlias, cMergeKey, cEmitter; VALUE cDate, cParser, cLoader, cNode, cPrivateType, cDomainType, cBadAlias, cMergeKey, cEmitter;
@ -112,7 +112,7 @@ syck_parser_assign_io(parser, port)
VALUE port; VALUE port;
{ {
int taint = Qtrue; int taint = Qtrue;
if (rb_respond_to(port, rb_intern("to_str"))) { if (rb_respond_to(port, s_to_str)) {
taint = OBJ_TAINTED(port); /* original taintedness */ taint = OBJ_TAINTED(port); /* original taintedness */
StringValue(port); /* possible conversion */ StringValue(port); /* possible conversion */
syck_parser_str( parser, RSTRING(port)->ptr, RSTRING(port)->len, NULL ); syck_parser_str( parser, RSTRING(port)->ptr, RSTRING(port)->len, NULL );
@ -306,79 +306,136 @@ syck_merge_i( entry, hsh )
} }
/* /*
* {native mode} node handler * build a syck node from a Ruby VALUE
* - Converts data into native Ruby types
*/ */
SYMID SyckNode *
rb_syck_load_handler(p, n) rb_new_syck_node( obj, type_id )
SyckParser *p; VALUE obj, type_id;
SyckNode *n;
{ {
VALUE obj = Qnil; long i = 0;
long i; SyckNode *n = NULL;
int check_transfers = 0;
struct parser_xtra *bonus;
if (rb_respond_to(obj, s_to_str))
{
StringValue(obj); /* possible conversion */
n = syck_alloc_str();
n->data.str->ptr = RSTRING(obj)->ptr;
n->data.str->len = RSTRING(obj)->len;
}
else if ( rb_obj_is_kind_of( obj, rb_cArray ) )
{
n = syck_alloc_seq();
for ( i = 0; i < RARRAY(obj)->len; i++ )
{
syck_seq_add(n, rb_ary_entry(obj, i));
}
}
else if ( rb_obj_is_kind_of( obj, rb_cHash ) )
{
VALUE keys;
n = syck_alloc_map();
keys = rb_funcall( obj, s_keys, 0 );
for ( i = 0; i < RARRAY(keys)->len; i++ )
{
VALUE key = rb_ary_entry(keys, i);
syck_map_add(n, key, rb_hash_aref(obj, key));
}
}
if ( n!= NULL && rb_respond_to( type_id, s_to_str ) )
{
StringValue(type_id);
n->type_id = syck_strndup( RSTRING(type_id)->ptr, RSTRING(type_id)->len );
}
return n;
}
/*
* default handler for ruby.yaml.org types
*/
int
yaml_org_handler( n, ref )
SyckNode *n;
VALUE *ref;
{
char *type_id = n->type_id;
int transferred = 0;
long i = 0;
VALUE obj = Qnil;
/*
* If prefixed with YAML_DOMAIN, skip to type name
*/
switch (n->kind) switch (n->kind)
{ {
case syck_str_kind: case syck_str_kind:
if ( n->type_id == NULL || strcmp( n->type_id, "str" ) == 0 ) transferred = 1;
if ( type_id == NULL || strcmp( type_id, "str" ) == 0 )
{ {
obj = rb_str_new( n->data.str->ptr, n->data.str->len ); obj = rb_str_new( n->data.str->ptr, n->data.str->len );
} }
else if ( strcmp( n->type_id, "null" ) == 0 ) else if ( strcmp( type_id, "null" ) == 0 )
{ {
obj = Qnil; obj = Qnil;
} }
else if ( strcmp( n->type_id, "bool#yes" ) == 0 ) 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 )
{ {
obj = Qtrue; obj = Qtrue;
} }
else if ( strcmp( n->type_id, "bool#no" ) == 0 ) else if ( strcmp( type_id, "bool#no" ) == 0 )
{ {
obj = Qfalse; obj = Qfalse;
} }
else if ( strcmp( n->type_id, "int#hex" ) == 0 ) else if ( strcmp( type_id, "int#hex" ) == 0 )
{ {
obj = rb_cstr2inum( n->data.str->ptr, 16 ); obj = rb_cstr2inum( n->data.str->ptr, 16 );
} }
else if ( strcmp( n->type_id, "int#oct" ) == 0 ) else if ( strcmp( type_id, "int#oct" ) == 0 )
{ {
obj = rb_cstr2inum( n->data.str->ptr, 8 ); obj = rb_cstr2inum( n->data.str->ptr, 8 );
} }
else if ( strncmp( n->type_id, "int", 3 ) == 0 ) else if ( strncmp( type_id, "int", 3 ) == 0 )
{ {
syck_str_blow_away_commas( n ); syck_str_blow_away_commas( n );
obj = rb_cstr2inum( n->data.str->ptr, 10 ); obj = rb_cstr2inum( n->data.str->ptr, 10 );
} }
else if ( strcmp( n->type_id, "float#nan" ) == 0 ) else if ( strcmp( type_id, "float#nan" ) == 0 )
{ {
obj = rb_float_new( S_nan() ); obj = rb_float_new( S_nan() );
} }
else if ( strcmp( n->type_id, "float#inf" ) == 0 ) else if ( strcmp( type_id, "float#inf" ) == 0 )
{ {
obj = rb_float_new( S_inf() ); obj = rb_float_new( S_inf() );
} }
else if ( strcmp( n->type_id, "float#neginf" ) == 0 ) else if ( strcmp( type_id, "float#neginf" ) == 0 )
{ {
obj = rb_float_new( -S_inf() ); obj = rb_float_new( -S_inf() );
} }
else if ( strncmp( n->type_id, "float", 5 ) == 0 ) else if ( strncmp( type_id, "float", 5 ) == 0 )
{ {
double f; double f;
syck_str_blow_away_commas( n ); syck_str_blow_away_commas( n );
f = strtod( n->data.str->ptr, NULL ); f = strtod( n->data.str->ptr, NULL );
obj = rb_float_new( f ); obj = rb_float_new( f );
} }
else if ( strcmp( n->type_id, "timestamp#iso8601" ) == 0 ) else if ( strcmp( type_id, "timestamp#iso8601" ) == 0 )
{ {
obj = rb_syck_mktime( n->data.str->ptr ); obj = rb_syck_mktime( n->data.str->ptr );
} }
else if ( strcmp( n->type_id, "timestamp#spaced" ) == 0 ) else if ( strcmp( type_id, "timestamp#spaced" ) == 0 )
{ {
obj = rb_syck_mktime( n->data.str->ptr ); obj = rb_syck_mktime( n->data.str->ptr );
} }
else if ( strcmp( n->type_id, "timestamp#ymd" ) == 0 ) else if ( strcmp( type_id, "timestamp#ymd" ) == 0 )
{ {
char *ptr = n->data.str->ptr; char *ptr = n->data.str->ptr;
VALUE year, mon, day; VALUE year, mon, day;
@ -399,17 +456,17 @@ rb_syck_load_handler(p, n)
obj = rb_funcall( cDate, s_new, 3, year, mon, day ); obj = rb_funcall( cDate, s_new, 3, year, mon, day );
} }
else if ( strncmp( n->type_id, "timestamp", 9 ) == 0 ) else if ( strncmp( type_id, "timestamp", 9 ) == 0 )
{ {
obj = rb_syck_mktime( n->data.str->ptr ); obj = rb_syck_mktime( n->data.str->ptr );
} }
else if ( strncmp( n->type_id, "merge", 5 ) == 0 ) else if ( strncmp( type_id, "merge", 5 ) == 0 )
{ {
obj = rb_funcall( cMergeKey, s_new, 0 ); obj = rb_funcall( cMergeKey, s_new, 0 );
} }
else else
{ {
check_transfers = 1; transferred = 0;
obj = rb_str_new( n->data.str->ptr, n->data.str->len ); obj = rb_str_new( n->data.str->ptr, n->data.str->len );
} }
break; break;
@ -420,7 +477,10 @@ rb_syck_load_handler(p, n)
{ {
rb_ary_store( obj, i, syck_seq_read( n, i ) ); rb_ary_store( obj, i, syck_seq_read( n, i ) );
} }
check_transfers = 1; if ( type_id == NULL || strcmp( type_id, "seq" ) == 0 )
{
transferred = 1;
}
break; break;
case syck_map_kind: case syck_map_kind:
@ -463,10 +523,38 @@ rb_syck_load_handler(p, n)
rb_hash_aset( obj, k, v ); rb_hash_aset( obj, k, v );
} }
} }
check_transfers = 1; if ( type_id == NULL || strcmp( type_id, "map" ) == 0 )
{
transferred = 1;
}
break; break;
} }
*ref = obj;
return transferred;
}
/*
* {native mode} node handler
* - Converts data into native Ruby types
*/
SYMID
rb_syck_load_handler(p, n)
SyckParser *p;
SyckNode *n;
{
VALUE obj = Qnil;
struct parser_xtra *bonus;
/*
* Attempt common transfers
*/
int transferred = yaml_org_handler(n, &obj);
if ( transferred == 0 && n->type_id != NULL )
{
obj = rb_funcall( oDefaultLoader, s_transfer, 2, rb_str_new2( n->type_id ), obj );
}
/* /*
* ID already set, let's alter the symbol table to accept the new object * ID already set, let's alter the symbol table to accept the new object
*/ */
@ -481,11 +569,6 @@ rb_syck_load_handler(p, n)
if ( bonus->taint) OBJ_TAINT( obj ); if ( bonus->taint) OBJ_TAINT( obj );
if ( bonus->proc != 0 ) rb_funcall(bonus->proc, s_call, 1, obj); if ( bonus->proc != 0 ) rb_funcall(bonus->proc, s_call, 1, obj);
if ( check_transfers == 1 && n->type_id != NULL )
{
obj = rb_funcall( oDefaultLoader, s_transfer, 2, rb_str_new2( n->type_id ), obj );
}
rb_hash_aset(bonus->data, INT2FIX(RHASH(bonus->data)->tbl->num_entries), obj); rb_hash_aset(bonus->data, INT2FIX(RHASH(bonus->data)->tbl->num_entries), obj);
return obj; return obj;
} }
@ -824,6 +907,7 @@ syck_loader_transfer( self, type, val )
*/ */
if ( TYPE(val) == T_STRING ) if ( TYPE(val) == T_STRING )
{ {
StringValue(val);
taguri = syck_match_implicit( RSTRING(val)->ptr, RSTRING(val)->len ); taguri = syck_match_implicit( RSTRING(val)->ptr, RSTRING(val)->len );
taguri = syck_taguri( YAML_DOMAIN, taguri, strlen( taguri ) ); taguri = syck_taguri( YAML_DOMAIN, taguri, strlen( taguri ) );
} }
@ -835,10 +919,12 @@ syck_loader_transfer( self, type, val )
if ( taguri != NULL ) if ( taguri != NULL )
{ {
int transferred = 0;
VALUE scheme, name, type_hash, domain = Qnil, type_proc = Qnil; VALUE scheme, name, type_hash, domain = Qnil, type_proc = Qnil;
VALUE type_uri = rb_str_new2( taguri ); VALUE type_uri = rb_str_new2( taguri );
VALUE str_taguri = rb_str_new2("taguri"); VALUE str_taguri = rb_str_new2("taguri");
VALUE str_xprivate = rb_str_new2("x-private"); VALUE str_xprivate = rb_str_new2("x-private");
VALUE str_yaml_domain = rb_str_new2(YAML_DOMAIN);
VALUE parts = rb_str_split( type_uri, ":" ); VALUE parts = rb_str_split( type_uri, ":" );
scheme = rb_ary_shift( parts ); scheme = rb_ary_shift( parts );
@ -854,6 +940,21 @@ syck_loader_transfer( self, type, val )
name = rb_ary_join( parts, rb_str_new2( ":" ) ); name = rb_ary_join( parts, rb_str_new2( ":" ) );
type_hash = rb_iv_get(self, "@families"); type_hash = rb_iv_get(self, "@families");
type_hash = rb_hash_aref(type_hash, domain); type_hash = rb_hash_aref(type_hash, domain);
/*
* Route yaml.org types through the transfer
* method here in this extension
*/
if ( rb_str_cmp( domain, str_yaml_domain ) == 0 )
{
SyckNode *n = rb_new_syck_node(val, name);
if ( n != NULL )
{
transferred = yaml_org_handler(n, &val);
S_FREE( n );
}
}
} }
else else
{ {
@ -861,30 +962,34 @@ syck_loader_transfer( self, type, val )
scheme); scheme);
} }
if ( rb_obj_is_instance_of( type_hash, rb_cHash ) ) if ( ! transferred )
{ {
type_proc = rb_hash_aref( type_hash, name ); if ( rb_obj_is_instance_of( type_hash, rb_cHash ) )
if ( NIL_P( type_proc ) )
{ {
VALUE col = rb_ary_new(); type_proc = rb_hash_aref( type_hash, name );
rb_ary_push( col, name ); if ( NIL_P( type_proc ) )
rb_iterate(rb_each, type_hash, transfer_find_i, col ); {
name = rb_ary_shift( col ); VALUE col = rb_ary_new();
type_proc = rb_ary_shift( col ); rb_ary_push( col, name );
rb_iterate(rb_each, type_hash, transfer_find_i, col );
name = rb_ary_shift( col );
type_proc = rb_ary_shift( col );
}
} }
}
if ( rb_respond_to( type_proc, s_call ) ) if ( rb_respond_to( type_proc, s_call ) )
{ {
val = rb_funcall(type_proc, s_call, 2, type_uri, val); val = rb_funcall(type_proc, s_call, 2, type_uri, val);
} }
else if ( rb_str_cmp( scheme, str_xprivate ) == 0 ) else if ( rb_str_cmp( scheme, str_xprivate ) == 0 )
{ {
val = rb_funcall(cPrivateType, s_new, 2, name, val); val = rb_funcall(cPrivateType, s_new, 2, name, val);
} }
else else
{ {
val = rb_funcall(cDomainType, s_new, 3, domain, name, val); val = rb_funcall(cDomainType, s_new, 3, domain, name, val);
}
transferred = 1;
} }
} }
@ -996,7 +1101,7 @@ rb_syck_output_handler( emitter, str, len )
long len; long len;
{ {
VALUE dest = (VALUE)emitter->bonus; VALUE dest = (VALUE)emitter->bonus;
if ( rb_respond_to( dest, rb_intern("to_str") ) ) { if ( rb_respond_to( dest, s_to_str ) ) {
rb_str_cat( dest, str, len ); rb_str_cat( dest, str, len );
} else { } else {
rb_io_write( dest, rb_str_new( str, len ) ); rb_io_write( dest, rb_str_new( str, len ) );
@ -1175,6 +1280,10 @@ Init_syck()
s_update = rb_intern("update"); s_update = rb_intern("update");
s_dup = rb_intern("dup"); s_dup = rb_intern("dup");
s_match = rb_intern("match"); s_match = rb_intern("match");
s_keys = rb_intern("keys");
s_to_str = rb_intern("to_str");
s_tr_bang = rb_intern("tr!");
s_unpack = rb_intern("unpack");
sym_model = ID2SYM(rb_intern("Model")); sym_model = ID2SYM(rb_intern("Model"));
sym_generic = ID2SYM(rb_intern("Generic")); sym_generic = ID2SYM(rb_intern("Generic"));

View file

@ -1,4 +1,4 @@
/* Generated by re2c 0.5 on Mon Jul 28 21:10:39 2003 */ /* Generated by re2c 0.5 on Thu Aug 21 14:28:35 2003 */
#line 1 "token.re" #line 1 "token.re"
/* /*
* token.re * token.re
@ -137,6 +137,7 @@
#define RETURN_YAML_BLOCK() \ #define RETURN_YAML_BLOCK() \
{ \ { \
SyckNode *n = syck_alloc_str(); \ SyckNode *n = syck_alloc_str(); \
n->type_id = syck_strndup( "str", 3 ); \
n->data.str->ptr = qstr; \ n->data.str->ptr = qstr; \
n->data.str->len = qidx; \ n->data.str->len = qidx; \
if ( qidx > 0 ) \ if ( qidx > 0 ) \
@ -228,7 +229,7 @@ sycklex( YYSTYPE *sycklval, SyckParser *parser )
return t; return t;
} }
#line 246 #line 247
if ( YYLINEPTR != YYCURSOR ) if ( YYLINEPTR != YYCURSOR )
@ -264,7 +265,7 @@ yy2: yyaccept = 0;
default: goto yy3; default: goto yy3;
} }
yy3: yy3:
#line 302 #line 303
{ YYPOS(0); { YYPOS(0);
goto Document; goto Document;
} }
@ -276,13 +277,13 @@ yy4: yyaccept = 0;
} }
yy5: yych = *++YYCURSOR; yy5: yych = *++YYCURSOR;
yy6: yy6:
#line 287 #line 288
{ eat_comments( parser ); { eat_comments( parser );
goto Header; goto Header;
} }
yy7: yych = *++YYCURSOR; yy7: yych = *++YYCURSOR;
yy8: yy8:
#line 291 #line 292
{ SyckLevel *lvl = CURRENT_LEVEL(); { SyckLevel *lvl = CURRENT_LEVEL();
ENSURE_YAML_IEND(lvl, -1); ENSURE_YAML_IEND(lvl, -1);
YYPOS(0); YYPOS(0);
@ -292,7 +293,7 @@ yy9: yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
goto yy14; goto yy14;
yy10: yy10:
#line 297 #line 298
{ int indt_len; { int indt_len;
GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN ); GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN );
goto Header; goto Header;
@ -339,7 +340,7 @@ yy18: yych = *++YYCURSOR;
} }
yy19: yych = *++YYCURSOR; yy19: yych = *++YYCURSOR;
yy20: yy20:
#line 273 #line 274
{ SyckLevel *lvl = CURRENT_LEVEL(); { SyckLevel *lvl = CURRENT_LEVEL();
if ( lvl->status == syck_lvl_header ) if ( lvl->status == syck_lvl_header )
{ {
@ -379,7 +380,7 @@ yy25: yych = *++YYCURSOR;
} }
yy26: yych = *++YYCURSOR; yy26: yych = *++YYCURSOR;
yy27: yy27:
#line 259 #line 260
{ SyckLevel *lvl = CURRENT_LEVEL(); { SyckLevel *lvl = CURRENT_LEVEL();
if ( lvl->status == syck_lvl_header ) if ( lvl->status == syck_lvl_header )
{ {
@ -406,7 +407,7 @@ yy30: yych = *++YYCURSOR;
default: goto yy16; default: goto yy16;
} }
} }
#line 306 #line 307
Document: Document:
@ -449,7 +450,7 @@ yy33: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
goto yy86; goto yy86;
yy34: yy34:
#line 320 #line 321
{ /* Isolate spaces */ { /* Isolate spaces */
int indt_len; int indt_len;
GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN ); GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN );
@ -470,13 +471,13 @@ yy35: yych = *++YYCURSOR;
default: goto yy36; default: goto yy36;
} }
yy36: yy36:
#line 407 #line 408
{ ENSURE_YAML_IOPEN(lvl, 0, 1); { ENSURE_YAML_IOPEN(lvl, 0, 1);
goto Plain; goto Plain;
} }
yy37: yych = *++YYCURSOR; yy37: yych = *++YYCURSOR;
yy38: yy38:
#line 335 #line 336
{ ENSURE_YAML_IOPEN(lvl, 0, 1); { ENSURE_YAML_IOPEN(lvl, 0, 1);
lvl = CURRENT_LEVEL(); lvl = CURRENT_LEVEL();
ADD_LEVEL(lvl->spaces + 1, syck_lvl_inline); ADD_LEVEL(lvl->spaces + 1, syck_lvl_inline);
@ -484,7 +485,7 @@ yy38:
} }
yy39: yych = *++YYCURSOR; yy39: yych = *++YYCURSOR;
yy40: yy40:
#line 341 #line 342
{ POP_LEVEL(); { POP_LEVEL();
return YYTOKEN[0]; return YYTOKEN[0];
} }
@ -634,17 +635,17 @@ yy44: yych = *++YYCURSOR;
} }
yy45: yych = *++YYCURSOR; yy45: yych = *++YYCURSOR;
yy46: yy46:
#line 380 #line 381
{ ENSURE_YAML_IOPEN(lvl, 0, 1); { ENSURE_YAML_IOPEN(lvl, 0, 1);
goto TransferMethod; } goto TransferMethod; }
yy47: yych = *++YYCURSOR; yy47: yych = *++YYCURSOR;
yy48: yy48:
#line 383 #line 384
{ ENSURE_YAML_IOPEN(lvl, 0, 1); { ENSURE_YAML_IOPEN(lvl, 0, 1);
goto SingleQuote; } goto SingleQuote; }
yy49: yych = *++YYCURSOR; yy49: yych = *++YYCURSOR;
yy50: yy50:
#line 386 #line 387
{ ENSURE_YAML_IOPEN(lvl, 0, 1); { ENSURE_YAML_IOPEN(lvl, 0, 1);
goto DoubleQuote; } goto DoubleQuote; }
yy51: yyaccept = 1; yy51: yyaccept = 1;
@ -667,18 +668,18 @@ yy51: yyaccept = 1;
} }
yy52: yych = *++YYCURSOR; yy52: yych = *++YYCURSOR;
yy53: yy53:
#line 396 #line 397
{ eat_comments( parser ); { eat_comments( parser );
goto Document; goto Document;
} }
yy54: yych = *++YYCURSOR; yy54: yych = *++YYCURSOR;
goto yy60; goto yy60;
yy55: yy55:
#line 400 #line 401
{ goto Document; } { goto Document; }
yy56: yych = *++YYCURSOR; yy56: yych = *++YYCURSOR;
yy57: yy57:
#line 402 #line 403
{ ENSURE_YAML_IEND(lvl, -1); { ENSURE_YAML_IEND(lvl, -1);
YYPOS(0); YYPOS(0);
return 0; return 0;
@ -718,7 +719,7 @@ yy63: YYCURSOR = YYMARKER;
} }
yy64: yych = *++YYCURSOR; yy64: yych = *++YYCURSOR;
yy65: yy65:
#line 389 #line 390
{ if ( is_newline( YYCURSOR - 1 ) ) { if ( is_newline( YYCURSOR - 1 ) )
{ {
YYCURSOR--; YYCURSOR--;
@ -804,7 +805,7 @@ yy70: switch(yych){
default: goto yy71; default: goto yy71;
} }
yy71: yy71:
#line 375 #line 376
{ ENSURE_YAML_IOPEN(lvl, 0, 1); { ENSURE_YAML_IOPEN(lvl, 0, 1);
sycklval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 ); sycklval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 );
return YAML_ALIAS; return YAML_ALIAS;
@ -876,7 +877,7 @@ yy73: switch(yych){
default: goto yy74; default: goto yy74;
} }
yy74: yy74:
#line 363 #line 364
{ ENSURE_YAML_IOPEN(lvl, 0, 1); { ENSURE_YAML_IOPEN(lvl, 0, 1);
sycklval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 ); sycklval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 );
@ -890,7 +891,7 @@ yy74:
} }
yy75: yych = *++YYCURSOR; yy75: yych = *++YYCURSOR;
yy76: yy76:
#line 349 #line 350
{ ENSURE_YAML_IOPEN(lvl, YYTOKEN - YYLINEPTR, 1); { ENSURE_YAML_IOPEN(lvl, YYTOKEN - YYLINEPTR, 1);
FORCE_NEXT_TOKEN(YAML_IOPEN); FORCE_NEXT_TOKEN(YAML_IOPEN);
if ( is_newline( YYCURSOR ) || is_newline( YYCURSOR - 1 ) ) if ( is_newline( YYCURSOR ) || is_newline( YYCURSOR - 1 ) )
@ -918,7 +919,7 @@ yy79: yych = *++YYCURSOR;
} }
yy80: yych = *++YYCURSOR; yy80: yych = *++YYCURSOR;
yy81: yy81:
#line 345 #line 346
{ YYPOS(1); { YYPOS(1);
return YYTOKEN[0]; return YYTOKEN[0];
} }
@ -951,7 +952,7 @@ yy87: ++YYCURSOR;
default: goto yy63; default: goto yy63;
} }
} }
#line 411 #line 412
} }
@ -1058,14 +1059,14 @@ yy91: yyaccept = 0;
default: goto yy92; default: goto yy92;
} }
yy92: yy92:
#line 424 #line 425
{ YYCURSOR = YYTOKTMP; { YYCURSOR = YYTOKTMP;
return YAML_DOCSEP; return YAML_DOCSEP;
} }
yy93: yych = *++YYCURSOR; yy93: yych = *++YYCURSOR;
goto yy97; goto yy97;
yy94: yy94:
#line 422 #line 423
{ goto Directive; } { goto Directive; }
yy95: yych = *++YYCURSOR; yy95: yych = *++YYCURSOR;
goto yy92; goto yy92;
@ -1317,10 +1318,10 @@ yy102: switch(yych){
default: goto yy103; default: goto yy103;
} }
yy103: yy103:
#line 420 #line 421
{ goto Directive; } { goto Directive; }
} }
#line 427 #line 428
} }
@ -1364,7 +1365,7 @@ yy106: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
goto yy132; goto yy132;
yy107: yy107:
#line 450 #line 451
{ int indt_len, nl_count = 0; { int indt_len, nl_count = 0;
SyckLevel *lvl; SyckLevel *lvl;
char *tok = YYTOKTMP; char *tok = YYTOKTMP;
@ -1402,7 +1403,7 @@ yy108: yych = *++YYCURSOR;
default: goto yy109; default: goto yy109;
} }
yy109: yy109:
#line 504 #line 505
{ QUOTECATS(qstr, qcapa, qidx, YYTOKTMP, YYCURSOR - YYTOKTMP); { QUOTECATS(qstr, qcapa, qidx, YYTOKTMP, YYCURSOR - YYTOKTMP);
goto Plain2; goto Plain2;
} }
@ -1416,7 +1417,7 @@ yy110: yyaccept = 1;
} }
yy111: yych = *++YYCURSOR; yy111: yych = *++YYCURSOR;
yy112: yy112:
#line 484 #line 485
{ if ( plvl->status != syck_lvl_inline ) { if ( plvl->status != syck_lvl_inline )
{ {
if ( *(YYCURSOR - 1) == ' ' || is_newline( YYCURSOR - 1 ) ) if ( *(YYCURSOR - 1) == ' ' || is_newline( YYCURSOR - 1 ) )
@ -1442,17 +1443,17 @@ yy114: yych = *++YYCURSOR;
default: goto yy115; default: goto yy115;
} }
yy115: yy115:
#line 502 #line 503
{ goto Plain3; } { goto Plain3; }
yy116: yych = *++YYCURSOR; yy116: yych = *++YYCURSOR;
yy117: yy117:
#line 500 #line 501
{ RETURN_IMPLICIT(); } { RETURN_IMPLICIT(); }
yy118: yych = *++YYCURSOR; yy118: yych = *++YYCURSOR;
goto yy109; goto yy109;
yy119: yych = *++YYCURSOR; yy119: yych = *++YYCURSOR;
yy120: yy120:
#line 496 #line 497
{ eat_comments( parser ); { eat_comments( parser );
RETURN_IMPLICIT(); RETURN_IMPLICIT();
} }
@ -1477,7 +1478,7 @@ yy125: YYCURSOR = YYMARKER;
} }
yy126: yych = *++YYCURSOR; yy126: yych = *++YYCURSOR;
yy127: yy127:
#line 482 #line 483
{ RETURN_IMPLICIT(); } { RETURN_IMPLICIT(); }
yy128: ++YYCURSOR; yy128: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1); if(YYLIMIT == YYCURSOR) YYFILL(1);
@ -1508,7 +1509,7 @@ yy133: ++YYCURSOR;
default: goto yy125; default: goto yy125;
} }
} }
#line 508 #line 509
} }
@ -1540,7 +1541,7 @@ yy136: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
goto yy147; goto yy147;
yy137: yy137:
#line 522 #line 523
{ int indt_len; { int indt_len;
int nl_count = 0; int nl_count = 0;
SyckLevel *lvl; SyckLevel *lvl;
@ -1582,7 +1583,7 @@ yy138: yych = *++YYCURSOR;
default: goto yy139; default: goto yy139;
} }
yy139: yy139:
#line 576 #line 578
{ QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1)); { QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
goto SingleQuote2; goto SingleQuote2;
} }
@ -1592,7 +1593,7 @@ yy140: yych = *++YYCURSOR;
default: goto yy141; default: goto yy141;
} }
yy141: yy141:
#line 562 #line 563
{ SyckLevel *lvl; { SyckLevel *lvl;
SyckNode *n = syck_alloc_str(); SyckNode *n = syck_alloc_str();
lvl = CURRENT_LEVEL(); lvl = CURRENT_LEVEL();
@ -1601,6 +1602,7 @@ yy141:
{ {
POP_LEVEL(); POP_LEVEL();
} }
n->type_id = syck_strndup( "str", 3 );
n->data.str->ptr = qstr; n->data.str->ptr = qstr;
n->data.str->len = qidx; n->data.str->len = qidx;
sycklval->nodeData = n; sycklval->nodeData = n;
@ -1612,7 +1614,7 @@ yy143: yych = *++YYCURSOR;
goto yy139; goto yy139;
yy144: yych = *++YYCURSOR; yy144: yych = *++YYCURSOR;
yy145: yy145:
#line 558 #line 559
{ QUOTECAT(qstr, qcapa, qidx, '\''); { QUOTECAT(qstr, qcapa, qidx, '\'');
goto SingleQuote2; goto SingleQuote2;
} }
@ -1637,7 +1639,7 @@ yy149: YYCURSOR = YYMARKER;
case 0: goto yy137; case 0: goto yy137;
} }
} }
#line 580 #line 582
} }
@ -1674,7 +1676,7 @@ yy152: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
goto yy174; goto yy174;
yy153: yy153:
#line 598 #line 600
{ int indt_len; { int indt_len;
int nl_count = 0; int nl_count = 0;
SyckLevel *lvl; SyckLevel *lvl;
@ -1720,7 +1722,7 @@ yy154: yych = *++YYCURSOR;
default: goto yy155; default: goto yy155;
} }
yy155: yy155:
#line 682 #line 685
{ QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1)); { QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
goto DoubleQuote2; goto DoubleQuote2;
} }
@ -1738,7 +1740,7 @@ yy156: yyaccept = 1;
} }
yy157: yych = *++YYCURSOR; yy157: yych = *++YYCURSOR;
yy158: yy158:
#line 668 #line 670
{ SyckLevel *lvl; { SyckLevel *lvl;
SyckNode *n = syck_alloc_str(); SyckNode *n = syck_alloc_str();
lvl = CURRENT_LEVEL(); lvl = CURRENT_LEVEL();
@ -1747,6 +1749,7 @@ yy158:
{ {
POP_LEVEL(); POP_LEVEL();
} }
n->type_id = syck_strndup( "str", 3 );
n->data.str->ptr = qstr; n->data.str->ptr = qstr;
n->data.str->len = qidx; n->data.str->len = qidx;
sycklval->nodeData = n; sycklval->nodeData = n;
@ -1772,7 +1775,7 @@ yy163: YYCURSOR = YYMARKER;
} }
yy164: yych = *++YYCURSOR; yy164: yych = *++YYCURSOR;
yy165: yy165:
#line 663 #line 665
{ keep_nl = 0; { keep_nl = 0;
YYCURSOR--; YYCURSOR--;
goto DoubleQuote2; goto DoubleQuote2;
@ -1808,7 +1811,7 @@ yy167: yych = *++YYCURSOR;
} }
yy168: yych = *++YYCURSOR; yy168: yych = *++YYCURSOR;
yy169: yy169:
#line 638 #line 640
{ char ch = *( YYCURSOR - 1 ); { char ch = *( YYCURSOR - 1 );
switch ( ch ) switch ( ch )
{ {
@ -1850,7 +1853,7 @@ yy170: yych = *++YYCURSOR;
} }
yy171: yych = *++YYCURSOR; yy171: yych = *++YYCURSOR;
yy172: yy172:
#line 654 #line 656
{ long ch; { long ch;
char *chr_text = syck_strndup( YYTOKTMP, 4 ); char *chr_text = syck_strndup( YYTOKTMP, 4 );
chr_text[0] = '0'; chr_text[0] = '0';
@ -1876,7 +1879,7 @@ yy175: ++YYCURSOR;
default: goto yy163; default: goto yy163;
} }
} }
#line 686 #line 689
} }
@ -1911,7 +1914,7 @@ yy178: YYCURSOR = YYMARKER;
} }
yy179: yych = *++YYCURSOR; yy179: yych = *++YYCURSOR;
yy180: yy180:
#line 700 #line 703
{ SyckLevel *lvl; { SyckLevel *lvl;
YYCURSOR = YYTOKTMP; YYCURSOR = YYTOKTMP;
if ( YYCURSOR == YYTOKEN + 1 ) if ( YYCURSOR == YYTOKEN + 1 )
@ -1969,7 +1972,7 @@ yy182: yych = *++YYCURSOR;
default: goto yy183; default: goto yy183;
} }
yy183: yy183:
#line 762 #line 765
{ QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1)); { QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
goto TransferMethod2; goto TransferMethod2;
} }
@ -2031,7 +2034,7 @@ yy187: yych = *++YYCURSOR;
} }
yy188: yych = *++YYCURSOR; yy188: yych = *++YYCURSOR;
yy189: yy189:
#line 753 #line 756
{ long ch; { long ch;
char *chr_text = syck_strndup( YYTOKTMP, 4 ); char *chr_text = syck_strndup( YYTOKTMP, 4 );
chr_text[0] = '0'; chr_text[0] = '0';
@ -2050,7 +2053,7 @@ yy192: switch(yych){
default: goto yy180; default: goto yy180;
} }
} }
#line 767 #line 770
} }
@ -2115,7 +2118,7 @@ yy195: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR); yych = *(YYMARKER = ++YYCURSOR);
goto yy205; goto yy205;
yy196: yy196:
#line 814 #line 817
{ char *pacer; { char *pacer;
char *tok = YYTOKTMP; char *tok = YYTOKTMP;
int indt_len = 0, nl_count = 0, fold_nl = 0, nl_begin = 0; int indt_len = 0, nl_count = 0, fold_nl = 0, nl_begin = 0;
@ -2187,13 +2190,13 @@ yy197: yych = *++YYCURSOR;
default: goto yy198; default: goto yy198;
} }
yy198: yy198:
#line 900 #line 903
{ QUOTECAT(qstr, qcapa, qidx, *YYTOKTMP); { QUOTECAT(qstr, qcapa, qidx, *YYTOKTMP);
goto ScalarBlock2; goto ScalarBlock2;
} }
yy199: yych = *++YYCURSOR; yy199: yych = *++YYCURSOR;
yy200: yy200:
#line 881 #line 884
{ lvl = CURRENT_LEVEL(); { lvl = CURRENT_LEVEL();
if ( lvl->status != syck_lvl_block ) if ( lvl->status != syck_lvl_block )
{ {
@ -2208,7 +2211,7 @@ yy200:
} }
yy201: yych = *++YYCURSOR; yy201: yych = *++YYCURSOR;
yy202: yy202:
#line 895 #line 898
{ YYCURSOR--; { YYCURSOR--;
POP_LEVEL(); POP_LEVEL();
RETURN_YAML_BLOCK(); RETURN_YAML_BLOCK();
@ -2236,7 +2239,7 @@ yy207: YYCURSOR = YYMARKER;
case 0: goto yy196; case 0: goto yy196;
} }
} }
#line 905 #line 908
} }
@ -2269,7 +2272,7 @@ yy208:
} }
yy210: yych = *++YYCURSOR; yy210: yych = *++YYCURSOR;
yy211: yy211:
#line 923 #line 926
{ YYCURSOR = tok; { YYCURSOR = tok;
return; return;
} }
@ -2282,7 +2285,7 @@ yy213: yych = *++YYCURSOR;
default: goto yy214; default: goto yy214;
} }
yy214: yy214:
#line 927 #line 930
{ goto Comment; { goto Comment;
} }
yy215: yych = *++YYCURSOR; yy215: yych = *++YYCURSOR;
@ -2308,7 +2311,7 @@ yy219: YYCURSOR = YYMARKER;
case 0: goto yy211; case 0: goto yy211;
} }
} }
#line 930 #line 933
} }

View file

@ -85,7 +85,6 @@ hash_proc = Proc.new { |type, val|
end end
val val
} }
YAML.add_builtin_type( 'map', &hash_proc )
YAML.add_ruby_type( /^hash/, &hash_proc ) YAML.add_ruby_type( /^hash/, &hash_proc )
module YAML module YAML
@ -237,7 +236,6 @@ array_proc = Proc.new { |type, val|
val.to_a val.to_a
end end
} }
YAML.add_builtin_type( 'seq', &array_proc )
YAML.add_ruby_type( /^array/, &array_proc ) YAML.add_ruby_type( /^array/, &array_proc )
# #
@ -319,16 +317,6 @@ class String
end end
end end
YAML.add_builtin_type( 'str' ) { |type,val| val.to_s }
YAML.add_builtin_type( 'binary' ) { |type,val|
enctype = "m"
if String === val
val.gsub( /\s+/, '' ).unpack( enctype )[0]
else
raise YAML::Error, "Binary data must be represented by a string: " + val.inspect
end
}
# #
# Symbol#to_yaml # Symbol#to_yaml
# #
@ -451,14 +439,6 @@ class Time
end end
end end
YAML.add_builtin_type( 'time#ymd' ) { |type, val|
if val =~ /\A(\d{4})\-(\d{1,2})\-(\d{1,2})\Z/
Date.new($1.to_i, $2.to_i, $3.to_i)
else
raise YAML::TypeError, "Invalid !time string: " + val.inspect
end
}
# #
# Emit a Date object as a simple implicit # Emit a Date object as a simple implicit
# #
@ -493,40 +473,6 @@ class Numeric
end end
end end
YAML.add_builtin_type( 'float' ) { |type, val|
if val =~ /\A[-+]?[\d][\d,]*\.[\d,]*[eE][-+][0-9]+\Z/ # Float (exponential)
$&.tr( ',', '' ).to_f
elsif val =~ /\A[-+]?[\d][\d,]*\.[\d,]*\Z/ # Float (fixed)
$&.tr( ',', '' ).to_f
elsif val =~ /\A([-+]?)\.(inf|Inf|INF)\Z/ # Float (english)
( $1 == "-" ? -1.0/0.0 : 1.0/0.0 )
elsif val =~ /\A\.(nan|NaN|NAN)\Z/
0.0/0.0
elsif type == :Implicit
:InvalidType
else
val.to_f
end
}
YAML.add_builtin_type( 'int' ) { |type, val|
if val =~ /\A[-+]?0[0-7,]+\Z/ # Integer (octal)
$&.oct
elsif val =~ /\A[-+]?0x[0-9a-fA-F,]+\Z/ # Integer (hex)
$&.hex
elsif val =~ /\A[-+]?\d[\d,]*\Z/ # Integer (canonical)
$&.tr( ',', '' ).to_i
elsif val =~ /\A([-+]?)(\d[\d,]*(?::[0-5]?[0-9])+)\Z/
sign = ( $1 == '-' ? -1 : 1 )
digits = $2.split( /:/ ).collect { |x| x.to_i }
val = 0; digits.each { |x| val = ( val * 60 ) + x }; val *= sign
elsif type == :Implicit
:InvalidType
else
val.to_i
end
}
class TrueClass class TrueClass
def is_complex_yaml? def is_complex_yaml?
false false
@ -547,18 +493,6 @@ class FalseClass
end end
end end
YAML.add_builtin_type( 'bool' ) { |type, val|
if val =~ /\A(\+|true|True|TRUE|yes|Yes|YES|on|On|ON)\Z/
true
elsif val =~ /\A(\-|false|False|FALSE|no|No|NO|off|Off|OFF)\Z/
false
elsif type == :Implicit
:InvalidType
else
raise YAML::TypeError, "Invalid !bool string: " + val.inspect
end
}
class NilClass class NilClass
def is_complex_yaml? def is_complex_yaml?
false false
@ -569,15 +503,3 @@ class NilClass
end end
end end
YAML.add_builtin_type( 'null' ) { |type, val|
if val =~ /\A(\~|null|Null|NULL)\Z/
nil
elsif val.empty?
nil
elsif type == :Implicit
:InvalidType
else
raise YAML::TypeError, "Invalid !null string: " + val.inspect
end
}