Fix unexpected whitespace in condition error
This commit is contained in:
parent
2bac397096
commit
f00302c8af
|
@ -200,6 +200,28 @@ pub enum Delimiter {
|
||||||
Bracket,
|
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.
|
/// Represents a list of tokens enclosed by a pair of delimiters.
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
|
|
@ -54,11 +54,7 @@ impl<'a> Parser<'a> {
|
||||||
// move after the whole delimited list
|
// move after the whole delimited list
|
||||||
self.current_frame.forward();
|
self.current_frame.forward();
|
||||||
|
|
||||||
let expected = match delimiter {
|
let expected = delimiter.opening_char();
|
||||||
Delimiter::Parenthesis => '(',
|
|
||||||
Delimiter::Brace => '{',
|
|
||||||
Delimiter::Bracket => '[',
|
|
||||||
};
|
|
||||||
|
|
||||||
let delimited_stream = if let Some(token_tree) = raw_token_tree {
|
let delimited_stream = if let Some(token_tree) = raw_token_tree {
|
||||||
match token_tree {
|
match token_tree {
|
||||||
|
@ -107,17 +103,13 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
// the current frame must be at the end
|
// the current frame must be at the end
|
||||||
if !self.current_frame.is_exhausted() {
|
if !self.current_frame.is_exhausted() {
|
||||||
let expected = match self
|
let expected = self
|
||||||
.current_frame
|
.current_frame
|
||||||
.token_provider
|
.token_provider
|
||||||
.as_delimited()
|
.as_delimited()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.delimiter
|
.delimiter
|
||||||
{
|
.closing_char();
|
||||||
Delimiter::Parenthesis => ')',
|
|
||||||
Delimiter::Brace => '}',
|
|
||||||
Delimiter::Bracket => ']',
|
|
||||||
};
|
|
||||||
|
|
||||||
handler.receive(Error::UnexpectedSyntax(UnexpectedSyntax {
|
handler.receive(Error::UnexpectedSyntax(UnexpectedSyntax {
|
||||||
expected: SyntaxKind::Punctuation(expected),
|
expected: SyntaxKind::Punctuation(expected),
|
||||||
|
|
|
@ -358,7 +358,11 @@ impl<'a> Parser<'a> {
|
||||||
) -> Option<ParenthesizedCondition> {
|
) -> Option<ParenthesizedCondition> {
|
||||||
let token_tree = self.step_into(
|
let token_tree = self.step_into(
|
||||||
Delimiter::Parenthesis,
|
Delimiter::Parenthesis,
|
||||||
|parser| parser.parse_condition(handler),
|
|parser| {
|
||||||
|
let cond = parser.parse_condition(handler)?;
|
||||||
|
parser.stop_at_significant();
|
||||||
|
Some(cond)
|
||||||
|
},
|
||||||
handler,
|
handler,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue