diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-10-05 12:49:39 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-10-05 12:49:39 +0200 |
| commit | ec884ec1d85f6e1d7868db3e82d572579cc5d345 (patch) | |
| tree | 92819f3a31abd6fdcd6b01adcd367bad344bef13 /src/parse/incremental.rs | |
| parent | 5a8534a395b500a25cbc46ee15ec031c8231de59 (diff) | |
Refactor syntax module
Diffstat (limited to 'src/parse/incremental.rs')
| -rw-r--r-- | src/parse/incremental.rs | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/parse/incremental.rs b/src/parse/incremental.rs index 06096a75..e0be9b6d 100644 --- a/src/parse/incremental.rs +++ b/src/parse/incremental.rs @@ -96,11 +96,10 @@ fn try_reparse( && (ahead.is_none() || change.replaced.start > child_span.end) && !ahead.map_or(false, Ahead::is_compulsory) { - ahead = - Some(Ahead::new(pos, at_start, child.kind().is_bounded())); + ahead = Some(Ahead::new(pos, at_start, is_bounded(child.kind()))); } - at_start = child.kind().is_at_start(at_start); + at_start = next_at_start(child.kind(), at_start); } } SearchState::Inside(start) => { @@ -137,7 +136,7 @@ fn try_reparse( if let SearchState::Contained(pos) = search { // Do not allow replacement of elements inside of constructs whose // opening and closing brackets look the same. - let safe_inside = node.kind().is_bounded(); + let safe_inside = is_bounded(node.kind()); let child = &mut node.children_mut()[pos.idx]; let prev_len = child.len(); let prev_descendants = child.descendants(); @@ -384,6 +383,36 @@ enum ReparseMode { MarkupElements { at_start: bool, min_indent: usize }, } +/// Whether changes _inside_ this node are safely encapsulated, so that only +/// this node must be reparsed. +fn is_bounded(kind: &NodeKind) -> bool { + match kind { + NodeKind::CodeBlock + | NodeKind::ContentBlock + | NodeKind::Backslash + | NodeKind::Tilde + | NodeKind::HyphQuest + | NodeKind::Hyph2 + | NodeKind::Hyph3 + | NodeKind::Dot3 + | NodeKind::Quote { .. } + | NodeKind::BlockComment + | NodeKind::Space { .. } + | NodeKind::Escape(_) => true, + _ => false, + } +} + +/// Whether `at_start` would still be true after this node given the +/// previous value of the property. +fn next_at_start(kind: &NodeKind, prev: bool) -> bool { + match kind { + NodeKind::Space { newlines: (1 ..) } => true, + NodeKind::Space { .. } | NodeKind::LineComment | NodeKind::BlockComment => prev, + _ => false, + } +} + #[cfg(test)] #[rustfmt::skip] mod tests { |
