Skip to content

Commit

Permalink
Improve unterminated string interpolation error
Browse files Browse the repository at this point in the history
Before, the error span would point to the whole string:

>>> {x} {1"
error: while parsing
  ┌─ <input:16>:1:1
  │
1 │ "{x} {1"
  │ ^^^^^^^^ Unterminated {...} interpolation in this string

Now it only points to the unfinished interpolation:

>>> "{x} {1"
error: while parsing
  ┌─ <input:2>:1:6
  │
1 │ "{x} {1"
  │      ^^ Unterminated string interpolation
  • Loading branch information
triallax authored and sharkdp committed Feb 5, 2024
1 parent b951645 commit 0de3697
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions numbat/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum TokenizerErrorKind {
#[error("Unterminated string")]
UnterminatedString,

#[error("Unterminated {{...}} interpolation in this string")]
#[error("Unterminated string interpolation")]
UnterminatedStringInterpolation,

#[error("Unexpected '{{' inside string interpolation")]
Expand Down Expand Up @@ -532,8 +532,8 @@ impl Tokenizer {
return Err(TokenizerError {
kind: TokenizerErrorKind::UnterminatedStringInterpolation,
span: Span {
start: self.string_start,
end: self.current,
start: self.interpolation_start,
end: self.last,
code_source_id: self.code_source_id,
},
});
Expand Down

0 comments on commit 0de3697

Please sign in to comment.