diff options
author | Nadrieril Feneanar | 2019-09-19 10:54:11 +0200 |
---|---|---|
committer | GitHub | 2019-09-19 10:54:11 +0200 |
commit | 4daead27eb65e3a38869924f0f3ed1f425de1b33 (patch) | |
tree | 06effc0f10795a208e929bdf9fdbbbfa6d94cc31 /dhall_syntax/src/core | |
parent | bcaeab3b7b114d8782be9589ad673ab9ab8c59fd (diff) | |
parent | bf417fadb206d6d2351a13cd7c6988977a46dd33 (diff) |
Merge pull request #113 from Nadrieril/pest_consume
Extract parser macros into an independent crate
Diffstat (limited to '')
-rw-r--r-- | dhall_syntax/src/core/expr.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index 2cb23c9..74b481f 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -37,6 +37,16 @@ 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}; + Span { + input: self.input.clone(), + start: min(self.start, other.start), + end: max(self.start, other.start), + } + } } /// Double with bitwise equality @@ -324,8 +334,11 @@ impl<E> Expr<E> { pub fn as_mut(&mut self) -> &mut RawExpr<E> { &mut self.0.as_mut().0 } + pub fn span(&self) -> Option<Span> { + self.0.as_ref().1.clone() + } - pub fn new(x: RawExpr<E>, n: Span) -> Self { + pub(crate) fn new(x: RawExpr<E>, n: Span) -> Self { Expr(Box::new((x, Some(n)))) } @@ -384,13 +397,6 @@ pub fn rc<E>(x: RawExpr<E>) -> Expr<E> { Expr::from_expr_no_span(x) } -pub(crate) fn spanned<E>(span: Span, x: RawExpr<E>) -> Expr<E> { - Expr::new(x, span) -} -pub(crate) fn unspanned<E>(x: RawExpr<E>) -> Expr<E> { - Expr::from_expr_no_span(x) -} - /// Add an isize to an usize /// Panics on over/underflow fn add_ui(u: usize, i: isize) -> Option<usize> { |