-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pablo Sichert <mail@pablosichert.com>
- Loading branch information
1 parent
07d6827
commit 894dfa0
Showing
6 changed files
with
87 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use diagnostic::{DiagnosticError, Label, Note, Span}; | ||
use value::Value; | ||
|
||
pub type Resolved = Result<Value, ExpressionError>; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub enum ExpressionError { | ||
Abort { | ||
span: Span, | ||
message: Option<String>, | ||
}, | ||
Error { | ||
message: String, | ||
labels: Vec<Label>, | ||
notes: Vec<Note>, | ||
}, | ||
} | ||
|
||
impl std::fmt::Display for ExpressionError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
self.message().fmt(f) | ||
} | ||
} | ||
|
||
impl std::error::Error for ExpressionError { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
None | ||
} | ||
} | ||
|
||
impl DiagnosticError for ExpressionError { | ||
fn code(&self) -> usize { | ||
0 | ||
} | ||
|
||
fn message(&self) -> String { | ||
use ExpressionError::*; | ||
|
||
match self { | ||
Abort { message, .. } => message.clone().unwrap_or_else(|| "aborted".to_owned()), | ||
Error { message, .. } => message.clone(), | ||
} | ||
} | ||
|
||
fn labels(&self) -> Vec<Label> { | ||
use ExpressionError::*; | ||
|
||
match self { | ||
Abort { span, .. } => { | ||
vec![Label::primary("aborted", span)] | ||
} | ||
Error { labels, .. } => labels.clone(), | ||
} | ||
} | ||
|
||
fn notes(&self) -> Vec<Note> { | ||
use ExpressionError::*; | ||
|
||
match self { | ||
Abort { .. } => vec![], | ||
Error { notes, .. } => notes.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl From<String> for ExpressionError { | ||
fn from(message: String) -> Self { | ||
ExpressionError::Error { | ||
message, | ||
labels: vec![], | ||
notes: vec![], | ||
} | ||
} | ||
} | ||
|
||
impl From<&str> for ExpressionError { | ||
fn from(message: &str) -> Self { | ||
message.to_owned().into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod expression; | ||
mod r#macro; | ||
mod target; | ||
|
||
pub use expression::{ExpressionError, Resolved}; | ||
pub use target::Target; | ||
pub use value::Value; |