Project

General

Profile

Feature #19015 ยป heredoc_extension.patch

ko1 (Koichi Sasada), 09/22/2022 03:23 AM

View differences:

parse.y
uint8_t quote;
uint8_t func;
#endif
bool shebang;
};
STATIC_ASSERT(rb_strterm_heredoc_t, sizeof(rb_strterm_heredoc_t) <= 4 * SIZEOF_VALUE);
......
%token <node> tNTH_REF "numbered reference"
%token <node> tBACK_REF "back reference"
%token <node> tSTRING_CONTENT "literal content"
%token <node> tSTRING_EXTEND_HEREDOC "Heredoc extension"
%token <num> tREGEXP_END
%type <node> singleton strings string string1 xstring regexp
......
;
string_content : tSTRING_CONTENT
/*% ripper[brace]: ripper_new_yylval(p, 0, get_value($1), $1) %*/
{
$$ = $1;
/*% ripper[brace]: ripper_new_yylval(p, 0, get_value($1), $1) %*/
}
| tSTRING_EXTEND_HEREDOC
{
// TODO: use delimiter token for function call
$$ = NEW_FCALL(rb_intern("heredoc_extension_erb"),
list_append(p,
NEW_LIST(NEW_LIT($1->nd_lit, &@$), &@$),
NEW_FCALL(rb_intern("binding"), NULL, &@$)),
&@$);
}
| tSTRING_DVAR
{
/* need to backup p->lex.strterm so that a string literal `%&foo,#$&,bar&` can be parsed */
......
int c = nextc(p), term, func = 0, quote = 0;
enum yytokentype token = tSTRING_BEG;
int indent = 0;
bool shebang = 0;
if (c == '-') {
c = nextc(p);
......
offset++;
indent = INT_MAX;
}
if (c == '!') {
c = nextc(p);
offset++;
shebang = true;
}
switch (c) {
case '\'':
func |= str_squote; goto quoted;
......
here->length = (int)len;
here->quote = quote;
here->func = func;
here->shebang = shebang;
token_flush(p);
p->heredoc_indent = indent;
......
#ifndef RIPPER
if (bol) yylval.node->flags |= NODE_FL_NEWLINE;
#endif
return tSTRING_CONTENT;
if (here->shebang) {
return tSTRING_EXTEND_HEREDOC;
}
else {
return tSTRING_CONTENT;
}
}
#include "lex.c"
    (1-1/1)