summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dhall_syntax/src/core/expr.rs35
-rw-r--r--dhall_syntax/src/core/mod.rs2
-rw-r--r--dhall_syntax/src/core/span.rs44
3 files changed, 46 insertions, 35 deletions
diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs
index 2ad3ba8..70ce1dc 100644
--- a/dhall_syntax/src/core/expr.rs
+++ b/dhall_syntax/src/core/expr.rs
@@ -1,4 +1,3 @@
-use std::rc::Rc;
use crate::map::{DupTreeMap, DupTreeSet};
use crate::visitor::{self, ExprFMutVisitor, ExprFVisitor};
@@ -15,40 +14,6 @@ pub fn trivial_result<T>(x: Result<T, !>) -> T {
}
}
-/// A location in the source text
-#[derive(Debug, Clone)]
-pub struct Span {
- input: Rc<str>,
- /// # Safety
- ///
- /// Must be a valid character boundary index into `input`.
- start: usize,
- /// # Safety
- ///
- /// Must be a valid character boundary index into `input`.
- end: usize,
-}
-
-impl Span {
- pub(crate) fn make(input: Rc<str>, sp: pest::Span) -> Self {
- Span {
- input,
- start: sp.start(),
- 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};
- Span {
- input: self.input.clone(),
- start: min(self.start, other.start),
- end: max(self.start, other.start),
- }
- }
-}
-
/// Double with bitwise equality
#[derive(Debug, Copy, Clone)]
pub struct NaiveDouble(f64);
diff --git a/dhall_syntax/src/core/mod.rs b/dhall_syntax/src/core/mod.rs
index fe2c0be..66bf229 100644
--- a/dhall_syntax/src/core/mod.rs
+++ b/dhall_syntax/src/core/mod.rs
@@ -4,6 +4,8 @@ mod import;
pub use import::*;
mod label;
pub use label::*;
+mod span;
+pub use span::*;
mod text;
pub use text::*;
pub mod context;
diff --git a/dhall_syntax/src/core/span.rs b/dhall_syntax/src/core/span.rs
new file mode 100644
index 0000000..ad5a3a9
--- /dev/null
+++ b/dhall_syntax/src/core/span.rs
@@ -0,0 +1,44 @@
+use std::rc::Rc;
+
+/// A location in the source text
+#[derive(Debug, Clone)]
+pub struct ParsedSpan {
+ input: Rc<str>,
+ /// # Safety
+ ///
+ /// Must be a valid character boundary index into `input`.
+ start: usize,
+ /// # Safety
+ ///
+ /// Must be a valid character boundary index into `input`.
+ end: usize,
+}
+
+/// A location in the source text
+#[derive(Debug, Clone)]
+pub enum Span {
+ Parsed(ParsedSpan),
+}
+
+impl Span {
+ pub(crate) fn make(input: Rc<str>, sp: pest::Span) -> Self {
+ Span::Parsed(ParsedSpan {
+ input,
+ start: sp.start(),
+ 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 {
+ input: x.input.clone(),
+ start: min(x.start, y.start),
+ end: max(x.start, y.start),
+ }),
+ }
+ }
+}