зеркало из https://github.com/github/ruby.git
* 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:
Родитель
17f4f5f507
Коммит
f3d9f34537
16
ChangeLog
16
ChangeLog
|
@ -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>
|
||||
|
||||
* file.c (rb_file_join): convert components by to_s instead of to_str.
|
||||
|
|
|
@ -338,27 +338,6 @@ syck_emitter_flush( SyckEmitter *e, long check_room )
|
|||
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.
|
||||
*/
|
||||
|
@ -383,6 +362,26 @@ syck_emit( SyckEmitter *e, st_data_t n )
|
|||
int indent = 0, x = 0;
|
||||
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 */
|
||||
if ( lvl->spaces >= 0 ) {
|
||||
indent = lvl->spaces + e->indent;
|
||||
|
@ -429,6 +428,7 @@ end_emit:
|
|||
syck_emitter_pop_level( e );
|
||||
if ( e->lvl_idx == 1 ) {
|
||||
syck_emitter_write( e, "\n", 1 );
|
||||
e->headless = 0;
|
||||
e->stage = doc_open;
|
||||
}
|
||||
}
|
||||
|
@ -493,6 +493,7 @@ void syck_emit_indent( SyckEmitter *e )
|
|||
{
|
||||
int i;
|
||||
SyckLevel *lvl = syck_emitter_current_level( e );
|
||||
if ( e->bufpos == 0 && ( e->marker - e->buffer ) == 0 ) return;
|
||||
if ( lvl->spaces >= 0 ) {
|
||||
char *spcs = S_ALLOC_N( char, lvl->spaces + 2 );
|
||||
|
||||
|
@ -511,8 +512,8 @@ void syck_emit_indent( SyckEmitter *e )
|
|||
#define SCAN_INDENTED 2
|
||||
/* Larger than the requested width? */
|
||||
#define SCAN_WIDE 4
|
||||
/* Opens with whitespace? */
|
||||
#define SCAN_WHITESTART 8
|
||||
/* Opens or closes with whitespace? */
|
||||
#define SCAN_WHITEEDGE 8
|
||||
/* Contains a newline */
|
||||
#define SCAN_NEWLINE 16
|
||||
/* Contains a single quote */
|
||||
|
@ -562,12 +563,18 @@ syck_scan_scalar( int req_width, char *cursor, long len )
|
|||
flags |= SCAN_INDIC_S;
|
||||
}
|
||||
|
||||
/* ending newlines */
|
||||
/* whitespace edges */
|
||||
if ( cursor[len-1] != '\n' ) {
|
||||
flags |= SCAN_NONL_E;
|
||||
} else if ( len > 1 && cursor[len-2] == '\n' ) {
|
||||
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 */
|
||||
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_FLOWSEQ;
|
||||
}
|
||||
|
||||
if ( i == 0 &&
|
||||
( cursor[i] == ' ' || cursor[i] == '\t' )
|
||||
) {
|
||||
flags |= SCAN_WHITESTART;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
if ( scan & SCAN_NONPRINT ) {
|
||||
force_style = scalar_2quote;
|
||||
} else if ( scan & SCAN_WHITESTART ) {
|
||||
} else if ( scan & SCAN_WHITEEDGE ) {
|
||||
force_style = scalar_2quote;
|
||||
} else if ( force_style != scalar_fold && ( scan & SCAN_INDENTED ) ) {
|
||||
force_style = scalar_literal;
|
||||
|
|
|
@ -46,13 +46,6 @@ typedef struct {
|
|||
|
||||
#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
|
||||
*/
|
||||
|
@ -1120,10 +1113,6 @@ syck_resolver_transfer( self, type, val )
|
|||
}
|
||||
else if ( rb_cObject == target_class && subclass_v == Qnil )
|
||||
{
|
||||
/*
|
||||
StringValue(subclass);
|
||||
printf( "No class: %s\n", RSTRING(subclass)->ptr );
|
||||
*/
|
||||
target_class = cYObject;
|
||||
type = subclass;
|
||||
subclass = cYObject;
|
||||
|
@ -2030,6 +2019,7 @@ syck_emitter_reset( argc, argv, self )
|
|||
rb_ivar_set(self, s_options, options);
|
||||
}
|
||||
|
||||
emitter->headless = 1;
|
||||
emitter->bonus = (void *)bonus;
|
||||
rb_ivar_set(self, s_level, INT2FIX(0));
|
||||
rb_ivar_set(self, s_resolver, Qnil);
|
||||
|
|
|
@ -274,7 +274,6 @@ typedef void (*SyckEmitterHandler)(SyckEmitter *, st_data_t);
|
|||
|
||||
enum doc_stage {
|
||||
doc_open,
|
||||
doc_need_header,
|
||||
doc_processing
|
||||
};
|
||||
|
||||
|
|
1023
ext/syck/token.c
1023
ext/syck/token.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,9 +1,6 @@
|
|||
# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4
|
||||
require 'date'
|
||||
|
||||
#
|
||||
# Type conversions
|
||||
#
|
||||
class Class
|
||||
def to_yaml( opts = {} )
|
||||
raise TypeError, "can't dump anonymous class %s" % self.class
|
||||
|
@ -25,9 +22,6 @@ class Object
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Maps: Hash#to_yaml
|
||||
#
|
||||
class Hash
|
||||
yaml_as "tag:ruby.yaml.org,2002:hash"
|
||||
yaml_as "tag:yaml.org,2002:map"
|
||||
|
@ -51,9 +45,6 @@ class Hash
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Structs: export as a !map
|
||||
#
|
||||
class Struct
|
||||
yaml_as "tag:ruby.yaml.org,2002:struct"
|
||||
def self.yaml_tag_class_name; self.name.gsub( "Struct::", "" ); end
|
||||
|
@ -108,9 +99,6 @@ class Struct
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Sequences: Array#to_yaml
|
||||
#
|
||||
class Array
|
||||
yaml_as "tag:ruby.yaml.org,2002:array"
|
||||
yaml_as "tag:yaml.org,2002:seq"
|
||||
|
@ -126,9 +114,6 @@ class Array
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Exception#to_yaml
|
||||
#
|
||||
class Exception
|
||||
yaml_as "tag:ruby.yaml.org,2002:exception"
|
||||
def Exception.yaml_new( klass, tag, val )
|
||||
|
@ -150,10 +135,6 @@ class Exception
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
# String#to_yaml
|
||||
#
|
||||
class String
|
||||
yaml_as "tag:ruby.yaml.org,2002:string"
|
||||
yaml_as "tag:yaml.org,2002:str"
|
||||
|
@ -194,9 +175,7 @@ class String
|
|||
end
|
||||
end
|
||||
end
|
||||
#
|
||||
# Symbol#to_yaml
|
||||
#
|
||||
|
||||
class Symbol
|
||||
yaml_as "tag:ruby.yaml.org,2002:symbol"
|
||||
yaml_as "tag:ruby.yaml.org,2002:sym"
|
||||
|
@ -210,15 +189,11 @@ class Symbol
|
|||
end
|
||||
def to_yaml( opts = {} )
|
||||
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
|
||||
|
||||
#
|
||||
# Range#to_yaml
|
||||
# TODO: Rework the Range as a sequence (simpler)
|
||||
#
|
||||
class Range
|
||||
yaml_as "tag:ruby.yaml.org,2002:range"
|
||||
def Range.yaml_new( klass, tag, val )
|
||||
|
@ -273,9 +248,6 @@ class Range
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Make an Regexp
|
||||
#
|
||||
class Regexp
|
||||
yaml_as "tag:ruby.yaml.org,2002:regexp"
|
||||
def Regexp.yaml_new( klass, tag, val )
|
||||
|
@ -323,9 +295,6 @@ class Regexp
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Emit a Time object as an ISO 8601 timestamp
|
||||
#
|
||||
class Time
|
||||
yaml_as "tag:ruby.yaml.org,2002:time"
|
||||
yaml_as "tag:yaml.org,2002:timestamp"
|
||||
|
@ -373,9 +342,6 @@ class Time
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Emit a Date object as a simple implicit
|
||||
#
|
||||
class Date
|
||||
yaml_as "tag:yaml.org,2002:timestamp#ymd"
|
||||
def to_yaml( opts = {} )
|
||||
|
@ -385,9 +351,6 @@ class Date
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Send Integer, Booleans, NilClass to String
|
||||
#
|
||||
class Numeric
|
||||
def to_yaml( opts = {} )
|
||||
YAML::quick_emit( nil, opts ) do |out|
|
||||
|
@ -403,9 +366,11 @@ class Numeric
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Fixnum
|
||||
yaml_as "tag:yaml.org,2002:int"
|
||||
end
|
||||
|
||||
class Float
|
||||
yaml_as "tag:yaml.org,2002:float"
|
||||
end
|
||||
|
|
|
@ -632,15 +632,17 @@ EOY
|
|||
end
|
||||
|
||||
def test_spec_domain_prefix
|
||||
YAML.add_domain_type( "domain.tld,2002", /(invoice|customer)/ ) { |type, val|
|
||||
if Hash === val
|
||||
customer_proc = proc { |type, val|
|
||||
if Hash === val
|
||||
scheme, domain, type = type.split( ':', 3 )
|
||||
val['type'] = "domain #{type}"
|
||||
val
|
||||
else
|
||||
raise ArgumentError, "Not a Hash in domain.tld,2002/invoice: " + val.inspect
|
||||
end
|
||||
}
|
||||
val['type'] = "domain #{type}"
|
||||
val
|
||||
else
|
||||
raise ArgumentError, "Not a Hash in domain.tld,2002/invoice: " + val.inspect
|
||||
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
|
||||
# 'http://domain.tld,2002/invoice' is some type family.
|
||||
invoice: !domain.tld,2002/^invoice
|
||||
|
@ -744,9 +746,9 @@ EOY
|
|||
end
|
||||
|
||||
def test_spec_explicit_families
|
||||
YAML.add_domain_type( "somewhere.com,2002", /^type$/ ) { |type, val|
|
||||
"SOMEWHERE: #{val}"
|
||||
}
|
||||
YAML.add_domain_type( "somewhere.com,2002", 'type' ) { |type, val|
|
||||
"SOMEWHERE: #{val}"
|
||||
}
|
||||
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: !str 2002-04-28
|
||||
|
@ -1049,17 +1051,6 @@ EOY
|
|||
)
|
||||
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
|
||||
#
|
||||
|
|
Загрузка…
Ссылка в новой задаче