Skip to content

Commit d8af1f7

Browse files
matkladmark-i-m
authored andcommitted
write a short paragraph about the new lexer
1 parent 831a469 commit d8af1f7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/the-parser.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ To minimise the amount of copying that is done, both the `StringReader` and
3232
`Parser` have lifetimes which bind them to the parent `ParseSess`. This contains
3333
all the information needed while parsing, as well as the `SourceMap` itself.
3434

35+
## More on Lexical Analysis
36+
37+
Code for lexical analysis is split between two crates:
38+
39+
- `rustc_lexer` crate is responsible for breaking a `&str` into chunks
40+
constituting tokens. Although it is popular to implement lexers as generated
41+
finite state machines, the lexer in `rustc_lexer` is hand-written.
42+
43+
- [`StringReader`] from [libsyntax] integrates `rustc_lexer` with `rustc`
44+
specific data structures. Specifically, it adds `Span` information to tokens
45+
returned by `rustc_lexer` and interns identifiers.
46+
47+
3548
[libsyntax]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/index.html
3649
[rustc_errors]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/index.html
3750
[ast]: https://en.wikipedia.org/wiki/Abstract_syntax_tree

0 commit comments

Comments
 (0)