From 89c66abc6da8a68c65f89069a6ade3baa40074e8 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 1 Jun 2020 10:15:19 -0700 Subject: [PATCH 1/2] Document shebang restriction. --- src/crates-and-source-files.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/crates-and-source-files.md b/src/crates-and-source-files.md index 1fb842555..e1c1e70cb 100644 --- a/src/crates-and-source-files.md +++ b/src/crates-and-source-files.md @@ -9,7 +9,7 @@ > **Lexer**\ > UTF8BOM : `\uFEFF`\ -> SHEBANG : `#!` ~[`[` `\n`] ~`\n`\* +> SHEBANG : `#!` \~`\n`\+[†](#shebang) > Note: Although Rust, like any other language, can be implemented by an @@ -65,10 +65,14 @@ apply to the crate as a whole. #![warn(non_camel_case_types)] ``` +## Byte order mark + The optional [_UTF8 byte order mark_] (UTF8BOM production) indicates that the file is encoded in UTF8. It can only occur at the beginning of the file and is ignored by the compiler. +## Shebang + A source file can have a [_shebang_] (SHEBANG production), which indicates to the operating system what program to use to execute this file. It serves essentially to treat the source file as an executable script. The shebang @@ -84,6 +88,13 @@ fn main() { } ``` +There are two restrictions imposed on the shebang syntax to avoid confusion +with an [attribute]. The shebang line must have at least one non-[whitespace] +character anywhere after the `#!` characters. Additionally, The `#!` +characters must not be followed by a `[` token, ignoring intervening +[comments] or [whitespace]. If either of these restrictions fails, then it is +not treated as a shebang, but instead as the start of an attribute. + ## Preludes and `no_std` All crates have a *prelude* that automatically inserts names from a specific @@ -166,8 +177,10 @@ or `-` (U+002D) characters. [`std::prelude::v1`]: ../std/prelude/index.html [attribute]: attributes.md [attributes]: attributes.md +[comments]: comments.md [function]: items/functions.md [module]: items/modules.md [module path]: paths.md [trait or lifetime bounds]: trait-bounds.md [where clauses]: items/generics.md#where-clauses +[whitespace]: whitespace.md From 277587a55aa24d8f6a66ddb43493e150c916ef43 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 2 Jul 2020 07:44:39 -0700 Subject: [PATCH 2/2] Update shebang restrictions. --- src/crates-and-source-files.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/crates-and-source-files.md b/src/crates-and-source-files.md index e1c1e70cb..ffb2ba60c 100644 --- a/src/crates-and-source-files.md +++ b/src/crates-and-source-files.md @@ -88,11 +88,9 @@ fn main() { } ``` -There are two restrictions imposed on the shebang syntax to avoid confusion -with an [attribute]. The shebang line must have at least one non-[whitespace] -character anywhere after the `#!` characters. Additionally, The `#!` -characters must not be followed by a `[` token, ignoring intervening -[comments] or [whitespace]. If either of these restrictions fails, then it is +A restriction is imposed on the shebang syntax to avoid confusion with an +[attribute]. The `#!` characters must not be followed by a `[` token, ignoring +intervening [comments] or [whitespace]. If this restriction fails, then it is not treated as a shebang, but instead as the start of an attribute. ## Preludes and `no_std`