diff options
author | Nadrieril | 2019-11-11 11:20:32 +0000 |
---|---|---|
committer | Nadrieril | 2019-11-11 13:50:36 +0000 |
commit | b68c3af578d1f6b0d1e32e7d88ef57774fb468d8 (patch) | |
tree | d35a77d82657928e817fa2541edb6dcbe8455266 /dhall_syntax/src/core/span.rs | |
parent | a8cb6926cbafb2ac806f7bec27a29b0528ed5056 (diff) |
Capture absence of span in Span itself
Diffstat (limited to '')
-rw-r--r-- | dhall_syntax/src/core/span.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/dhall_syntax/src/core/span.rs b/dhall_syntax/src/core/span.rs index f0eb89a..fc8de6e 100644 --- a/dhall_syntax/src/core/span.rs +++ b/dhall_syntax/src/core/span.rs @@ -14,10 +14,14 @@ pub struct ParsedSpan { end: usize, } -/// A location in the source text #[derive(Debug, Clone)] pub enum Span { + /// A location in the source text Parsed(ParsedSpan), + /// For expressions obtained from decoding binary + Decoded, + /// For expressions constructed during normalization/typecheck + Artificial, } impl Span { @@ -28,17 +32,22 @@ impl Span { end: sp.end(), }) } + /// Takes the union of the two spans. Assumes that the spans come from the same input. /// This will also capture any input between the spans. pub fn union(&self, other: &Span) -> Self { use std::cmp::{max, min}; use Span::*; match (self, other) { - (Parsed(x), Parsed(y)) => Span::Parsed(ParsedSpan { + (Parsed(x), Parsed(y)) => Parsed(ParsedSpan { input: x.input.clone(), start: min(x.start, y.start), end: max(x.end, y.end), }), + _ => panic!( + "Tried to union incompatible spans: {:?} and {:?}", + self, other + ), } } } |