Skip to content

Commit

Permalink
Merge pull request #180 from Glyphack/improve-parser-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyphack authored Sep 30, 2023
2 parents 4910541 + a06bcb7 commit f911ff0
Show file tree
Hide file tree
Showing 15 changed files with 899 additions and 418 deletions.
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

0 comments on commit f911ff0

Please sign in to comment.