diff options
Diffstat (limited to 'crates/ra_syntax/src/parser_api.rs')
-rw-r--r-- | crates/ra_syntax/src/parser_api.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/parser_api.rs b/crates/ra_syntax/src/parser_api.rs index 0f740963d..3487aef85 100644 --- a/crates/ra_syntax/src/parser_api.rs +++ b/crates/ra_syntax/src/parser_api.rs | |||
@@ -142,11 +142,13 @@ impl Marker { | |||
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
145 | /// Finishes the syntax tree node and assigns `kind` to it. | 145 | /// Finishes the syntax tree node and assigns `kind` to it, |
146 | /// and mark the create a `CompletedMarker` for possible future | ||
147 | /// operation like `.precede()` to deal with forward_parent. | ||
146 | pub(crate) fn complete(mut self, p: &mut Parser, kind: SyntaxKind) -> CompletedMarker { | 148 | pub(crate) fn complete(mut self, p: &mut Parser, kind: SyntaxKind) -> CompletedMarker { |
147 | self.bomb.defuse(); | 149 | self.bomb.defuse(); |
148 | p.0.complete(self.pos, kind); | 150 | p.0.complete(self.pos, kind); |
149 | CompletedMarker(self.pos, kind) | 151 | CompletedMarker::new(self.pos, kind) |
150 | } | 152 | } |
151 | 153 | ||
152 | /// Abandons the syntax tree node. All its children | 154 | /// Abandons the syntax tree node. All its children |
@@ -160,13 +162,22 @@ impl Marker { | |||
160 | pub(crate) struct CompletedMarker(u32, SyntaxKind); | 162 | pub(crate) struct CompletedMarker(u32, SyntaxKind); |
161 | 163 | ||
162 | impl CompletedMarker { | 164 | impl CompletedMarker { |
163 | /// This one is tricky :-) | 165 | fn new(pos: u32, kind: SyntaxKind) -> Self { |
166 | CompletedMarker(pos, kind) | ||
167 | } | ||
168 | |||
164 | /// This method allows to create a new node which starts | 169 | /// This method allows to create a new node which starts |
165 | /// *before* the current one. That is, parser could start | 170 | /// *before* the current one. That is, parser could start |
166 | /// node `A`, then complete it, and then after parsing the | 171 | /// node `A`, then complete it, and then after parsing the |
167 | /// whole `A`, decide that it should have started some node | 172 | /// whole `A`, decide that it should have started some node |
168 | /// `B` before starting `A`. `precede` allows to do exactly | 173 | /// `B` before starting `A`. `precede` allows to do exactly |
169 | /// that. See also docs about `forward_parent` in `Event::Start`. | 174 | /// that. See also docs about `forward_parent` in `Event::Start`. |
175 | /// | ||
176 | /// Given completed events `[START, FINISH]` and its corresponding | ||
177 | /// `CompletedMarker(pos: 0, _)`. | ||
178 | /// Append a new `START` events as `[START, FINISH, NEWSTART]`, | ||
179 | /// then mark `NEWSTART` as `START`'s parent with saving its relative | ||
180 | /// distance to `NEWSTART` into forward_parent(=2 in this case); | ||
170 | pub(crate) fn precede(self, p: &mut Parser) -> Marker { | 181 | pub(crate) fn precede(self, p: &mut Parser) -> Marker { |
171 | Marker::new(p.0.precede(self.0)) | 182 | Marker::new(p.0.precede(self.0)) |
172 | } | 183 | } |