-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d1d9cf
commit f6053e2
Showing
8 changed files
with
804 additions
and
203 deletions.
There are no files selected for viewing
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,29 +1,34 @@ | ||
use std::fmt; | ||
|
||
use pest::Span; | ||
use crate::{parser::Rule, CompilationStage}; | ||
|
||
use crate::parser::Rule; | ||
pub(crate) type PestError = pest::error::Error<Rule>; | ||
pub(crate) type ErrorVariant = pest::error::ErrorVariant<Rule>; | ||
|
||
pub struct AstBuildError<'a> { | ||
pub(crate) message: String, | ||
pub(crate) span: Span<'a> | ||
pub struct AstBuildError { | ||
pub(crate) stage: CompilationStage, | ||
pub(crate) inner: PestError | ||
} | ||
|
||
impl<'a> fmt::Display for AstBuildError<'a> { | ||
impl fmt::Display for AstBuildError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "An Error Occurred, Please Try Again!") // user-facing output | ||
write!(f, "Error occurred when {}: {}", self.stage, self.inner) // user-facing output | ||
} | ||
} | ||
|
||
impl<'a> fmt::Debug for AstBuildError<'a> { | ||
impl fmt::Debug for AstBuildError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{{ file: {}, line: {} }}", file!(), line!()) // programmer-facing output | ||
} | ||
} | ||
|
||
pub fn produce_unexpected_pair_error<R>(pair: pest::iterators::Pair<Rule>) -> Result<R, AstBuildError> { | ||
let rule = pair.as_rule(); | ||
let span = pair.as_span(); | ||
let pair = pair.as_str().clone(); | ||
let message = format!("Unexpected rule {}", pair); | ||
Err(AstBuildError { message, span }) | ||
let message = format!("Unexpected rule {:?} ({})", rule, pair); | ||
Err(AstBuildError { | ||
stage: CompilationStage::BuildAst, | ||
inner: PestError::new_from_span(pest::error::ErrorVariant::CustomError { message }, span) | ||
}) | ||
} |
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,7 +1,9 @@ | ||
pub mod errors; | ||
pub mod nodes; | ||
pub mod types; | ||
mod errors; | ||
mod parse; | ||
mod types; | ||
|
||
pub use errors::*; | ||
pub use nodes::*; | ||
pub use types::*; | ||
pub(crate) use errors::*; | ||
|
||
pub use parse::parse_ast; | ||
|
||
pub(crate) use types::*; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.