Support for the Ruby 2.4 series has ended. See here for reference.
static VALUE parser_dedent_string(VALUE self, VALUE input, VALUE width) { int wid, col; StringValue(input); wid = NUM2UINT(width); col = dedent_string(input, wid); return INT2NUM(col); }
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
.
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_TYPE_P(src, T_FILE)) { lex_gets = ripper_lex_io_get; } else if (rb_respond_to(src, id_gets)) { lex_gets = ripper_lex_get_generic; } else { StringValue(src); lex_gets = lex_get_str; } lex_input = src; parser->eofp = 0; if (NIL_P(fname)) { fname = STR_NEW2("(ripper)"); OBJ_FREEZE(fname); } else { StringValue(fname); fname = rb_str_new_frozen(fname); } parser_initialize(parser); ruby_sourcefile_string = fname; ruby_sourcefile = RSTRING_PTR(fname); ruby_sourceline = NIL_P(lineno) ? 0 : NUM2INT(lineno) - 1; return Qnil; }
Return column number of current parsing line. This number starts from 0.
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"); } if (NIL_P(parser->parsing_thread)) return Qnil; col = parser->tokp - lex_pbeg; return LONG2NUM(col); }
Return encoding of the source.
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(current_enc); }
Return true if parsed source ended by +_END_+.
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; }
Return true if parsed source has errors.
static VALUE ripper_error_p(VALUE vparser) { struct parser_params *parser; TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser); return parser->error_p ? Qtrue : Qfalse; }
Return current parsing filename.
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"); } return ruby_sourcefile_string; }
Return line number of current parsing line. This number starts from 1.
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"); } if (NIL_P(parser->parsing_thread)) return Qnil; return INT2NUM(ruby_sourceline); }
Start parsing and returns the value of the root action.
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"); } if (!NIL_P(parser->parsing_thread)) { if (parser->parsing_thread == rb_thread_current()) rb_raise(rb_eArgError, "Ripper#parse is not reentrant"); else rb_raise(rb_eArgError, "Ripper#parse is not multithread-safe"); } parser->parsing_thread = rb_thread_current(); rb_ensure(ripper_parse0, self, ripper_ensure, self); return parser->result; }