Skip to content

Commit 4d032a7

Browse files
committed
Move shebang into its own subchapter
In #2192, we extended our documentation about shebangs but kept it in Input Format under a section on shebang removal. But really, this section is mostly now about documenting what a shebang is, for our purposes. Let's separate this out into a new subchapter. We'll keep the rule about shebang removal in Input Format; it can link to Shebang for a description of what a shebang is, its grammar, etc. This follows the pattern that we'll similarly be using for frontmatter.
1 parent caa4205 commit 4d032a7

4 files changed

Lines changed: 38 additions & 30 deletions

File tree

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- [Lexical structure](lexical-structure.md)
88
- [Input format](input-format.md)
9+
- [Shebang](shebang.md)
910
- [Keywords](keywords.md)
1011
- [Identifiers](identifiers.md)
1112
- [Comments](comments.md)

src/crates-and-source-files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,6 @@ The crate name must not be empty, and must only contain [Unicode alphanumeric] o
137137
[module]: items/modules.md
138138
[module path]: paths.md
139139
[panic-docs]: panic.md#unwinding-across-ffi-boundaries
140-
[shebang]: input-format.md#shebang-removal
140+
[shebang]: shebang.md
141141
[trait or lifetime bounds]: trait-bounds.md
142142
[where clauses]: items/generics.md#where-clauses

src/input-format.md

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,8 @@ Other occurrences of the character `U+000D` (CR) are left in place (they are tre
4141
r[input.shebang]
4242
## Shebang removal
4343

44-
r[input.shebang.intro]
45-
A *[shebang]* is an optional line that is typically used in Unix-like systems to specify an interpreter for executing the file.
46-
47-
> [!EXAMPLE]
48-
> <!-- ignore: tests don't like shebang -->
49-
> ```rust,ignore
50-
> #!/usr/bin/env rustx
51-
>
52-
> fn main() {
53-
> println!("Hello!");
54-
> }
55-
> ```
56-
57-
r[input.shebang.syntax]
58-
```grammar,lexer
59-
@root SHEBANG ->
60-
`#!` !((WHITESPACE | LINE_COMMENT | BLOCK_COMMENT)* `[`)
61-
~LF* (LF | EOF)
62-
```
63-
64-
The shebang starts with the characters `#!` and extends through the first `U+000A` (LF) or through EOF if no LF is present. If the `#!` characters are followed by `[` (ignoring any intervening [comments] or [whitespace]), the line is not considered a shebang (to avoid ambiguity with an [inner attribute]).
65-
66-
r[input.shebang.position]
67-
The shebang may appear immediately at the start of the file or after the optional [byte order mark].
68-
6944
r[input.shebang.removal]
70-
The shebang is removed from the input sequence (and is therefore ignored).
45+
If a [shebang] is present, it is removed from the input sequence (and is therefore ignored).
7146

7247
r[input.tokenization]
7348
## Tokenization
@@ -83,9 +58,7 @@ The resulting sequence of characters is then converted into tokens as described
8358
>
8459
> The [`include_str!`] and [`include_bytes!`] macros do not apply these transformations.
8560
86-
[inner attribute]: attributes.md
8761
[BYTE ORDER MARK]: https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8
88-
[comments]: comments.md
8962
[Crates and source files]: crates-and-source-files.md
90-
[shebang]: https://en.wikipedia.org/wiki/Shebang_(Unix)
63+
[shebang]: shebang.md
9164
[whitespace]: whitespace.md

src/shebang.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
r[shebang]
2+
# Shebang
3+
4+
r[shebang.syntax]
5+
```grammar,lexer
6+
@root SHEBANG ->
7+
`#!` !((WHITESPACE | LINE_COMMENT | BLOCK_COMMENT)* `[`)
8+
~LF* (LF | EOF)
9+
```
10+
11+
r[shebang.intro]
12+
A *[shebang]* is an optional line that is typically used in Unix-like systems to specify an interpreter for executing the file.
13+
14+
> [!EXAMPLE]
15+
> <!-- ignore: tests don't like shebang -->
16+
> ```rust,ignore
17+
> #!/usr/bin/env rustx
18+
>
19+
> fn main() {
20+
> println!("Hello!");
21+
> }
22+
> ```
23+
24+
r[shebang.syntax-description]
25+
The shebang starts with the characters `#!` and extends through the first `U+000A` (LF) or through EOF if no LF is present. If the `#!` characters are followed by `[` (ignoring any intervening [comments] or [whitespace]), the line is not considered a shebang (to avoid ambiguity with an [inner attribute]).
26+
27+
r[shebang.position]
28+
The shebang may appear immediately at the start of the file or after the optional [byte order mark].
29+
30+
[byte order mark]: https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8
31+
[comments]: comments.md
32+
[inner attribute]: attributes.md
33+
[shebang]: https://en.wikipedia.org/wiki/Shebang_(Unix)
34+
[whitespace]: whitespace.md

0 commit comments

Comments
 (0)