You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/input-format.md
+18-1
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,41 @@
1
1
# Input format
2
2
3
+
r[input]
4
+
5
+
r[input.intro]
3
6
This chapter describes how a source file is interpreted as a sequence of tokens.
4
7
5
8
See [Crates and source files] for a description of how programs are organised into files.
6
9
7
10
## Source encoding
8
11
12
+
r[input.encoding]
13
+
14
+
r[input.encoding.utf8]
9
15
Each source file is interpreted as a sequence of Unicode characters encoded in UTF-8.
16
+
17
+
r[input.encoding.invalid]
10
18
It is an error if the file is not valid UTF-8.
11
19
12
20
## Byte order mark removal
13
21
22
+
r[input.byte-order-mark]
23
+
14
24
If the first character in the sequence is `U+FEFF` ([BYTE ORDER MARK]), it is removed.
15
25
16
26
## CRLF normalization
17
27
28
+
r[input.crlf]
29
+
18
30
Each pair of characters `U+000D` (CR) immediately followed by `U+000A` (LF) is replaced by a single `U+000A` (LF).
19
31
20
32
Other occurrences of the character `U+000D` (CR) are left in place (they are treated as [whitespace]).
21
33
22
34
## Shebang removal
23
35
36
+
r[input.shebang]
37
+
38
+
r[input.shebang.intro]
24
39
If the remaining sequence begins with the characters `#!`, the characters up to and including the first `U+000A` (LF) are removed from the sequence.
25
40
26
41
For example, the first line of the following file would be ignored:
@@ -34,15 +49,17 @@ fn main() {
34
49
}
35
50
```
36
51
52
+
r[input.shebang.inner-attribute]
37
53
As an exception, if the `#!` characters are followed (ignoring intervening [comments] or [whitespace]) by a `[` token, nothing is removed.
38
54
This prevents an [inner attribute] at the start of a source file being removed.
39
55
40
56
> **Note**: The standard library [`include!`] macro applies byte order mark removal, CRLF normalization, and shebang removal to the file it reads. The [`include_str!`] and [`include_bytes!`] macros do not.
41
57
42
58
## Tokenization
43
59
44
-
The resulting sequence of characters is then converted into tokens as described in the remainder of this chapter.
60
+
r[input.tokenization]
45
61
62
+
The resulting sequence of characters is then converted into tokens as described in the remainder of this chapter.
0 commit comments