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
The source for 1 and 2 is in [`ast_src.rs`](https://github.com/rust-analyzer/rust-analyzer/blob/a0be39296d2925972cacd9fbf8b5fb258fad6947/xtask/src/ast_src.rs).
57
64
58
65
## Code Walk-Through
59
66
60
67
### `crates/ra_syntax`, `crates/ra_parser`
61
68
62
69
Rust syntax tree structure and parser. See
63
-
[RFC](https://github.com/rust-lang/rfcs/pull/2256) for some design notes.
70
+
[RFC](https://github.com/rust-lang/rfcs/pull/2256)and [./syntax.md](./syntax.md)for some design notes.
64
71
65
72
-[rowan](https://github.com/rust-analyzer/rowan) library is used for constructing syntax trees.
66
73
-`grammar` module is the actual parser. It is a hand-written recursive descent parser, which
67
74
produces a sequence of events like "start node X", "finish node Y". It works similarly to [kotlin's parser](https://github.com/JetBrains/kotlin/blob/4d951de616b20feca92f3e9cc9679b2de9e65195/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java),
68
75
which is a good source of inspiration for dealing with syntax errors and incomplete input. Original [libsyntax parser](https://github.com/rust-lang/rust/blob/6b99adeb11313197f409b4f7c4083c2ceca8a4fe/src/libsyntax/parse/parser.rs)
69
76
is what we use for the definition of the Rust language.
70
-
-`parser_api/parser_impl` bridges the tree-agnostic parser from `grammar` with `rowan` trees.
71
-
This is the thing that turns a flat list of events into a tree (see `EventProcessor`)
77
+
-`TreeSink` and `TokenSource` traits bridge the tree-agnostic parser from `grammar` with `rowan` trees.
72
78
-`ast` provides a type safe API on top of the raw `rowan` tree.
73
-
-`grammar.ron` RON description of the grammar, which is used to
74
-
generate `syntax_kinds` and `ast` modules, using `cargo xtask codegen` command.
75
-
-`algo`: generic tree algorithms, including `walk` for O(1) stack
76
-
space tree traversal (this is cool).
79
+
-`ast_src` description of the grammar, which is used to generate `syntax_kinds`
80
+
and `ast` modules, using `cargo xtask codegen` command.
77
81
78
82
Tests for ra_syntax are mostly data-driven: `test_data/parser` contains subdirectories with a bunch of `.rs`
79
83
(test vectors) and `.txt` files with corresponding syntax trees. During testing, we check
80
84
`.rs` against `.txt`. If the `.txt` file is missing, it is created (this is how you update
81
85
tests). Additionally, running `cargo xtask codegen` will walk the grammar module and collect
82
86
all `// test test_name` comments into files inside `test_data/parser/inline` directory.
0 commit comments