Fix unexpected whitespace in condition error

This commit is contained in:
Moritz Hölting 2024-04-13 13:41:24 +02:00
parent 2bac397096
commit f00302c8af
3 changed files with 30 additions and 12 deletions

View File

@ -200,6 +200,28 @@ pub enum Delimiter {
Bracket,
}
impl Delimiter {
/// Returns the opening delimiter.
#[must_use]
pub fn opening_char(&self) -> char {
match self {
Self::Parenthesis => '(',
Self::Brace => '{',
Self::Bracket => '[',
}
}
/// Returns the closing delimiter.
#[must_use]
pub fn closing_char(&self) -> char {
match self {
Self::Parenthesis => ')',
Self::Brace => '}',
Self::Bracket => ']',
}
}
}
/// Represents a list of tokens enclosed by a pair of delimiters.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]

View File

@ -54,11 +54,7 @@ impl<'a> Parser<'a> {
// move after the whole delimited list
self.current_frame.forward();
let expected = match delimiter {
Delimiter::Parenthesis => '(',
Delimiter::Brace => '{',
Delimiter::Bracket => '[',
};
let expected = delimiter.opening_char();
let delimited_stream = if let Some(token_tree) = raw_token_tree {
match token_tree {
@ -107,17 +103,13 @@ impl<'a> Parser<'a> {
// the current frame must be at the end
if !self.current_frame.is_exhausted() {
let expected = match self
let expected = self
.current_frame
.token_provider
.as_delimited()
.unwrap()
.delimiter
{
Delimiter::Parenthesis => ')',
Delimiter::Brace => '}',
Delimiter::Bracket => ']',
};
.closing_char();
handler.receive(Error::UnexpectedSyntax(UnexpectedSyntax {
expected: SyntaxKind::Punctuation(expected),

View File

@ -358,7 +358,11 @@ impl<'a> Parser<'a> {
) -> Option<ParenthesizedCondition> {
let token_tree = self.step_into(
Delimiter::Parenthesis,
|parser| parser.parse_condition(handler),
|parser| {
let cond = parser.parse_condition(handler)?;
parser.stop_at_significant();
Some(cond)
},
handler,
)?;