summaryrefslogtreecommitdiff
path: root/dhall_syntax
diff options
context:
space:
mode:
authorNadrieril2019-11-11 13:42:31 +0000
committerNadrieril2019-11-11 13:50:37 +0000
commit207d10c4b7d838d712b135dca56bc31f3fe5b648 (patch)
tree54cd7e703e3c340390563554ad96ed04faa68a64 /dhall_syntax
parentd28d114552e6c6cb913dce48893fa87e87bf11e2 (diff)
Clarify Span::union and add Span::merge
Diffstat (limited to 'dhall_syntax')
-rw-r--r--dhall_syntax/src/core/span.rs16
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;