mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Adds three new AST nodes to the mix: - `TemplateString` represents a t-string in Python 3.14 - `TemplateStringPart` represents one of the string constituents of a t-string. (The interpolated expressions are represented as `Expr` nodes, just like f-strings.) - `JoinedTemplateString` represents an implicit concatenation of template strings. Importantly, we _completely avoid_ the complicated construction we currently do for format strings (as well as the confusing nomenclature). No extra injection of empty strings (so that a template string is a strict alternation of strings and expressions). A `JoinedTemplateString` simply has a list of template string children, and a `TemplateString` has a list of "values" which may be either `Expr` or `TemplateStringPart` nodes. If we ever find that we actually want the more complicated interface for these strings, then I would much rather we reconstruct this inside of QL rather than in the parser.
18 lines
323 B
Python
18 lines
323 B
Python
name = "World"
|
|
value = 42.5678
|
|
first = "first"
|
|
second = "second"
|
|
|
|
if 1:
|
|
t""
|
|
if 2:
|
|
t"Hello, {name}!"
|
|
if 3:
|
|
t"Value: {value:.2f}, Hex: {value:#x}"
|
|
if 4:
|
|
t"Just a regular string."
|
|
if 5:
|
|
t"Multiple {first} and {second} placeholders."
|
|
if 6:
|
|
t"Implicit concatenation: " t"Hello, {name}!" t" How are you?"
|