diff options
| author | Martin Haug <mhaug@live.de> | 2021-11-02 12:06:22 +0100 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2021-11-02 12:06:22 +0100 |
| commit | 1e4cab393e55df8875c6303ebb7bde8f09f911c9 (patch) | |
| tree | 72d3bf30e24971efa5f7e2505ebfc009b3c85d1b /src/syntax/span.rs | |
| parent | 52761a3baa901865b1fc42366017740cfa7eb566 (diff) | |
Introduce incremental parsing
Diffstat (limited to 'src/syntax/span.rs')
| -rw-r--r-- | src/syntax/span.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/syntax/span.rs b/src/syntax/span.rs index 4d5b8819..a707d3d9 100644 --- a/src/syntax/span.rs +++ b/src/syntax/span.rs @@ -125,6 +125,17 @@ impl Span { *self = self.join(other) } + /// Create a new span with n characters inserted inside of this span. + pub fn inserted(mut self, other: Self, n: usize) -> Self { + if !self.contains(other.start) || !self.contains(other.end) { + panic!(); + } + + let len_change = (n as isize - other.len() as isize) as usize; + self.end += len_change; + self + } + /// Test whether a position is within the span. pub fn contains(&self, pos: usize) -> bool { self.start <= pos && self.end >= pos |
