Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ impl Assignment {
pub fn expression(&self) -> &Expression {
&self.expression
}

/// Access the span of the assignment.
pub fn span(&self) -> &Span {
&self.span
}
}

impl_eq_hash!(Assignment; pattern, expression);
Expand All @@ -149,6 +154,11 @@ impl Expression {
pub fn ty(&self) -> &ResolvedType {
&self.ty
}

/// Access the span of the expression.
pub fn span(&self) -> &Span {
&self.span
}
}

/// Variant of an expression.
Expand Down Expand Up @@ -192,6 +202,11 @@ impl SingleExpression {
pub fn ty(&self) -> &ResolvedType {
&self.ty
}

/// Access the span of the expression.
pub fn span(&self) -> &Span {
&self.span
}
}

impl_eq_hash!(SingleExpression; inner, ty);
Expand Down Expand Up @@ -243,6 +258,11 @@ impl Call {
pub fn args(&self) -> &Arc<[Expression]> {
&self.args
}

/// Access the span of the call.
pub fn span(&self) -> &Span {
&self.span
}
}

impl_eq_hash!(Call; name, args);
Expand Down Expand Up @@ -352,6 +372,11 @@ impl Match {
pub fn right(&self) -> &MatchArm {
&self.right
}

/// Access the span of the match statement.
pub fn span(&self) -> &Span {
&self.span
}
}

impl_eq_hash!(Match; scrutinee, left, right);
Expand Down Expand Up @@ -394,6 +419,11 @@ impl Module {
pub fn assignments(&self) -> &[ModuleAssignment] {
&self.assignments
}

/// Access the span of the module.
pub fn span(&self) -> &Span {
&self.span
}
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
Expand All @@ -413,6 +443,11 @@ impl ModuleAssignment {
pub fn value(&self) -> &Value {
&self.value
}

/// Access the span of the module.
pub fn span(&self) -> &Span {
&self.span
}
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
Expand Down
8 changes: 8 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ impl RichError {
file: Some(file),
}
}

pub fn error(&self) -> &Error {
&self.error
}

pub fn span(&self) -> &Span {
&self.span
}
}

impl fmt::Display for RichError {
Expand Down
45 changes: 45 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ impl Function {
pub fn body(&self) -> &Expression {
&self.body
}

/// Access the span of the function.
pub fn span(&self) -> &Span {
&self.span
}
}

impl_eq_hash!(Function; name, params, ret, body);
Expand Down Expand Up @@ -142,6 +147,11 @@ impl Assignment {
pub fn expression(&self) -> &Expression {
&self.expression
}

/// Access the span of the expression.
pub fn span(&self) -> &Span {
&self.span
}
}

impl_eq_hash!(Assignment; pattern, ty, expression);
Expand All @@ -164,6 +174,11 @@ impl Call {
pub fn args(&self) -> &[Expression] {
self.args.as_ref()
}

/// Access the span of the call.
pub fn span(&self) -> &Span {
&self.span
}
}

impl_eq_hash!(Call; name, args);
Expand Down Expand Up @@ -220,6 +235,11 @@ impl TypeAlias {
pub fn ty(&self) -> &AliasedType {
&self.ty
}

/// Access the span of the alias.
pub fn span(&self) -> &Span {
&self.span
}
}

impl_eq_hash!(TypeAlias; name, ty);
Expand All @@ -237,6 +257,11 @@ impl Expression {
&self.inner
}

/// Access the span of the expression.
pub fn span(&self) -> &Span {
&self.span
}

/// Convert the expression into a block expression.
#[cfg(feature = "arbitrary")]
fn into_block(self) -> Self {
Expand Down Expand Up @@ -275,6 +300,11 @@ impl SingleExpression {
pub fn inner(&self) -> &SingleExpressionInner {
&self.inner
}

/// Access the span of the expression.
pub fn span(&self) -> &Span {
&self.span
}
}

impl_eq_hash!(SingleExpression; inner);
Expand Down Expand Up @@ -341,6 +371,11 @@ impl Match {
&self.right
}

/// Access the span of the match statement.
pub fn span(&self) -> &Span {
&self.span
}

/// Get the type of the expression that is matched.
pub fn scrutinee_type(&self) -> AliasedType {
match (&self.left.pattern, &self.right.pattern) {
Expand Down Expand Up @@ -427,6 +462,11 @@ impl ModuleProgram {
pub fn items(&self) -> &[ModuleItem] {
&self.items
}

/// Access the span of the program.
pub fn span(&self) -> &Span {
&self.span
}
}

impl_eq_hash!(ModuleProgram; items);
Expand Down Expand Up @@ -455,6 +495,11 @@ impl Module {
pub fn assignments(&self) -> &[ModuleAssignment] {
&self.assignments
}

/// Access the span of the module.
pub fn span(&self) -> &Span {
&self.span
}
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
Expand Down