Skip to content

Commit 1d55d6d

Browse files
authored
Merge pull request #2192 from ehuss/shebang
Update shebang
2 parents 0a1928e + c6f8a7f commit 1d55d6d

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

src/input-format.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,32 @@ r[input.shebang]
4242
## Shebang removal
4343

4444
r[input.shebang.intro]
45-
If the remaining sequence begins with the characters `#!`, the characters up to and including the first `U+000A` (LF) are removed from the sequence.
45+
A *[shebang]* is an optional line that is typically used in Unix-like systems to specify an interpreter for executing the file.
4646

47-
For example, the first line of the following file would be ignored:
48-
49-
<!-- ignore: tests don't like shebang -->
50-
```rust,ignore
51-
#!/usr/bin/env rustx
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+
> ```
5256
53-
fn main() {
54-
println!("Hello!");
55-
}
57+
r[input.shebang.syntax]
58+
```grammar,lexer
59+
@root SHEBANG ->
60+
`#!` !((WHITESPACE | LINE_COMMENT | BLOCK_COMMENT)* `[`)
61+
~LF* (LF | EOF)
5662
```
5763
58-
r[input.shebang.inner-attribute]
59-
As an exception, if the `#!` characters are followed (ignoring intervening [comments] or [whitespace]) by a `[` token, nothing is removed. This prevents an [inner attribute] at the start of a source file being removed.
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+
69+
r[input.shebang.removal]
70+
The shebang is removed from the input sequence (and is therefore ignored).
6071

6172
r[input.tokenization]
6273
## Tokenization
@@ -76,5 +87,5 @@ The resulting sequence of characters is then converted into tokens as described
7687
[BYTE ORDER MARK]: https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8
7788
[comments]: comments.md
7889
[Crates and source files]: crates-and-source-files.md
79-
[_shebang_]: https://en.wikipedia.org/wiki/Shebang_(Unix)
90+
[shebang]: https://en.wikipedia.org/wiki/Shebang_(Unix)
8091
[whitespace]: whitespace.md

src/whitespace.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ r[lex.whitespace]
33

44
r[whitespace.syntax]
55
```grammar,lexer
6-
@root WHITESPACE ->
6+
WHITESPACE ->
77
U+0009 // Horizontal tab, `'\t'`
88
| U+000A // Line feed, `'\n'`
99
| U+000B // Vertical tab

0 commit comments

Comments
 (0)