From 2ca4648bf6260be6d30db150969df7f34dce9dc2 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Wed, 7 Oct 2026 14:12:45 -0400 Subject: [PATCH] Add support for ignored directives --- standard/lexical-structure.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/standard/lexical-structure.md b/standard/lexical-structure.md index 37f4deec7..934a2eba3 100644 --- a/standard/lexical-structure.md +++ b/standard/lexical-structure.md @@ -1211,7 +1211,7 @@ unsigned_right_shift_assignment ### 6.5.1 General -The pre-processing directives provide the ability to conditionally skip sections of compilation units, to report error and warning conditions, to delineate distinct regions of source code, and to set the nullable context. +The pre-processing directives provide the ability to conditionally skip sections of compilation units, to report error and warning conditions, to delineate distinct regions of source code, to set the nullable context, and to assist tools. > *Note*: The term “pre-processing directives” is used only for consistency with the C and C++ programming languages. In C#, there is no separate pre-processing step; pre-processing directives are processed as part of the lexical analysis phase. *end note* @@ -1228,6 +1228,7 @@ fragment PP_Kind | PP_Region | PP_Pragma | PP_Nullable + | PP_Ignored ; // Only recognised at the beginning of a line @@ -1265,8 +1266,9 @@ The following pre-processing directives are available: - `#region` and `#endregion`, which are used to explicitly mark sections of source code ([§6.5.7](lexical-structure.md#657-region-directives)). - `#nullable`, which is used to specify the nullable context ([§6.5.9](lexical-structure.md#659-nullable-directive)). - `#pragma`, which is used to specify optional contextual information to a compiler ([§6.5.10](lexical-structure.md#6510-pragma-directives)). +- `#!` and `#:`, which designate ignored directives that are intended to assist implementation-specific tools (§ignored-directives). -A pre-processing directive always occupies a separate line of source code and always begins with a `#` character and a pre-processing directive name. White space may occur before the `#` character and between the `#` character and the directive name. +A pre-processing directive always occupies a separate line of source code and always begins with a `#` character and a pre-processing directive name. Except for a `#!`-form ignored directive, white space may occur before the `#` character and between the `#` character and the directive name. A source line containing a `#define`, `#undef`, `#if`, `#elif`, `#else`, `#endif`, `#line`, `#endregion`, or `#nullable` directive can end with a single-line comment. Delimited comments (the `/* */` style of comments) are not permitted on source lines containing pre-processing directives. @@ -1836,3 +1838,20 @@ fragment PP_Pragma_Text The *Input_Character*s in the *PP_Pragma_Text* are interpreted by a compiler in an implementation-defined manner. The information supplied in a `#pragma` directive shall not change program semantics. A `#pragma` directive shall only change compiler behavior that is outside the scope of this language specification. If a compiler cannot interpret the *Input_Character*s, a compiler can produce a warning; however, it shall not produce a compile-time error. > *Note*: *PP_Pragma_Text* can contain arbitrary text; specifically, it need not contain well-formed tokens. *end note* + +### §ignored-directives Ignored directives + +These preprocessing directives are intended for tools whose nature and purpose are outside the scope of this specification. + +```ANTLR +PP_Ignored + : PP_IgnoredToken Input_Character* + ; + +PP_IgnoredToken + : '!' + | ':' + ; +``` + +Ignored directives shall occur before the first *token* in a *compilation_unit*.