Skip to content

Commit 2490578

Browse files
committed
Add specific error for unclosed string interpolations
1 parent 839fa37 commit 2490578

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/parsing/parser.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub enum ParsingError {
2727
Unrecognized(usize), // improve this
2828
Expected(usize, &'static str),
2929
ExpectedMatchingChar(usize, &'static str, char, char),
30+
UnclosedInterpolation(usize),
3031
InvalidHeader(usize),
3132
InvalidCharacter(usize, char),
3233
UnexpectedEndOfInput(usize),
@@ -60,6 +61,7 @@ impl ParsingError {
6061
ParsingError::Unrecognized(offset) => *offset,
6162
ParsingError::Expected(offset, _) => *offset,
6263
ParsingError::ExpectedMatchingChar(offset, _, _, _) => *offset,
64+
ParsingError::UnclosedInterpolation(offset) => *offset,
6365
ParsingError::InvalidHeader(offset) => *offset,
6466
ParsingError::InvalidCharacter(offset, _) => *offset,
6567
ParsingError::UnexpectedEndOfInput(offset) => *offset,
@@ -1479,12 +1481,9 @@ impl<'i> Parser<'i> {
14791481
current_pos = end_pos + 1;
14801482
}
14811483
None => {
1482-
// Unmatched brace - point to end of string content (at closing quote)
1483-
return Err(ParsingError::ExpectedMatchingChar(
1484-
self.offset + raw.len(),
1485-
"an interpolation",
1486-
'{',
1487-
'}',
1484+
// Unmatched brace - point to the opening brace position
1485+
return Err(ParsingError::UnclosedInterpolation(
1486+
self.offset + absolute_brace_start,
14881487
));
14891488
}
14901489
}

src/problem/messages.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ there was no more input remaining in the current scope.
3535
.trim_ascii()
3636
.to_string(),
3737
),
38+
ParsingError::UnclosedInterpolation(_) => (
39+
"Unclosed string interpolation".to_string(),
40+
r#"
41+
Every '{' that starts an interpolation within a string must have a
42+
corresponding '}' to mark where the interpolation ends and the string
43+
literal resumes.
44+
"#
45+
.trim_ascii()
46+
.to_string(),
47+
),
3848
ParsingError::InvalidHeader(_) => {
3949
// Format the sample metadata using the same code as the formatter
4050
let mut formatted_example = String::new();

0 commit comments

Comments
 (0)