Class: Ripper
Constant Summary collapse
- Version =
version of Ripper
rb_usascii_str_new2(RIPPER_VERSION)
Instance Method Summary collapse
-
#column ⇒ Integer
Return column number of current parsing line.
-
#encoding ⇒ Encoding
Return encoding of the source.
-
#end_seen? ⇒ Boolean
Return true if parsed source ended by _END_.
-
#filename ⇒ String
Return current parsing filename.
-
#new(src, filename = "(ripper)", lineno = 1) ⇒ Object
constructor
Create a new Ripper object.
-
#lineno ⇒ Integer
Return line number of current parsing line.
-
#parse ⇒ Object
Start parsing and returns the value of the root action.
-
#yydebug ⇒ Boolean
Get yydebug.
-
#yydebug=(flag) ⇒ Object
Set yydebug.
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.
11399 11400 11401 11402 11403 11404 11405 11406 11407 11408 11409 11410 11411 11412 11413 11414 11415 11416 11417 11418 11419 11420 11421 11422 11423 11424 11425 11426 11427 11428 11429 |
# File 'parse.y', line 11399 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)) { parser->parser_lex_gets = ripper_lex_get_generic; } else { StringValue(src); parser->parser_lex_gets = lex_get_str; } parser->parser_lex_input = src; parser->eofp = Qfalse; if (NIL_P(fname)) { fname = STR_NEW2("(ripper)"); } else { StringValue(fname); } parser_initialize(parser); parser->parser_ruby_sourcefile_string = fname; parser->parser_ruby_sourcefile = RSTRING_PTR(fname); parser->parser_ruby_sourceline = NIL_P(lineno) ? 0 : NUM2INT(lineno) - 1; return Qnil; } |
Instance Method Details
#column ⇒ Integer
Return column number of current parsing line. This number starts from 0.
11492 11493 11494 11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 |
# File 'parse.y', line 11492 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 - parser->parser_lex_pbeg; return LONG2NUM(col); } |
#encoding ⇒ Encoding
Return encoding of the source.
10994 10995 10996 10997 10998 10999 11000 11001 |
# File 'parse.y', line 10994 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); } |
#end_seen? ⇒ Boolean
Return true if parsed source ended by _END_.
10979 10980 10981 10982 10983 10984 10985 10986 |
# File 'parse.y', line 10979 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; } |
#filename ⇒ String
Return current parsing filename.
11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 |
# File 'parse.y', line 11513 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 parser->parser_ruby_sourcefile_string; } |
#lineno ⇒ Integer
Return line number of current parsing line. This number starts from 1.
11532 11533 11534 11535 11536 11537 11538 11539 11540 11541 11542 11543 |
# File 'parse.y', line 11532 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(parser->parser_ruby_sourceline); } |
#parse ⇒ Object
Start parsing and returns the value of the root action.
11464 11465 11466 11467 11468 11469 11470 11471 11472 11473 11474 11475 11476 11477 11478 11479 11480 11481 11482 11483 |
# File 'parse.y', line 11464 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; } |
#yydebug ⇒ Boolean
Get yydebug.
11009 11010 11011 11012 11013 11014 11015 11016 |
# File 'parse.y', line 11009 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.
11024 11025 11026 11027 11028 11029 11030 11031 11032 |
# File 'parse.y', line 11024 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; } |