Skip to content

Commit e16541a

Browse files
committed
Adapt compile.c changes
1 parent 0a23d67 commit e16541a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Python/compile.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4499,6 +4499,30 @@ compiler_joined_str(struct compiler *c, expr_ty e)
44994499
return SUCCESS;
45004500
}
45014501

4502+
/* Used to implement tag strings */
4503+
static int
4504+
compiler_tag_string(struct compiler *c, expr_ty e)
4505+
{
4506+
location loc = LOC(e);
4507+
if (e->kind == TagString_kind) {
4508+
expr_ty tag = e->v.TagString.tag;
4509+
expr_ty str = e->v.TagString.str;
4510+
if (tag->kind == Name_kind) {
4511+
if (str->kind == JoinedStr_kind) {
4512+
// Generate code for tag(str1, str2, ...)
4513+
asdl_keyword_seq *keywords =
4514+
_Py_asdl_keyword_seq_new(0, c->c_arena);
4515+
if (keywords == NULL)
4516+
return 0;
4517+
ADDOP(c, loc, PUSH_NULL);
4518+
VISIT(c, expr, tag);
4519+
return compiler_call_helper(c, loc, 0, str->v.JoinedStr.values, keywords);
4520+
}
4521+
}
4522+
}
4523+
return compiler_error(c, loc, "More complicated tag-string not yet supported");
4524+
}
4525+
45024526
/* Used to implement f-strings. Format a single value. */
45034527
static int
45044528
compiler_formatted_value(struct compiler *c, expr_ty e)
@@ -5420,6 +5444,8 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
54205444
break;
54215445
case JoinedStr_kind:
54225446
return compiler_joined_str(c, e);
5447+
case TagString_kind:
5448+
return compiler_tag_string(c, e);
54235449
case FormattedValue_kind:
54245450
return compiler_formatted_value(c, e);
54255451
/* The following exprs can be assignment targets. */

0 commit comments

Comments
 (0)