You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This contains the interpolated string expression segments `"val = {"`, `"}; 2 * val = "`, and `"."`, the first of which factors in the presence of the open/close brace escape sequences described in the grammar below. The quoted text also contains the interpolations `"{val,4:X}"` and `"{2 * val}"`.
1408
1408
1409
-
Interpolated string expressions have two forms; regular (*interpolated_regular_string_expression*)
1410
-
and verbatim (*interpolated_verbatim_string_expression*); which are lexically similar to, but differ semantically from, the two forms of string
An *interpolated_string_expression* has one of the following forms; regular (*interpolated_regular_string_expression*),
1410
+
verbatim (*interpolated_verbatim_string_expression*), and raw (*interpolated_raw_string_expression*); which are lexically similar to, but differ semantically from, the corresponding forms of string literals ([§6.4.5.6](lexical-structure.md#6456-string-literals)).
1412
1411
1413
1412
```ANTLR
1414
1413
interpolated_string_expression
1415
1414
: interpolated_regular_string_expression
1416
1415
| interpolated_verbatim_string_expression
1416
+
| interpolated_raw_string_expression
1417
1417
;
1418
1418
1419
1419
// interpolated regular string expressions
@@ -1518,16 +1518,79 @@ fragment Open_Brace_Escape_Sequence
Six of the lexical rules defined above are *context sensitive* as follows:
1585
+
A number of the lexical rules defined above are *context sensitive* as follows:
1524
1586
1525
1587
|**Rule**|**Contextual Requirements**|
1526
1588
| :------- | :-------------------------- |
1527
1589
|*Interpolated_Regular_String_Mid*| Only recognised after an *Interpolated_Regular_String_Start*, between any following interpolations, and before the corresponding *Interpolated_Regular_String_End*. |
1528
1590
|*Regular_Interpolation_Format*| Only recognised within a *regular_interpolation* and when the starting colon (:) is not nested within any kind of bracket (parentheses/braces/square). |
1529
1591
|*Interpolated_Regular_String_End*| Only recognised after an *Interpolated_Regular_String_Start* and only if any intervening tokens are either *Interpolated_Regular_String_Mid*s or tokens that can be part of *regular_interpolation*s, including tokens for any *interpolated_regular_string_expression*s contained within such interpolations. |
1530
-
|*Interpolated_Verbatim_String_Mid**Verbatim_Interpolation_Format**Interpolated_Verbatim_String_End*| Recognition of these three rules follows that of the corresponding rules above with each mentioned *regular* grammar rule replaced by the corresponding *verbatim* one. |
1592
+
|*Interpolated_Verbatim_String_Mid**Verbatim_Interpolation_Format**Interpolated_Verbatim_String_End*| Recognition of these three rules follows that of the corresponding first three rules above with each mentioned *regular* grammar rule replaced by the corresponding *verbatim* one. |
1593
+
|*Interpolated_Raw_String_Mid**Raw_Interpolation_Format**Interpolated_Raw_String_End*| Recognition of these three rules follows that of the corresponding first three rules above with each mentioned *regular* grammar rule replaced by the corresponding *raw* one. |
1531
1594
1532
1595
> *Note*: The above rules are context sensitive as their definitions overlap with those of
The remainder of this subclause deals with the default interpolated string handler behavior only. The declaration and use of custom interpolated string handlers is described in [§23.5.9.1](attributes.md#23591-custom-interpolated-string-expression-handlers).
1566
1629
1567
-
The meaning of an interpolation, both *regular_interpolation* and *verbatim_interpolation*, is to format the value of the *expression* as a `string` either according to the format specified by the *Regular_Interpolation_Format*or *Verbatim_Interpolation_Format*, or according to a default format for the type of *expression*. The formatted string is then modified by the *interpolation_minimum_width*, if any, to produce the final `string` to be interpolated into the *interpolated_string_expression*.
1630
+
The meaning of an interpolation (*regular_interpolation*, *verbatim_interpolation*, and *raw_interpolation*) is to format the value of the *expression* as a `string` either according to the format specified by the *Regular_Interpolation_Format*, *Verbatim_Interpolation_Format*, or *Raw_Interpolation_Format*, or according to a default format for the type of *expression*. The formatted string is then modified by the *interpolation_minimum_width*, if any, to produce the final `string` to be interpolated into the *interpolated_string_expression*.
1568
1631
1569
1632
In an *interpolation_minimum_width* the *constant_expression* shall have an implicit conversion to `int`. Let the *field width* be the absolute value of this *constant_expression* and the *alignment* be the sign (positive or negative) of the value of this *constant_expression*:
1570
1633
@@ -1577,17 +1640,17 @@ The interpolated string expression is treated as a *format string literal* with
1577
1640
1578
1641
The format string literal is constructed as follows, where `N` is the number of interpolations in the *interpolated_string_expression*. The format string literal consists of, in order:
1579
1642
1580
-
- The characters of the *Interpolated_Regular_String_Start*or *Interpolated_Verbatim_String_Start*
1581
-
- The characters of the *Interpolated_Regular_String_Mid*or *Interpolated_Verbatim_String_Mid*, if any
1643
+
- The characters of the *Interpolated_Regular_String_Start*, *Interpolated_Verbatim_String_Start*, or *Interpolated_Raw_String_Start*
1644
+
- The characters of the *Interpolated_Regular_String_Mid*, *Interpolated_Verbatim_String_Mid*, or *Interpolated_Raw_String_Mid*, if any
1582
1645
- Then if `N ≥ 1` for each number `I` from `0` to `N-1`:
1583
1646
- A placeholder specification:
1584
1647
- A left brace (`{`) character
1585
1648
- The decimal representation of `I`
1586
-
- Then, if the corresponding *regular_interpolation*or *verbatim_interpolation* has a *interpolation_minimum_width*, a comma (`,`) followed by the decimal representation of the value of the *constant_expression*
1587
-
- The characters of the *Regular_Interpolation_Format*or *Verbatim_Interpolation_Format*, if any, of the corresponding *regular_interpolation*or *verbatim_interpolation*
1649
+
- Then, if the corresponding *regular_interpolation*, *verbatim_interpolation*, or *raw_interpolation* has a *interpolation_minimum_width*, a comma (`,`) followed by the decimal representation of the value of the *constant_expression*
1650
+
- The characters of the *Regular_Interpolation_Format*, *Verbatim_Interpolation_Format*, or *Raw_Interpolation_Format*, if any, of the corresponding *regular_interpolation*, *verbatim_interpolation*, or *raw_interpolation*
1588
1651
- A right brace (`}`) character
1589
-
- The characters of the *Interpolated_Regular_String_Mid*or *Interpolated_Verbatim_String_Mid* immediately following the corresponding interpolation, if any
1590
-
- Finally the characters of the *Interpolated_Regular_String_End*or *Interpolated_Verbatim_String_End*.
1652
+
- The characters of the *Interpolated_Regular_String_Mid*, *Interpolated_Verbatim_String_Mid*, or *Interpolated_Raw_String_Mid* immediately following the corresponding interpolation, if any
1653
+
- Finally the characters of the *Interpolated_Regular_String_End*, *Interpolated_Verbatim_String_End*, or *Interpolated_Raw_String_End*.
1591
1654
1592
1655
The subsequent arguments are the *expression*s from the interpolations, if any, in order.
1593
1656
@@ -1625,6 +1688,9 @@ Then:
1625
1688
|`$"{text + '?'} {number % 3}"`|`string.Format("{0} {1}", text + '?', number % 3)`|`"red? 2"`|
1626
1689
|`$"{text + $"[{number}]"}"`|`string.Format("{0}", text + string.Format("[{0}]", number))`|`"red[14]"`|
0 commit comments