Skip to content

Commit

Permalink
add filename
Browse files Browse the repository at this point in the history
  • Loading branch information
yihozhang committed Aug 16, 2024
1 parent 36bcdd5 commit 8f962be
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub struct Location {

pub enum Quote {
Quote {
filename: String,
quote: String,
start: Location,
end: Location,
Expand All @@ -83,13 +84,22 @@ pub enum Quote {
impl Display for Quote {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Quote::Quote { quote, start, end } => {
Quote::Quote {
filename,
quote,
start,
end,
} => {
if start.line == end.line {
write!(f, "In {}:{}-{}: {}", start.line, start.col, end.col, quote)
write!(
f,
"In {}:{}-{} of {filename}: {}",
start.line, start.col, end.col, quote
)
} else {
write!(
f,
"In {}:{}-{}:{}: {}",
"In {}:{}-{}:{} of {filename}: {}",
start.line, start.col, end.line, end.col, quote
)
}
Expand Down Expand Up @@ -127,10 +137,16 @@ impl Span {
let Some(contents) = self.0.contents.as_ref() else {
return Quote::NotAvailable;
};
let filename = self.0.name.clone();
let start = self.0.get_location(self.1);
let end = self.0.get_location(self.2 - 1);
let quote = contents[self.1..self.2].to_string();
Quote::Quote { quote, start, end }
Quote::Quote {
filename,
quote,
start,
end,
}
}
}

Expand Down

0 comments on commit 8f962be

Please sign in to comment.