ruby-changes:70262
From: S.H <ko1@a...>
Date: Thu, 16 Dec 2021 20:03:53 +0900 (JST)
Subject: [ruby-changes:70262] 9b187fec58 (master): Add `rb_parser_set_pos` function
https://git.ruby-lang.org/ruby.git/commit/?id=9b187fec58 From 9b187fec58daafc80164bc29c57dd306d053bcfe Mon Sep 17 00:00:00 2001 From: "S.H" <gamelinks007@g...> Date: Thu, 16 Dec 2021 20:03:44 +0900 Subject: Add `rb_parser_set_pos` function Co-authored-by: Nobuyoshi Nakada <nobu@r...> Co-authored-by: Marivaldo Cavalheiro <marivaldo@g...> --- parse.y | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/parse.y b/parse.y index 0bf7b9c9aff..7555d0db166 100644 --- a/parse.y +++ b/parse.y @@ -10835,6 +10835,16 @@ rb_parser_fatal(struct parser_params *p, const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/parse.y#L10835 p->debug = TRUE; } +static 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; +} + YYLTYPE * rb_parser_set_location_from_strterm_heredoc(struct parser_params *p, rb_strterm_heredoc_t *here, YYLTYPE *yylloc) { @@ -10843,31 +10853,25 @@ rb_parser_set_location_from_strterm_heredoc(struct parser_params *p, rb_strterm_ https://github.com/ruby/ruby/blob/trunk/parse.y#L10853 - (rb_strlen_lit("<<-") - !(here->func & STR_FUNC_INDENT)); int end_pos = (int)here->offset + here->length + here->quote; - yylloc->beg_pos.lineno = sourceline; - yylloc->beg_pos.column = beg_pos; - yylloc->end_pos.lineno = sourceline; - yylloc->end_pos.column = end_pos; - return yylloc; + return rb_parser_set_pos(yylloc, sourceline, beg_pos, end_pos); } YYLTYPE * rb_parser_set_location_of_none(struct parser_params *p, YYLTYPE *yylloc) { - 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.ptok - p->lex.pbeg); - return yylloc; + int sourceline = p->ruby_sourceline; + int beg_pos = (int)(p->lex.ptok - p->lex.pbeg); + int end_pos = (int)(p->lex.ptok - p->lex.pbeg); + return rb_parser_set_pos(yylloc, sourceline, beg_pos, end_pos); } YYLTYPE * rb_parser_set_location(struct parser_params *p, YYLTYPE *yylloc) { - 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; + int sourceline = p->ruby_sourceline; + int beg_pos = (int)(p->lex.ptok - p->lex.pbeg); + int end_pos = (int)(p->lex.pcur - p->lex.pbeg); + return rb_parser_set_pos(yylloc, sourceline, beg_pos, end_pos); } #endif /* !RIPPER */ -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/