diff options
-rw-r--r-- | dhall_syntax/src/core/span.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/dhall_syntax/src/core/span.rs b/dhall_syntax/src/core/span.rs index d10a53d..4012cfb 100644 --- a/dhall_syntax/src/core/span.rs +++ b/dhall_syntax/src/core/span.rs @@ -33,8 +33,9 @@ impl Span { }) } - /// 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. + /// Takes the union of the two spans, i.e. the range of input covered by the two spans plus any + /// input between them. Assumes that the spans come from the same input. Fails if one of the + /// spans does not point to an input location. pub fn union(&self, other: &Span) -> Self { use std::cmp::{max, min}; use Span::*; @@ -51,6 +52,17 @@ impl Span { } } + /// Merges two spans assumed to point to a similar thing. If only one of them points to an + /// input location, use that one. + pub fn merge(&self, other: &Span) -> Self { + use Span::*; + match (self, other) { + (Parsed(x), _) | (_, Parsed(x)) => Parsed(x.clone()), + (Artificial, _) | (_, Artificial) => Artificial, + (Decoded, Decoded) => Decoded, + } + } + pub fn error(&self, message: impl Into<String>) -> String { use pest::error::{Error, ErrorVariant}; use pest::Span; |