Class: Ripper

Inherits:
Object show all
Defined in:
parse.c

Constant Summary collapse

Version =
rb_usascii_str_new2(RIPPER_VERSION)

Instance Method Summary collapse

Constructor Details

#new(src, filename = "(ripper)", lineno = 1) ⇒ Object

Create a new Ripper object. src must be a String, an IO, or an Object which has #gets method.

This method does not starts parsing. See also Ripper#parse and Ripper.parse.



# File 'parse.c'

static VALUE
ripper_initialize(int argc, VALUE *argv, VALUE self)
{
struct parser_params *parser;
VALUE src, fname, lineno;

TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
rb_scan_args(argc, argv, "12", &src, &fname, &lineno);
if (rb_obj_respond_to(src, ripper_id_gets, 0)) {
    parser->parser_lex_gets = ripper_lex_get_generic;
}

Instance Method Details

#columnInteger

Return column number of current parsing line. This number starts from 0.

Returns:



# File 'parse.c'

static VALUE
ripper_column(VALUE self)
{
struct parser_params *parser;
long col;

TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
if (!ripper_initialized_p(parser)) {
    rb_raise(rb_eArgError, "method called for uninitialized object");
}

#encodingEncoding

Return encoding of the source.

Returns:



# File 'parse.c'

VALUE
rb_parser_encoding(VALUE vparser)
{
    struct parser_params *parser;

    TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser);
    return rb_enc_from_encoding(parser->enc);
}

#end_seen?Boolean

Return true if parsed source ended by _END_.

Returns:

  • (Boolean)


# File 'parse.c'

VALUE
rb_parser_end_seen_p(VALUE vparser)
{
    struct parser_params *parser;

    TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser);
    return ruby__end__seen ? Qtrue : Qfalse;
}

#filenameString

Return current parsing filename.

Returns:



# File 'parse.c'

static VALUE
ripper_filename(VALUE self)
{
struct parser_params *parser;

TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
if (!ripper_initialized_p(parser)) {
    rb_raise(rb_eArgError, "method called for uninitialized object");
}

#linenoInteger

Return line number of current parsing line. This number starts from 1.

Returns:



# File 'parse.c'

static VALUE
ripper_lineno(VALUE self)
{
struct parser_params *parser;

TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
if (!ripper_initialized_p(parser)) {
    rb_raise(rb_eArgError, "method called for uninitialized object");
}

#parseObject

Start parsing and returns the value of the root action.



# File 'parse.c'

static VALUE
ripper_parse(VALUE self)
{
struct parser_params *parser;

TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
if (!ripper_initialized_p(parser)) {
    rb_raise(rb_eArgError, "method called for uninitialized object");
}

#yydebugBoolean

Get yydebug.

Returns:

  • (Boolean)


# File 'parse.c'

VALUE
rb_parser_get_yydebug(VALUE self)
{
    struct parser_params *parser;

    TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
    return yydebug ? Qtrue : Qfalse;
}

#yydebug=(flag) ⇒ Object

Set yydebug.



# File 'parse.c'

VALUE
rb_parser_set_yydebug(VALUE self, VALUE flag)
{
    struct parser_params *parser;

    TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
    yydebug = RTEST(flag);
    return flag;
}