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

* lib/yaml/rubytypes.rb: remove comments that are bungling up

the rdoc and ri output.  output symbols as plain scalars.

* ext/syck/rubyext.c (syck_emitter_reset): emit headless
  documents always.

* ext/syck/emitter.c (syck_scan_scalar): quote scalars with any
  kind of surrounding line space, tabs or spaces alike.

* ext/syck/token.c: accept tabs as whitespace, not for indentation,
  but strip from plain scalars.

* test/yaml/test_yaml.rb: remove outdated tests.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
why 2005-09-17 17:22:49 +00:00
parent 17f4f5f507
commit f3d9f34537
7 changed files with 583 additions and 610 deletions

View file

@ -1,3 +1,19 @@
Sun Sep 18 02:10:47 2005 why the lucky stiff <why@ruby-lang.org>
* lib/yaml/rubytypes.rb: remove comments that are bungling up
the rdoc and ri output. output symbols as plain scalars.
* ext/syck/rubyext.c (syck_emitter_reset): emit headless
documents always.
* ext/syck/emitter.c (syck_scan_scalar): quote scalars with any
kind of surrounding line space, tabs or spaces alike.
* ext/syck/token.c: accept tabs as whitespace, not for indentation,
but strip from plain scalars.
* test/yaml/test_yaml.rb: remove outdated tests.
Sun Sep 18 01:10:37 2005 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun Sep 18 01:10:37 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_join): convert components by to_s instead of to_str. * file.c (rb_file_join): convert components by to_s instead of to_str.

View file

