In Files

  • syck/rubyext.c

Object::Syck::Parser

Define YAML::Syck::Parser class

Attributes

input[RW]
options[RW]
resolver[RW]

Public Class Methods

new(p1 = v1) click to toggle source

YAML::Syck::Parser.initialize( resolver, options )

 
               static VALUE
syck_parser_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE options;
    if (rb_scan_args(argc, argv, "01", &options) == 0)
    {
        options = rb_hash_new();
    }
    else
    {
        Check_Type(options, T_HASH);
    }
    rb_ivar_set(self, s_options, options);
    rb_ivar_set(self, s_input, Qnil);
    return self;
}
            

Public Instance Methods

bufsize() click to toggle source

YAML::Syck::Parser.bufsize => Integer

 
               static VALUE
syck_parser_bufsize_get(VALUE self)
{
    SyckParser *parser;

    Data_Get_Struct(self, SyckParser, parser);
    return INT2FIX( parser->bufsize );
}
            
bufsize=(p1) click to toggle source

YAML::Syck::Parser.bufsize = Integer

 
               static VALUE
syck_parser_bufsize_set(VALUE self, VALUE size)
{
    SyckParser *parser;

    if ( rb_respond_to( size, s_to_i ) ) {
        int n = NUM2INT(rb_funcall(size, s_to_i, 0));
        Data_Get_Struct(self, SyckParser, parser);
        parser->bufsize = n;
    }
    return self;
}
            
load(p1, p2 = v2) click to toggle source

YAML::Syck::Parser.load( IO or String )

 
               VALUE
syck_parser_load(int argc, VALUE *argv, VALUE self)
{
    VALUE port, proc, model, input;
    SyckParser *parser;
    struct parser_xtra *bonus;

    rb_scan_args(argc, argv, "11", &port, &proc);

    input = rb_hash_aref( rb_attr_get( self, s_options ), sym_input );
    model = rb_hash_aref( rb_attr_get( self, s_options ), sym_model );
    Data_Get_Struct(self, SyckParser, parser);
    syck_set_model( self, input, model );

    bonus = (struct parser_xtra *)parser->bonus;
    bonus->taint = syck_parser_assign_io(parser, &port);
    bonus->data = rb_hash_new();
    bonus->resolver = rb_attr_get( self, s_resolver );
    if ( NIL_P( proc ) ) bonus->proc = 0;
    else                 bonus->proc = proc;

    return syck_parse( parser );
}
            
load_documents(p1, &block) click to toggle source

YAML::Syck::Parser.load_documents( IO or String ) { |doc| }

 
               VALUE
syck_parser_load_documents(int argc, VALUE *argv, VALUE self)
{
    VALUE port, proc, v, input, model;
    SyckParser *parser;
    struct parser_xtra *bonus;

    rb_scan_args(argc, argv, "1&", &port, &proc);

    input = rb_hash_aref( rb_attr_get( self, s_options ), sym_input );
    model = rb_hash_aref( rb_attr_get( self, s_options ), sym_model );
    Data_Get_Struct(self, SyckParser, parser);
    syck_set_model( self, input, model );

    bonus = (struct parser_xtra *)parser->bonus;
    bonus->taint = syck_parser_assign_io(parser, &port);
    bonus->resolver = rb_attr_get( self, s_resolver );
    bonus->proc = 0;

    while ( 1 )
    {
        /* Reset hash for tracking nodes */
        bonus->data = rb_hash_new();

        /* Parse a document */
        v = syck_parse( parser );
        if ( parser->eof == 1 )
        {
            break;
        }

        /* Pass document to block */
        rb_funcall( proc, s_call, 1, v );
    }

    return Qnil;
}
            
set_resolver(p1) click to toggle source

YAML::Syck::Parser#set_resolver

 
               VALUE
syck_parser_set_resolver(VALUE self, VALUE resolver)
{
    rb_ivar_set( self, s_resolver, resolver );
    return self;
}