aboutsummaryrefslogtreecommitdiff
path: root/rfc.md
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2017-12-22 13:28:04 +0000
committerAleksey Kladov <[email protected]>2017-12-22 13:28:04 +0000
commit6ff019c25f027be1bf2896ce82659dc8d99515f8 (patch)
treed1c256805acb5e487d556f4b3a281470a25b8414 /rfc.md
parentb878f3b636365aa9af327fea1aebf97d34cc87dd (diff)
Add minimal syntax tree implementation
Diffstat (limited to 'rfc.md')
-rw-r--r--rfc.md22
1 files changed, 20 insertions, 2 deletions
diff --git a/rfc.md b/rfc.md
index 9b7c79991..1476cbaf2 100644
--- a/rfc.md
+++ b/rfc.md
@@ -80,7 +80,10 @@ simpler ones.
80 80
81In contrast, for IDEs it is crucial to have a lossless view of the 81In contrast, for IDEs it is crucial to have a lossless view of the
82source code because, for example, it's important to preserve comments 82source code because, for example, it's important to preserve comments
83during refactorings. 83during refactorings. Ideally, IDEs should be able to incrementally
84relex and reparse the file as the user types, because syntax tree is
85necessary to correctly handle certain code-editing actions like
86autoindentation or joining lines.
84 87
85Currently rustc uses the AST approach, which preserves the source code 88Currently rustc uses the AST approach, which preserves the source code
86information to some extent by storing spans in the AST. 89information to some extent by storing spans in the AST.
@@ -98,7 +101,7 @@ Not applicable.
98 101
99This section proposes a new syntax tree data structure, which should 102This section proposes a new syntax tree data structure, which should
100be suitable for both compiler and IDE. It is heavily inspired by [PSI] 103be suitable for both compiler and IDE. It is heavily inspired by [PSI]
101data structure which used in [IntelliJ] based IDEs and in the Kotlin 104data structure which used in [IntelliJ] based IDEs and in the [Kotlin]
102compiler. 105compiler.
103 106
104 107
@@ -107,6 +110,21 @@ compiler.
107[Kotlin]: https://kotlinlang.org/ 110[Kotlin]: https://kotlinlang.org/
108 111
109 112
113The main idea is to store the minimal amount of information in the
114tree itself, and instead lean heavily on the source code string for
115the actual data about identifier names, constant values etc.
116
117All nodes in the tree are of the same type and store a constant for
118the syntactic category of the element and a range in the source code.
119
120Here is a minimal implementation of this data structure:
121
122
123```Rust
124```
125
126
127
110# Drawbacks 128# Drawbacks
111[drawbacks]: #drawbacks 129[drawbacks]: #drawbacks
112 130