use crate::error::{CypherError, ErrorKind, Span};
#[derive(Debug, Clone)]
pub enum SemaError {
UnresolvedVariable { name: String, span: Span },
RedeclaredVariable {
name: String,
first_span: Span,
redecl_span: Span,
},
AggregationMix {
non_grouping: Vec<String>,
span: Span,
},
DistinctNotAllowed { span: Span },
InvalidReference {
name: String,
reason: &'static str,
span: Span,
},
}
impl SemaError {
pub fn to_error_kind(&self) -> ErrorKind {
match self {
SemaError::UnresolvedVariable { name, .. } => {
ErrorKind::UnresolvedVariable { name: name.clone() }
}
SemaError::RedeclaredVariable {
name, first_span, ..
} => ErrorKind::RedeclaredVariable {
name: name.clone(),
first_span: *first_span,
},
SemaError::AggregationMix { non_grouping, .. } => ErrorKind::AggregationMix {
non_grouping: non_grouping.clone(),
},
SemaError::DistinctNotAllowed { .. } => ErrorKind::DistinctNotAllowed,
SemaError::InvalidReference { name, reason, .. } => ErrorKind::InvalidReference {
name: name.clone(),
reason,
},
}
}
pub fn into_error(self) -> CypherError {
CypherError {
kind: self.to_error_kind(),
span: match &self {
SemaError::UnresolvedVariable { span, .. } => *span,
SemaError::RedeclaredVariable { redecl_span, .. } => *redecl_span,
SemaError::AggregationMix { span, .. } => *span,
SemaError::DistinctNotAllowed { span } => *span,
SemaError::InvalidReference { span, .. } => *span,
},
source_label: None,
notes: Vec::new(),
source: None,
}
}
}