Skip to content

Commit

Permalink
Bugfix: Missing filename when panic (#44)
Browse files Browse the repository at this point in the history
Fixes #43 

Proper fix was done in the `moparse` crate in. This PR contains only
adjustments after switching to the newer parser version.
  • Loading branch information
ErykMroczek authored Feb 21, 2024
2 parents 8a9b4b6 + 2eea26c commit ffaa856
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["Modelica", "development", "formatter"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
moparse = "0.1.5-rc1"
moparse = "0.1.5-rc2"

[profile.release]
strip = true
25 changes: 15 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,38 @@ fn format_files(args: &[String], check: bool) {
.for_each(|mut v| files.append(&mut v));
files.iter().for_each(|p| {
let contents = read_file(p);
let name = p.display();
match contents {
Ok(source) => {
let parsed = parse(&source, SyntaxKind::StoredDefinition);
let parsed = parse(
name.to_string().as_str(),
&source,
SyntaxKind::StoredDefinition,
);
if !parsed.errors.is_empty() {
let messages: Vec<String> = parsed
.errors
.iter()
.map(|e| format!("{}:{}", p.display(), e))
.collect();
writeln!(lock, "Syntax errors detected:\n{}", messages.join("\n")).unwrap();
writeln!(
lock,
"Syntax errors detected:\n{}",
parsed.errors.join("\n")
)
.unwrap();
code = 1;
} else {
let output = pretty_print(parsed.tokens, parsed.comments, parsed.events);
if check {
if output != source {
code = 1;
writeln!(lock, "{}: check failed", p.display()).unwrap();
writeln!(lock, "{}: check failed", name).unwrap();
} else {
writeln!(lock, "{}: check passed", p.display()).unwrap();
writeln!(lock, "{}: check passed", name).unwrap();
}
} else {
write_file(p, output);
}
}
}
Err(e) => {
eprintln!("{}: error: {}", p.display(), e);
eprintln!("{}: error: {}", name, e);
code = 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod tests {
use super::*;

fn tree(source: &str, start: SyntaxKind) -> Tree {
let parsed = parse(source, start);
let parsed = parse("none", source, start);
build_tree(parsed.tokens, parsed.events)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/style_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs;
// Helper functions
fn format_file(path: &str) -> String {
let input = fs::read_to_string(path).expect("error");
let parsed = moparse::parse(&input, moparse::SyntaxKind::StoredDefinition);
let parsed = moparse::parse(path, &input, moparse::SyntaxKind::StoredDefinition);
mofmt::pretty_print(parsed.tokens, parsed.comments, parsed.events)
}

Expand Down

0 comments on commit ffaa856

Please sign in to comment.