@ -338,27 +338,6 @@ syck_emitter_flush( SyckEmitter *e, long check_room )
check_room = e->bufsize; check_room = e->bufsize;
} }
/*
* Determine headers.
*/
if ( ( e->stage == doc_open && ( e->headless == 0 || e->use_header == 1 ) ) ||
e->stage == doc_need_header )
{
if ( e->use_version == 1 )
{
char *header = S_ALLOC_N( char, 64 );
S_MEMZERO( header, char, 64 );
sprintf( header, "--- %%YAML:%d.%d ", SYCK_YAML_MAJOR, SYCK_YAML_MINOR );
(e->output_handler)( e, header, strlen( header ) );
S_FREE( header );
}
else
{
(e->output_handler)( e, "--- ", 4 );
}
e->stage = doc_processing;
}
/* /*
* Commit buffer. * Commit buffer.
*/ */
@ -383,6 +362,26 @@ syck_emit( SyckEmitter *e, st_data_t n )
int indent = 0, x = 0; int indent = 0, x = 0;
SyckLevel *lvl = syck_emitter_current_level( e ); SyckLevel *lvl = syck_emitter_current_level( e );
/*
* Determine headers.
*/
if ( e->stage == doc_open && ( e->headless == 0 || e->use_header == 1 ) )
{
if ( e->use_version == 1 )
{
char *header = S_ALLOC_N( char, 64 );
S_MEMZERO( header, char, 64 );
sprintf( header, "--- %%YAML:%d.%d ", SYCK_YAML_MAJOR, SYCK_YAML_MINOR );
syck_emitter_write( e, header, strlen( header ) );
S_FREE( header );
}
else
{
syck_emitter_write( e, "--- ", 4 );
}
e->stage = doc_processing;
}
/* Add new level */ /* Add new level */
if ( lvl->spaces >= 0 ) { if ( lvl->spaces >= 0 ) {
indent = lvl->spaces + e->indent; indent = lvl->spaces + e->indent;
@ -429,6 +428,7 @@ end_emit:
syck_emitter_pop_level( e ); syck_emitter_pop_level( e );
if ( e->lvl_idx == 1 ) { if ( e->lvl_idx == 1 ) {
syck_emitter_write( e, "\n", 1 ); syck_emitter_write( e, "\n", 1 );
e->headless = 0;
e->stage = doc_open; e->stage = doc_open;
} }
} }
@ -493,6 +493,7 @@ void syck_emit_indent( SyckEmitter *e )
{ {
int i; int i;
SyckLevel *lvl = syck_emitter_current_level( e ); SyckLevel *lvl = syck_emitter_current_level( e );
if ( e->bufpos == 0 && ( e->marker - e->buffer ) == 0 ) return;
if ( lvl->spaces >= 0 ) { if ( lvl->spaces >= 0 ) {
char *spcs = S_ALLOC_N( char, lvl->spaces + 2 ); char *spcs = S_ALLOC_N( char, lvl->spaces + 2 );
@ -511,8 +512,8 @@ void syck_emit_indent( SyckEmitter *e )
#define SCAN_INDENTED 2 #define SCAN_INDENTED 2
/* Larger than the requested width? */ /* Larger than the requested width? */
#define SCAN_WIDE 4 #define SCAN_WIDE 4
/* Opens with whitespace? */ /* Opens or closes with whitespace? */
#define SCAN_WHITESTART 8 #define SCAN_WHITEEDGE 8
/* Contains a newline */ /* Contains a newline */
#define SCAN_NEWLINE 16 #define SCAN_NEWLINE 16
/* Contains a single quote */ /* Contains a single quote */
@ -562,12 +563,18 @@ syck_scan_scalar( int req_width, char *cursor, long len )
flags |= SCAN_INDIC_S; flags |= SCAN_INDIC_S;
} }
/* ending newlines */ /* whitespace edges */
if ( cursor[len-1] != '\n' ) { if ( cursor[len-1] != '\n' ) {
flags |= SCAN_NONL_E; flags |= SCAN_NONL_E;
} else if ( len > 1 && cursor[len-2] == '\n' ) { } else if ( len > 1 && cursor[len-2] == '\n' ) {
flags |= SCAN_MANYNL_E; flags |= SCAN_MANYNL_E;
} }
if (
( len > 0 && ( cursor[0] == ' ' || cursor[0] == '\t' ) ) ||
( len > 1 && ( cursor[len-1] == ' ' || cursor[len-1] == '\t' ) )
) {
flags |= SCAN_WHITEEDGE;
}
/* opening doc sep */ /* opening doc sep */
if ( len >= 3 && strncmp( cursor, "---", 3 ) == 0 ) if ( len >= 3 && strncmp( cursor, "---", 3 ) == 0 )
@ -620,12 +627,6 @@ syck_scan_scalar( int req_width, char *cursor, long len )
flags |= SCAN_FLOWMAP; flags |= SCAN_FLOWMAP;
flags |= SCAN_FLOWSEQ; flags |= SCAN_FLOWSEQ;
} }
if ( i == 0 &&
( cursor[i] == ' ' || cursor[i] == '\t' )
) {
flags |= SCAN_WHITESTART;
}
} }
/* printf( "---STR---\n%s\nFLAGS: %d\n", cursor, flags ); */ /* printf( "---STR---\n%s\nFLAGS: %d\n", cursor, flags ); */
@ -682,7 +683,7 @@ void syck_emit_scalar( SyckEmitter *e, char *tag, enum scalar_style force_style,
/* Determine block style */ /* Determine block style */
if ( scan & SCAN_NONPRINT ) { if ( scan & SCAN_NONPRINT ) {
force_style = scalar_2quote; force_style = scalar_2quote;
} else if ( scan & SCAN_WHITESTART ) { } else if ( scan & SCAN_WHITEEDGE ) {
force_style = scalar_2quote; force_style = scalar_2quote;
} else if ( force_style != scalar_fold && ( scan & SCAN_INDENTED ) ) { } else if ( force_style != scalar_fold && ( scan & SCAN_INDENTED ) ) {
force_style = scalar_literal; force_style = scalar_literal;

View file

@ -46,13 +46,6 @@ typedef struct {
#define RUBY_DOMAIN "ruby.yaml.org,2002" #define RUBY_DOMAIN "ruby.yaml.org,2002"
#ifndef StringValue
#define StringValue(v) (v)
#endif
#ifndef rb_attr_get
#define rb_attr_get(o, i) rb_ivar_get(o, i)
#endif
/* /*
* symbols and constants * symbols and constants
*/ */
@ -1120,10 +1113,6 @@ syck_resolver_transfer( self, type, val )
} }
else if ( rb_cObject == target_class && subclass_v == Qnil ) else if ( rb_cObject == target_class && subclass_v == Qnil )
{ {
/*
StringValue(subclass);
printf( "No class: %s\n", RSTRING(subclass)->ptr );
*/
target_class = cYObject; target_class = cYObject;
type = subclass; type = subclass;
subclass = cYObject; subclass = cYObject;
@ -2030,6 +2019,7 @@ syck_emitter_reset( argc, argv, self )
rb_ivar_set(self, s_options, options); rb_ivar_set(self, s_options, options);
} }
emitter->headless = 1;
emitter->bonus = (void *)bonus; emitter->bonus = (void *)bonus;
rb_ivar_set(self, s_level, INT2FIX(0)); rb_ivar_set(self, s_level, INT2FIX(0));
rb_ivar_set(self, s_resolver, Qnil); rb_ivar_set(self, s_resolver, Qnil);

View file

@ -274,7 +274,6 @@ typedef void (*SyckEmitterHandler)(SyckEmitter *, st_data_t);
enum doc_stage { enum doc_stage {
doc_open, doc_open,
doc_need_header,
doc_processing doc_processing
}; };

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,6 @@
# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4 # -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4
require 'date' require 'date'
#
# Type conversions
#
class Class class Class
def to_yaml( opts = {} ) def to_yaml( opts = {} )
raise TypeError, "can't dump anonymous class %s" % self.class raise TypeError, "can't dump anonymous class %s" % self.class
@ -25,9 +22,6 @@ class Object
end end
end end
#
# Maps: Hash#to_yaml
#
class Hash class Hash
yaml_as "tag:ruby.yaml.org,2002:hash" yaml_as "tag:ruby.yaml.org,2002:hash"
yaml_as "tag:yaml.org,2002:map" yaml_as "tag:yaml.org,2002:map"
@ -51,9 +45,6 @@ class Hash
end end
end end
#
# Structs: export as a !map
#
class Struct class Struct
yaml_as "tag:ruby.yaml.org,2002:struct" yaml_as "tag:ruby.yaml.org,2002:struct"
def self.yaml_tag_class_name; self.name.gsub( "Struct::", "" ); end def self.yaml_tag_class_name; self.name.gsub( "Struct::", "" ); end
@ -108,9 +99,6 @@ class Struct
end end
end end
#
# Sequences: Array#to_yaml
#
class Array class Array
yaml_as "tag:ruby.yaml.org,2002:array" yaml_as "tag:ruby.yaml.org,2002:array"
yaml_as "tag:yaml.org,2002:seq" yaml_as "tag:yaml.org,2002:seq"
@ -126,9 +114,6 @@ class Array
end end
end end
#
# Exception#to_yaml
#
class Exception class Exception
yaml_as "tag:ruby.yaml.org,2002:exception" yaml_as "tag:ruby.yaml.org,2002:exception"
def Exception.yaml_new( klass, tag, val ) def Exception.yaml_new( klass, tag, val )
@ -150,10 +135,6 @@ class Exception
end end
end end
#
# String#to_yaml
#
class String class String
yaml_as "tag:ruby.yaml.org,2002:string" yaml_as "tag:ruby.yaml.org,2002:string"
yaml_as "tag:yaml.org,2002:str" yaml_as "tag:yaml.org,2002:str"
@ -194,9 +175,7 @@ class String
end end
end end
end end
#
# Symbol#to_yaml
#
class Symbol class Symbol
yaml_as "tag:ruby.yaml.org,2002:symbol" yaml_as "tag:ruby.yaml.org,2002:symbol"
yaml_as "tag:ruby.yaml.org,2002:sym" yaml_as "tag:ruby.yaml.org,2002:sym"
@ -210,15 +189,11 @@ class Symbol
end end
def to_yaml( opts = {} ) def to_yaml( opts = {} )
YAML::quick_emit( nil, opts ) do |out| YAML::quick_emit( nil, opts ) do |out|
out.scalar( taguri, self.id2name, :plain ) out.scalar( "tag:yaml.org,2002:str", self.inspect, :plain )
end end
end end
end end
#
# Range#to_yaml
# TODO: Rework the Range as a sequence (simpler)
#
class Range class Range
yaml_as "tag:ruby.yaml.org,2002:range" yaml_as "tag:ruby.yaml.org,2002:range"
def Range.yaml_new( klass, tag, val ) def Range.yaml_new( klass, tag, val )
@ -273,9 +248,6 @@ class Range
end end
end end
#
# Make an Regexp
#
class Regexp class Regexp
yaml_as "tag:ruby.yaml.org,2002:regexp" yaml_as "tag:ruby.yaml.org,2002:regexp"
def Regexp.yaml_new( klass, tag, val ) def Regexp.yaml_new( klass, tag, val )
@ -323,9 +295,6 @@ class Regexp
end end
end end
#
# Emit a Time object as an ISO 8601 timestamp
#
class Time class Time
yaml_as "tag:ruby.yaml.org,2002:time" yaml_as "tag:ruby.yaml.org,2002:time"
yaml_as "tag:yaml.org,2002:timestamp" yaml_as "tag:yaml.org,2002:timestamp"
@ -373,9 +342,6 @@ class Time
end end
end end
#
# Emit a Date object as a simple implicit
#
class Date class Date
yaml_as "tag:yaml.org,2002:timestamp#ymd" yaml_as "tag:yaml.org,2002:timestamp#ymd"
def to_yaml( opts = {} ) def to_yaml( opts = {} )
@ -385,9 +351,6 @@ class Date
end end
end end
#
# Send Integer, Booleans, NilClass to String
#
class Numeric class Numeric
def to_yaml( opts = {} ) def to_yaml( opts = {} )
YAML::quick_emit( nil, opts ) do |out| YAML::quick_emit( nil, opts ) do |out|
@ -403,9 +366,11 @@ class Numeric
end end
end end
end end
class Fixnum class Fixnum
yaml_as "tag:yaml.org,2002:int" yaml_as "tag:yaml.org,2002:int"
end end
class Float class Float
yaml_as "tag:yaml.org,2002:float" yaml_as "tag:yaml.org,2002:float"
end end

View file

@ -632,15 +632,17 @@ EOY
end end
def test_spec_domain_prefix def test_spec_domain_prefix
YAML.add_domain_type( "domain.tld,2002", /(invoice|customer)/ ) { |type, val| customer_proc = proc { |type, val|
if Hash === val if Hash === val
scheme, domain, type = type.split( ':', 3 ) scheme, domain, type = type.split( ':', 3 )
val['type'] = "domain #{type}" val['type'] = "domain #{type}"
val val
else else
raise ArgumentError, "Not a Hash in domain.tld,2002/invoice: " + val.inspect raise ArgumentError, "Not a Hash in domain.tld,2002/invoice: " + val.inspect
end end
} }
YAML.add_domain_type( "domain.tld,2002", 'invoice', &customer_proc )
YAML.add_domain_type( "domain.tld,2002", 'customer', &customer_proc )
assert_parse_only( { "invoice"=> { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }, <<EOY assert_parse_only( { "invoice"=> { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }, <<EOY
# 'http://domain.tld,2002/invoice' is some type family. # 'http://domain.tld,2002/invoice' is some type family.
invoice: !domain.tld,2002/^invoice invoice: !domain.tld,2002/^invoice
@ -744,9 +746,9 @@ EOY
end end
def test_spec_explicit_families def test_spec_explicit_families
YAML.add_domain_type( "somewhere.com,2002", /^type$/ ) { |type, val| YAML.add_domain_type( "somewhere.com,2002", 'type' ) { |type, val|
"SOMEWHERE: #{val}" "SOMEWHERE: #{val}"
} }
assert_parse_only( assert_parse_only(
{ 'not-date' => '2002-04-28', 'picture' => "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236i^\020' \202\n\001\000;", 'hmm' => "SOMEWHERE: family above is short for\nhttp://somewhere.com/type\n" }, <<EOY { 'not-date' => '2002-04-28', 'picture' => "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236i^\020' \202\n\001\000;", 'hmm' => "SOMEWHERE: family above is short for\nhttp://somewhere.com/type\n" }, <<EOY
not-date: !str 2002-04-28 not-date: !str 2002-04-28
@ -1049,17 +1051,6 @@ EOY
) )
end end
def test_perl_regexp
# Parsing perl regular expressions from YAML.pm
assert_parse_only(
[ /bozo$/i ], <<EOY
- !perl/regexp:
regexp: bozo$
mods: i
EOY
)
end
# #
# Test of Ranges # Test of Ranges
# #