Skip to content

Commit dbc39fe

Browse files
committed
Apply delta from PR #1564 (Extended line directive) - 6 new review commits
1 parent c99e5f5 commit dbc39fe

1 file changed

Lines changed: 22 additions & 29 deletions

File tree

standard/lexical-structure.md

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,6 @@ then the *type_argument_list* shall be retained as part of the disambiguated pro
137137
138138
When recognising a *relational_expression* ([§12.15.1](expressions.md#12151-general)) if both the “*relational_expression* `is` *type*” and “*relational_expression* `is` *pattern*” alternatives are applicable, and *type* resolves to an accessible type, then the “*relational_expression* `is` *type*” alternative shall be chosen.
139139
140-
To differentiate a collection initializer ([§12.8.17.3.1](expressions.md#1281731-collection-initializers)) with an element assignment, from a collection initializer with a lambda expression, the parser shall look ahead. Consider the following:
141-
142-
```csharp
143-
var y = new C { [A] = x }; // OK: y[A] = x
144-
var z = new C { [A] x => x }; // OK: z[0] = [A] x => x
145-
```
146-
147-
The parser shall treat `?[` as the start of a *null_conditional_element_access* ([[§12.8.13](expressions.md#12813-null-conditional-element-access)):
148-
149-
```csharp
150-
x = b ? [A]; // OK
151-
y = b ? [A] () => { } : z; // error
152-
```
153-
154-
To differentiate a method call `T()` from a lambda expression `T () => e`, the parser shall look ahead.
155-
156140
## 6.3 Lexical analysis
157141
158142
### 6.3.1 General
@@ -1112,7 +1096,7 @@ The following pre-processing directives are available:
11121096

11131097
- `#define` and `#undef`, which are used to define and undefine, respectively, conditional compilation symbols ([§6.5.4](lexical-structure.md#654-definition-directives)).
11141098
- `#if`, `#elif`, `#else`, and `#endif`, which are used to skip conditionally sections of source code ([§6.5.5](lexical-structure.md#655-conditional-compilation-directives)).
1115-
- `#line`, which is used to control line numbers emitted for errors and warnings ([§6.5.8](lexical-structure.md#658-line-directives)).
1099+
- `#line`, which is used to control line numbers and source file mapping emitted for errors and warnings (§6.5.8).
11161100
- `#error`, which is used to issue errors ([§6.5.6](lexical-structure.md#656-diagnostic-directives)).
11171101
- `#region` and `#endregion`, which are used to explicitly mark sections of source code ([§6.5.7](lexical-structure.md#657-region-directives)).
11181102
- `#nullable`, which is used to specify the nullable context ([§6.5.9](lexical-structure.md#659-nullable-directive)).
@@ -1573,35 +1557,44 @@ The maximum value allowed for `Decimal_Digit+` is implementation-defined.
15731557
15741558
A `#line default` directive undoes the effect of all preceding `#line` directives. A compiler reports true line information for subsequent lines, precisely as if no `#line` directives had been processed.
15751559
1576-
A `#line hidden` directive has no effect on the compilation unit and line numbers reported in error messages, or produced by use of `CallerLineNumberAttribute` ([§23.5.6.2](attributes.md#23562-the-callerlinenumber-attribute)). It is intended to affect source-level debugging tools so that, when debugging, all lines between a `#line hidden` directive and the subsequent `#line` directive (that is not `#line hidden`) have no line number information, and are skipped entirely when stepping through code.
1560+
A `#line hidden` directive has no effect on the source location information reported in error messages, or produced by use of `CallerLineNumberAttribute` ([§23.5.6.2](attributes.md#23562-the-callerlinenumber-attribute)). It is intended to affect source-level debugging tools so that, when debugging, all lines between a `#line hidden` directive and the subsequent `#line` directive (that is not `#line hidden`) have no line number information, and are skipped entirely when stepping through code.
15771561
15781562
> *Note*: Although a *PP_Compilation_Unit_Name* might contain text that looks like an escape sequence, such text is not an escape sequence; in this context a ‘`\`’ character simply designates an ordinary backslash character. *end note*
15791563
1580-
Together, the tokens *Start_Line_Character* '-' *PP_End_Line_Character* specify a span of characters in the so-called mapped file *PP_Compilation_Unit_Name*.
1564+
Together, the tokens *PP_Start_Line_Character* '-' *PP_End_Line_Character* specify a span of characters in the source file identified by *PP_Compilation_Unit_Name* (the ***mapped file***).
15811565
1582-
*PP_Start_Line_Character* represents the start line (*PP_Start_Line*) and column (*PP_Start_Character*) pair of the first character on the line following the directive, which is the mapped file text; for example, `(1,1)`.
1566+
*PP_Start_Line_Character* represents a start position in the mapped file, specified as a line (*PP_Start_Line*) and column (*PP_Start_Character*) pair; for example, `(1,1)`. This position corresponds to the first character on the line following the directive in the generated code.
15831567
1584-
*PP_End_Line_Character* represents the end line (*PP_End_Line*) and column (*PP_End_Character*) pair of the mapped file text; for example, `(3,10)`.
1568+
*PP_End_Line_Character* represents an end position in the mapped file, specified as a line (*PP_End_Line*) and column (*PP_End_Character*) pair; for example, `(3,10)`.
15851569
1586-
*PP_Start_Line* and *PP_End_Line* are positive integers that specify line numbers. *PP_Start_Character* and *PP_End_Character* are positive integers that specify UTF-16 character numbers. All four of these numbers are 1-based, meaning that the first line of the mapped file and the first UTF-16 character on each line is assigned number 1.
1570+
*PP_Start_Line* and *PP_End_Line* are positive integers that specify line numbers. *PP_Start_Character* and *PP_End_Character* are positive integers that specify character numbers. All four of these numbers are 1-based, meaning that the first line of the mapped file and the first character on each line is assigned number 1.
15871571
1588-
By default, the mapped text starts at the first character on the line following the `#line` directive. However, this can be adjusted using *PP_Character_Offset*. If *PP_Character_Offset* is omitted, it defaults to 0; otherwise, it specifies the number of UTF-16 characters to skip in that next line. That number shall be non-negative and less than the length of the line following the `#line` directive.
1572+
The end position shall not precede the start position: *PP_End_Line* shall be greater than or equal to *PP_Start_Line*, and when *PP_Start_Line* equals *PP_End_Line*, *PP_End_Character* shall be greater than *PP_Start_Character*.
1573+
1574+
By default, the mapped text starts at the first character on the line following the `#line` directive. However, this can be adjusted using *PP_Character_Offset*. If *PP_Character_Offset* is omitted, it defaults to 0; otherwise, it specifies the number of characters to skip in that next line. That number shall be non-negative and less than the length of the line following the `#line` directive.
15891575
15901576
The mapping specified by a *PP_Line* is in scope until the following `#line` directive or the end of the compilation unit, whichever comes first.
15911577
1592-
> *Example*: Consider the following:
1578+
> *Example*: A code generator that produces C# from a template file can use the enhanced form of the `#line` directive to map diagnostics back to positions in the original source. If line 5, columns 3 through 17 of `template.dsl` contains `Greet("Hello")`, the generator might emit:
15931579
>
1594-
> <!-- Example: {template:"standalone-console", name:"LineWithMapping"} -->
15951580
> ```csharp
1596-
> // exxample goes here
1581+
> #line (5,3)-(5,17) "template.dsl"
1582+
> output.Add(Greet("Hello"));
1583+
> #line default
15971584
> ```
15981585
>
1599-
> the output produced might be something like the following:
1586+
> Any diagnostic produced for the `output.Add(Greet("Hello"));` statement would be reported at line 5, columns 317 in `template.dsl`.
16001587
>
1601-
> ```console
1602-
> ???
1588+
> The *PP_Character_Offset* form allows the generator to account for an inserted prefix. With a character offset of `11` for the prefix `output.Add(`:
1589+
>
1590+
> ```csharp
1591+
> #line (5,3)-(5,17) 11 "template.dsl"
1592+
> output.Add(Greet("Hello"));
1593+
> #line default
16031594
> ```
16041595
>
1596+
> the offset causes the mapped span to begin at `Greet("Hello")` rather than at `output.Add(`, mapping `Greet("Hello")` to line 5, column 3 in `template.dsl`.
1597+
>
16051598
> *end example*
16061599
16071600
### 6.5.9 Nullable directive

0 commit comments

Comments
 (0)