Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DO NOT MERGE -- Tag strings #103766

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

Closed
wants to merge 12 commits into from
Closed
Prev Previous commit
Next Next commit
Pass lambdas (not quite thunks, but a step in the right direction)
  • Loading branch information
gvanrossum committed May 3, 2022
commit 1c36df7e8908b5fa075d55695c2275bfcc31a176
31 changes: 26 additions & 5 deletions 31 Parser/action_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,26 +869,47 @@ _PyPegen_seq_delete_starred_exprs(Parser *p, asdl_seq *kwargs)
return new_seq;
}

static expr_ty
lambdafy(Parser *p, expr_ty arg)
{
assert(arg->kind == FormattedValue_kind);
arguments_ty args = _PyPegen_empty_arguments(p);
if (args == NULL)
return NULL;
return _PyAST_Lambda(args, arg,
arg->lineno, arg->col_offset, arg->end_lineno, arg->end_col_offset,
p->arena);
}

expr_ty
_PyPegen_tag_string(Parser *p, expr_ty tag, Token *tok)
{
// No prefixes (f, r, b, u)
// Parse like fstring
// Create a node similar to f-string AST
asdl_generic_seq *tokens = _Py_asdl_generic_seq_new(1, p->arena);
if (tokens == NULL)
return NULL;
asdl_seq_SET(tokens, 0, tok);
expr_ty str = _PyPegen_concatenate_strings(p, (asdl_seq *)tokens, 1);
if (str == NULL)
return NULL;
if (str->kind == JoinedStr_kind) {
// Transform FormattedValue items into thunks
asdl_expr_seq *values = str->v.JoinedStr.values;
int nvalues = asdl_seq_LEN(values);
for (int i = 0; i < nvalues; i++) {
expr_ty value = asdl_seq_GET(values, i);
if (value->kind == FormattedValue_kind) {
value = lambdafy(p, value);
if (value == NULL)
return NULL;
asdl_seq_SET(values, i, value);
}
}
}
return _PyAST_TagString(tag, str,
tag->lineno, tag->col_offset, str->end_lineno, str->end_col_offset,
p->arena);

}


expr_ty
_PyPegen_concatenate_strings(Parser *p, asdl_seq *strings, int tagged)
{
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.