@@ -30,13 +30,16 @@ we'll talk about that later.
30
30
to the rest of the compilation process as a [ ` rustc_interface::Config ` ] .
31
31
- The raw Rust source text is analyzed by a low-level lexer located in
32
32
[ ` librustc_lexer ` ] . At this stage, the source text is turned into a stream of
33
- atomic source code units known as _ tokens_ . The lexer supports the Unicode
34
- character encoding.
33
+ atomic source code units known as _ tokens_ . The lexer supports the
34
+ Unicode character encoding.
35
35
- The token stream passes through a higher-level lexer located in
36
36
[ ` librustc_parse ` ] to prepare for the next stage of the compile process. The
37
37
[ ` StringReader ` ] struct is used at this stage to perform a set of validations
38
38
and turn strings into interned symbols.
39
- - ** TODO** : Add lexer error information / error handling documentation
39
+ - The lexer has a small interface and doesn't depend directly on the
40
+ diagnostic infrastructure in ` rustc ` . Instead it provides diagnostics as plain
41
+ data which are emitted in ` librustc_parse::lexer::mod ` as real diagnostics.
42
+ - The lexer preseves full fidelity information for both IDEs and proc macros.
40
43
- The parser [ translates the token stream from the lexer into an Abstract Syntax
41
44
Tree (AST)] [ parser ] . It uses a recursive descent (top-down) approach to syntax
42
45
analysis. The crate entry points for the parser are the ` Parser.parse_crate_mod() ` and
@@ -46,26 +49,21 @@ we'll talk about that later.
46
49
- Parsing is performed with a set of ` Parser ` utility methods including ` fn bump ` ,
47
50
` fn check ` , ` fn eat ` , ` fn expect ` , ` fn look_ahead ` .
48
51
- Parsing is organized by the semantic construct that is being parsed. Separate
49
- ` parse_* ` methods can be found in ` librustc_parse ` ` parser ` directory. File
50
- naming follows the construct name. For example, the following files are found
52
+ ` parse_* ` methods can be found in ` librustc_parse ` ` parser ` directory. The source
53
+ file name follows the construct name. For example, the following files are found
51
54
in the parser:
52
55
- ` expr.rs `
53
56
- ` pat.rs `
54
57
- ` ty.rs `
55
58
- ` stmt.rs `
56
- - This naming scheme is used across the parser, lowering, type checking,
57
- HAIR lowering, & MIR building stages of the compile process and you will
58
- find either a file or directory with the same name for most of these constructs
59
- at each of these stages of compilation.
60
- - For error handling, the parser uses the standard ` DiagnosticBuilder ` API, but we
59
+ - This naming scheme is used across many compiler stages. You will find
60
+ either a file or directory with the same name across the parsing, lowering,
61
+ type checking, HAIR lowering, and MIR building sources.
62
+ - Macro expansion, AST validation, name resolution, and early linting takes place
63
+ during this stage of the compile process.
64
+ - The parser uses the standard ` DiagnosticBuilder ` API for error handling, but we
61
65
try to recover, parsing a superset of Rust's grammar, while also emitting an error.
62
- - The ` rustc_ast::ast::{Crate, Mod, Expr, Pat, ...} ` AST node returned from the parser.
63
-
64
- - macro expansion (** TODO** chrissimpkins)
65
- - ast validation (** TODO** chrissimpkins)
66
- - nameres (** TODO** chrissimpkins)
67
- - early linting (** TODO** chrissimpkins)
68
-
66
+ - ` rustc_ast::ast::{Crate, Mod, Expr, Pat, ...} ` AST nodes are returned from the parser.
69
67
- We then take the AST and [ convert it to High-Level Intermediate
70
68
Representation (HIR)] [ hir ] . This is a compiler-friendly representation of the
71
69
AST. This involves a lot of desugaring of things like loops and ` async fn ` .
0 commit comments