mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/psych/{emitter,parser,psych}.c: move variable
declaration to the first of the block. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7abf7e58e8
commit
e43b94231b
4 changed files with 48 additions and 43 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Mar 30 03:56:13 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* ext/psych/{emitter,parser,psych}.c: move variable
|
||||
declaration to the first of the block.
|
||||
|
||||
Mon Mar 29 21:47:44 2010 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* prelude.rb, .document: Stuff in prelude.rb should be documented
|
||||
|
|
27
ext/psych/emitter.c
Normal file → Executable file
27
ext/psych/emitter.c
Normal file → Executable file
|
@ -56,10 +56,10 @@ static VALUE initialize(VALUE self, VALUE io)
|
|||
static VALUE start_stream(VALUE self, VALUE encoding)
|
||||
{
|
||||
yaml_emitter_t * emitter;
|
||||
yaml_event_t event;
|
||||
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||||
Check_Type(encoding, T_FIXNUM);
|
||||
|
||||
yaml_event_t event;
|
||||
yaml_stream_start_event_initialize(&event, (yaml_encoding_t)NUM2INT(encoding));
|
||||
|
||||
emit(emitter, &event);
|
||||
|
@ -76,9 +76,9 @@ static VALUE start_stream(VALUE self, VALUE encoding)
|
|||
static VALUE end_stream(VALUE self)
|
||||
{
|
||||
yaml_emitter_t * emitter;
|
||||
yaml_event_t event;
|
||||
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||||
|
||||
yaml_event_t event;
|
||||
yaml_stream_end_event_initialize(&event);
|
||||
|
||||
emit(emitter, &event);
|
||||
|
@ -96,9 +96,12 @@ static VALUE end_stream(VALUE self)
|
|||
static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
|
||||
{
|
||||
yaml_emitter_t * emitter;
|
||||
yaml_tag_directive_t * head = NULL;
|
||||
yaml_tag_directive_t * tail = NULL;
|
||||
yaml_event_t event;
|
||||
yaml_version_directive_t version_directive;
|
||||
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||||
|
||||
yaml_version_directive_t version_directive;
|
||||
|
||||
Check_Type(version, T_ARRAY);
|
||||
|
||||
|
@ -110,9 +113,6 @@ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
|
|||
version_directive.minor = NUM2INT(minor);
|
||||
}
|
||||
|
||||
yaml_tag_directive_t * head = NULL;
|
||||
yaml_tag_directive_t * tail = NULL;
|
||||
|
||||
if(RTEST(tags)) {
|
||||
int i = 0;
|
||||
|
||||
|
@ -137,7 +137,6 @@ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
|
|||
}
|
||||
}
|
||||
|
||||
yaml_event_t event;
|
||||
yaml_document_start_event_initialize(
|
||||
&event,
|
||||
(RARRAY_LEN(version) > 0) ? &version_directive : NULL,
|
||||
|
@ -162,9 +161,9 @@ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
|
|||
static VALUE end_document(VALUE self, VALUE imp)
|
||||
{
|
||||
yaml_emitter_t * emitter;
|
||||
yaml_event_t event;
|
||||
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||||
|
||||
yaml_event_t event;
|
||||
yaml_document_end_event_initialize(&event, imp ? 1 : 0);
|
||||
|
||||
emit(emitter, &event);
|
||||
|
@ -189,11 +188,11 @@ static VALUE scalar(
|
|||
VALUE style
|
||||
) {
|
||||
yaml_emitter_t * emitter;
|
||||
yaml_event_t event;
|
||||
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||||
|
||||
Check_Type(value, T_STRING);
|
||||
|
||||
yaml_event_t event;
|
||||
yaml_scalar_event_initialize(
|
||||
&event,
|
||||
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValuePtr(anchor)),
|
||||
|
@ -225,9 +224,9 @@ static VALUE start_sequence(
|
|||
VALUE style
|
||||
) {
|
||||
yaml_emitter_t * emitter;
|
||||
yaml_event_t event;
|
||||
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||||
|
||||
yaml_event_t event;
|
||||
yaml_sequence_start_event_initialize(
|
||||
&event,
|
||||
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValuePtr(anchor)),
|
||||
|
@ -250,9 +249,9 @@ static VALUE start_sequence(
|
|||
static VALUE end_sequence(VALUE self)
|
||||
{
|
||||
yaml_emitter_t * emitter;
|
||||
yaml_event_t event;
|
||||
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||||
|
||||
yaml_event_t event;
|
||||
yaml_sequence_end_event_initialize(&event);
|
||||
|
||||
emit(emitter, &event);
|
||||
|
@ -275,9 +274,9 @@ static VALUE start_mapping(
|
|||
VALUE style
|
||||
) {
|
||||
yaml_emitter_t * emitter;
|
||||
yaml_event_t event;
|
||||
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||||
|
||||
yaml_event_t event;
|
||||
yaml_mapping_start_event_initialize(
|
||||
&event,
|
||||
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValuePtr(anchor)),
|
||||
|
@ -300,9 +299,9 @@ static VALUE start_mapping(
|
|||
static VALUE end_mapping(VALUE self)
|
||||
{
|
||||
yaml_emitter_t * emitter;
|
||||
yaml_event_t event;
|
||||
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||||
|
||||
yaml_event_t event;
|
||||
yaml_mapping_end_event_initialize(&event);
|
||||
|
||||
emit(emitter, &event);
|
||||
|
@ -319,9 +318,9 @@ static VALUE end_mapping(VALUE self)
|
|||
static VALUE alias(VALUE self, VALUE anchor)
|
||||
{
|
||||
yaml_emitter_t * emitter;
|
||||
yaml_event_t event;
|
||||
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
||||
|
||||
yaml_event_t event;
|
||||
yaml_alias_event_initialize(
|
||||
&event,
|
||||
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValuePtr(anchor))
|
||||
|
|
50
ext/psych/parser.c
Normal file → Executable file
50
ext/psych/parser.c
Normal file → Executable file
|
@ -45,6 +45,12 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
{
|
||||
yaml_parser_t parser;
|
||||
yaml_event_t event;
|
||||
int done = 0;
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
int encoding = rb_enc_find_index("ASCII-8BIT");
|
||||
#endif
|
||||
VALUE handler = rb_iv_get(self, "@handler");
|
||||
|
||||
|
||||
yaml_parser_initialize(&parser);
|
||||
|
||||
|
@ -58,13 +64,6 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
);
|
||||
}
|
||||
|
||||
int done = 0;
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
int encoding = rb_enc_find_index("ASCII-8BIT");
|
||||
#endif
|
||||
|
||||
VALUE handler = rb_iv_get(self, "@handler");
|
||||
|
||||
while(!done) {
|
||||
if(!yaml_parser_parse(&parser, &event)) {
|
||||
size_t line = parser.mark.line;
|
||||
|
@ -102,7 +101,9 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
break;
|
||||
case YAML_DOCUMENT_START_EVENT:
|
||||
{
|
||||
// Grab the document version
|
||||
/* Get a list of tag directives (if any) */
|
||||
VALUE tag_directives = rb_ary_new();
|
||||
/* Grab the document version */
|
||||
VALUE version = event.data.document_start.version_directive ?
|
||||
rb_ary_new3(
|
||||
(long)2,
|
||||
|
@ -110,8 +111,6 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
INT2NUM((long)event.data.document_start.version_directive->minor)
|
||||
) : rb_ary_new();
|
||||
|
||||
// Get a list of tag directives (if any)
|
||||
VALUE tag_directives = rb_ary_new();
|
||||
if(event.data.document_start.tag_directives.start) {
|
||||
yaml_tag_directive_t *start =
|
||||
event.data.document_start.tag_directives.start;
|
||||
|
@ -119,6 +118,7 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
event.data.document_start.tag_directives.end;
|
||||
for(; start != end; start++) {
|
||||
VALUE handle = Qnil;
|
||||
VALUE prefix = Qnil;
|
||||
if(start->handle) {
|
||||
handle = rb_str_new2((const char *)start->handle);
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
|
@ -126,7 +126,6 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
#endif
|
||||
}
|
||||
|
||||
VALUE prefix = Qnil;
|
||||
if(start->prefix) {
|
||||
prefix = rb_str_new2((const char *)start->prefix);
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
|
@ -134,8 +133,7 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
#endif
|
||||
}
|
||||
|
||||
VALUE pair = rb_ary_new3((long)2, handle, prefix);
|
||||
rb_ary_push(tag_directives, pair);
|
||||
rb_ary_push(tag_directives, rb_ary_new3((long)2, handle, prefix));
|
||||
}
|
||||
}
|
||||
rb_funcall(handler, id_start_document, 3,
|
||||
|
@ -164,6 +162,9 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
break;
|
||||
case YAML_SCALAR_EVENT:
|
||||
{
|
||||
VALUE anchor = Qnil;
|
||||
VALUE tag = Qnil;
|
||||
VALUE plain_implicit, quoted_implicit, style;
|
||||
VALUE val = rb_str_new(
|
||||
(const char *)event.data.scalar.value,
|
||||
(long)event.data.scalar.length
|
||||
|
@ -173,7 +174,6 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
rb_enc_associate_index(val, encoding);
|
||||
#endif
|
||||
|
||||
VALUE anchor = Qnil;
|
||||
if(event.data.scalar.anchor) {
|
||||
anchor = rb_str_new2((const char *)event.data.scalar.anchor);
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
|
@ -181,7 +181,6 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
#endif
|
||||
}
|
||||
|
||||
VALUE tag = Qnil;
|
||||
if(event.data.scalar.tag) {
|
||||
tag = rb_str_new2((const char *)event.data.scalar.tag);
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
|
@ -189,13 +188,13 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
#endif
|
||||
}
|
||||
|
||||
VALUE plain_implicit =
|
||||
plain_implicit =
|
||||
event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue;
|
||||
|
||||
VALUE quoted_implicit =
|
||||
quoted_implicit =
|
||||
event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
|
||||
|
||||
VALUE style = INT2NUM((long)event.data.scalar.style);
|
||||
style = INT2NUM((long)event.data.scalar.style);
|
||||
|
||||
rb_funcall(handler, id_scalar, 6,
|
||||
val, anchor, tag, plain_implicit, quoted_implicit, style);
|
||||
|
@ -204,6 +203,8 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
case YAML_SEQUENCE_START_EVENT:
|
||||
{
|
||||
VALUE anchor = Qnil;
|
||||
VALUE tag = Qnil;
|
||||
VALUE implicit, style;
|
||||
if(event.data.sequence_start.anchor) {
|
||||
anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
|
@ -211,7 +212,7 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
#endif
|
||||
}
|
||||
|
||||
VALUE tag = Qnil;
|
||||
tag = Qnil;
|
||||
if(event.data.sequence_start.tag) {
|
||||
tag = rb_str_new2((const char *)event.data.sequence_start.tag);
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
|
@ -219,10 +220,10 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
#endif
|
||||
}
|
||||
|
||||
VALUE implicit =
|
||||
implicit =
|
||||
event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue;
|
||||
|
||||
VALUE style = INT2NUM((long)event.data.sequence_start.style);
|
||||
style = INT2NUM((long)event.data.sequence_start.style);
|
||||
|
||||
rb_funcall(handler, id_start_sequence, 4,
|
||||
anchor, tag, implicit, style);
|
||||
|
@ -234,6 +235,8 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
case YAML_MAPPING_START_EVENT:
|
||||
{
|
||||
VALUE anchor = Qnil;
|
||||
VALUE tag = Qnil;
|
||||
VALUE implicit, style;
|
||||
if(event.data.mapping_start.anchor) {
|
||||
anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
|
@ -241,7 +244,6 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
#endif
|
||||
}
|
||||
|
||||
VALUE tag = Qnil;
|
||||
if(event.data.mapping_start.tag) {
|
||||
tag = rb_str_new2((const char *)event.data.mapping_start.tag);
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
|
@ -249,10 +251,10 @@ static VALUE parse(VALUE self, VALUE yaml)
|
|||
#endif
|
||||
}
|
||||
|
||||
VALUE implicit =
|
||||
implicit =
|
||||
event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
|
||||
|
||||
VALUE style = INT2NUM((long)event.data.mapping_start.style);
|
||||
style = INT2NUM((long)event.data.mapping_start.style);
|
||||
|
||||
rb_funcall(handler, id_start_mapping, 4,
|
||||
anchor, tag, implicit, style);
|
||||
|
|
9
ext/psych/psych.c
Normal file → Executable file
9
ext/psych/psych.c
Normal file → Executable file
|
@ -7,14 +7,13 @@
|
|||
static VALUE libyaml_version(VALUE module)
|
||||
{
|
||||
int major, minor, patch;
|
||||
VALUE list[3];
|
||||
|
||||
yaml_get_version(&major, &minor, &patch);
|
||||
|
||||
VALUE list[3] = {
|
||||
INT2NUM((long)major),
|
||||
INT2NUM((long)minor),
|
||||
INT2NUM((long)patch)
|
||||
};
|
||||
list[0] = INT2NUM((long)major);
|
||||
list[1] = INT2NUM((long)minor);
|
||||
list[2] = INT2NUM((long)patch);
|
||||
|
||||
return rb_ary_new4((long)3, list);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue