forked from extern/nushell
Have lite-parse complete return a complete bare form. (#2389)
Previously, lite parse would stack up opening delimiters in vec, and if we didn't close everything off, it would simply return an error with a partial form that didn't include the missing closing delimiters. This commits adds those delimiters so that `classify_block` can parse correctly.
This commit is contained in:
@ -56,12 +56,23 @@ fn skip_whitespace(src: &mut Input) {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum BlockKind {
|
||||
Paren,
|
||||
CurlyBracket,
|
||||
SquareBracket,
|
||||
}
|
||||
|
||||
impl From<BlockKind> for char {
|
||||
fn from(bk: BlockKind) -> char {
|
||||
match bk {
|
||||
BlockKind::Paren => ')',
|
||||
BlockKind::SquareBracket => ']',
|
||||
BlockKind::CurlyBracket => '}',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn bare(src: &mut Input, span_offset: usize) -> ParseResult<Spanned<String>> {
|
||||
skip_whitespace(src);
|
||||
|
||||
@ -114,15 +125,15 @@ fn bare(src: &mut Input, span_offset: usize) -> ParseResult<Spanned<String>> {
|
||||
);
|
||||
|
||||
if let Some(block) = block_level.last() {
|
||||
let delim: char = (*block).into();
|
||||
let cause = nu_errors::ParseError::unexpected_eof(delim.to_string(), span);
|
||||
|
||||
while let Some(bk) = block_level.pop() {
|
||||
bare.push(bk.into());
|
||||
}
|
||||
|
||||
return Err(ParseError {
|
||||
cause: nu_errors::ParseError::unexpected_eof(
|
||||
match block {
|
||||
BlockKind::Paren => ")",
|
||||
BlockKind::SquareBracket => "]",
|
||||
BlockKind::CurlyBracket => "}",
|
||||
},
|
||||
span,
|
||||
),
|
||||
cause,
|
||||
partial: Some(bare.spanned(span)),
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user