Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make lastline and nextline to be rb_parser_string #9631

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion ext/ripper/ripper_init.c.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,13 @@ ripper_token(VALUE self)
{
struct parser_params *p = ripper_parser_params(self, true);
long pos, len;
VALUE str;

if (NIL_P(rb_ruby_parser_parsing_thread(p))) return Qnil;
pos = rb_ruby_ripper_column(p);
len = rb_ruby_ripper_token_len(p);
return rb_str_subseq(rb_ruby_ripper_lex_lastline(p), pos, len);
str = rb_str_new_parser_string(rb_ruby_ripper_lex_lastline(p));
return rb_str_subseq(str, pos, len);
}

#ifdef RIPPER_DEBUG
Expand Down
5 changes: 3 additions & 2 deletions internal/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef struct rb_strterm_literal_struct {
} rb_strterm_literal_t;

typedef struct rb_strterm_heredoc_struct {
VALUE lastline; /* the string of line that contains `<<"END"` */
rb_parser_string_t *lastline; /* the string of line that contains `<<"END"` */
long offset; /* the column of END in `<<"END"` */
int sourceline; /* lineno of the line that contains `<<"END"` */
unsigned length; /* the length of END in `<<"END"` */
Expand Down Expand Up @@ -65,6 +65,7 @@ RUBY_SYMBOL_EXPORT_BEGIN
VALUE rb_ruby_parser_encoding(rb_parser_t *p);
int rb_ruby_parser_end_seen_p(rb_parser_t *p);
int rb_ruby_parser_set_yydebug(rb_parser_t *p, int flag);
rb_parser_string_t *rb_str_to_parser_string(rb_parser_t *p, VALUE str);

RUBY_SYMBOL_EXPORT_END

Expand Down Expand Up @@ -96,7 +97,7 @@ int rb_ruby_ripper_initialized_p(rb_parser_t *p);
void rb_ruby_ripper_parser_initialize(rb_parser_t *p);
long rb_ruby_ripper_column(rb_parser_t *p);
long rb_ruby_ripper_token_len(rb_parser_t *p);
VALUE rb_ruby_ripper_lex_lastline(rb_parser_t *p);
rb_parser_string_t *rb_ruby_ripper_lex_lastline(rb_parser_t *p);
VALUE rb_ruby_ripper_lex_state_name(struct parser_params *p, int state);
struct parser_params *rb_ruby_ripper_parser_allocate(void);
#endif
Expand Down
4 changes: 4 additions & 0 deletions internal/ruby_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ enum lex_state_e {
EXPR_NONE = 0
};

RUBY_SYMBOL_EXPORT_BEGIN
VALUE rb_str_new_parser_string(rb_parser_string_t *str);
RUBY_SYMBOL_EXPORT_END

VALUE rb_node_sym_string_val(const NODE *);
VALUE rb_node_line_lineno_val(const NODE *);
VALUE rb_node_file_path_val(const NODE *);
Expand Down