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

Add rb_parser_set_pos function #5089

Merged
merged 4 commits into from
Dec 16, 2021

Conversation

S-H-GAMELINKS
Copy link
Contributor

@S-H-GAMELINKS S-H-GAMELINKS commented Nov 6, 2021

rb_parser_set_location_from_strterm_heredoc, rb_parser_set_location_of_none and rb_parser_set_location functions has similar code(like this).

    yylloc->beg_pos.lineno = p->ruby_sourceline;
    yylloc->beg_pos.column = (int)(p->lex.ptok - p->lex.pbeg);
    yylloc->end_pos.lineno = p->ruby_sourceline;
    yylloc->end_pos.column = (int)(p->lex.pcur - p->lex.pbeg);
    return yylloc;

I think better to cut out these similar code to function like rb_parser_set_pos, but how about it?

YYLTYPE *
rb_parser_set_pos(YYLTYPE *yylloc, int sourceline, int beg_pos, int end_pos)
{
    yylloc->beg_pos.lineno = sourceline;
    yylloc->beg_pos.column = beg_pos;
    yylloc->end_pos.lineno = sourceline;
    yylloc->end_pos.column = end_pos;
    return yylloc;
}

parse.y Outdated Show resolved Hide resolved
parse.y Outdated Show resolved Hide resolved
Co-authored-by: Marivaldo Cavalheiro <marivaldo@gmail.com>
@nobu
Copy link
Member

nobu commented Nov 7, 2021

Why is rb_parser_set_pos global?

@S-H-GAMELINKS
Copy link
Contributor Author

S-H-GAMELINKS commented Nov 7, 2021

@nobu

Why is rb_parser_set_pos global?

Sorry, I forgot add static modifier.

@nobu nobu merged commit 9b187fe into ruby:master Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants