Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve parser errors #180

Merged
merged 2 commits into from
Sep 30, 2023
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
6 changes: 5 additions & 1 deletion enderpy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ fn tokenize(file: &PathBuf) -> Result<()> {

fn parse(file: &PathBuf) -> Result<()> {
let source = fs::read_to_string(file)?;
let mut parser = Parser::new(source);
let file_path = match file.to_str() {
Some(path) => path,
None => "",
};
let mut parser = Parser::new(source, file_path.into());
let ast = parser.parse();
println!("{:#?}", ast);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ serde = { version = "1.0", features = ["derive"] }
tracing = "0.1"
tracing-subscriber = "0.3"
unicode-id-start = "1.0.3"
miette = "5.6.0"
miette = { version = "5.6.0", features = ["fancy"] }
thiserror = "1.0.40"

[dev-dependencies]
Expand Down
31 changes: 0 additions & 31 deletions parser/src/parser/diagnostics.rs

This file was deleted.

27 changes: 27 additions & 0 deletions parser/src/parser/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use miette::Diagnostic;
use thiserror::Error;

#[derive(Error, Diagnostic, Debug)]
pub enum ParsingError {
#[error(transparent)]
#[diagnostic(code(gen_color::io_error))]
IoError(#[from] std::io::Error),

#[error(
"Invalid syntax"
)]
#[diagnostic(code(
gen_color::colors_and_steps_mismatch
))]
InvalidSyntax {
path: Box<str>,
msg: Box<str>,
line: u32,
#[source_code]
input: String,
#[help]
advice: String,
#[label("span")]
span: (usize, usize),
},
}
2 changes: 1 addition & 1 deletion parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod ast;
mod diagnostics;
pub mod error;
mod expression;
mod operator;
pub mod parser;
Expand Down
Loading