Perl / PPCs

This repository is for Requests For Comments - proposals to change the Perl language.
61 stars 22 forks source link

RFC 0019: template literals #19

Closed rjbs closed 2 years ago

haarg commented 2 years ago

It's implied that $scalar and @array interpolations would not happen in the qt string, but probably should be stated explicitly.

Also probably worth being explicit about how escape sequences work. Do all the normal backslash escapes work? And can the { be escaped to prevent it from being a template section?

rwp0 commented 2 years ago

Overall, LGTM give or take a couple of small comments.

One thing left unsaid is how to write a literal open-brace { character inside one of these quoted template strings. I suspect the answer would be qt{This is in \{literal braces\}} as per usual, but it would be good to spell that out in an example.

Or as qt({...}), no?

ivrntsv commented 2 years ago

About heredocs. Maybe qt infront of curly braces should be dropped (<<{END} instead of <<qt{END}). Curly braces are kind of a distinctive feature of template strings and Perl doesn't allow other general quote constructs like q, qq and qx as a heredoc modifier. Or maybe instead Perl should support all of them to make the thing more complete and explicit. But a bareword can serve as a heredoc delimiter so q, qq, qx and qt would be parsed as barewords. Parsing general quote constructs could be difficult. I prefer curly braces without prefix.

haarg commented 2 years ago

Or as qt({...}), no?

No. The delimiters for template sections are always { }, no matter what the outer delimiters are. So qt(a b {1 + 2} c) and qt{a b {1 + 2} c} would act the same.