mirror of
https://github.com/nushell/nushell.git
synced 2024-11-23 00:43:33 +01:00
Fail more gently for bad list/table parses
This commit is contained in:
parent
b8e8061787
commit
e00da070fd
@ -161,15 +161,14 @@ pub fn lex_item(
|
||||
|
||||
let span = Span::new(span_offset + token_start, span_offset + *curr_offset);
|
||||
|
||||
// If there is still unclosed opening delimiters, close them and add
|
||||
// synthetic closing characters to the accumulated token.
|
||||
// If there is still unclosed opening delimiters, remember they were missing
|
||||
if let Some(block) = block_level.last() {
|
||||
let delim = block.closing();
|
||||
let cause = ParseError::UnexpectedEof(
|
||||
(delim as char).to_string(),
|
||||
Span {
|
||||
start: span.end - 1,
|
||||
end: span.end,
|
||||
start: span.end,
|
||||
end: span.end + 1,
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -2050,6 +2050,19 @@ pub fn parse_value(
|
||||
}
|
||||
}
|
||||
SyntaxShape::Any => {
|
||||
if bytes.starts_with(b"[") {
|
||||
let shapes = [SyntaxShape::Table];
|
||||
for shape in shapes.iter() {
|
||||
if let (s, None) = parse_value(working_set, span, shape) {
|
||||
return (s, None);
|
||||
}
|
||||
}
|
||||
parse_value(
|
||||
working_set,
|
||||
span,
|
||||
&SyntaxShape::List(Box::new(SyntaxShape::Any)),
|
||||
)
|
||||
} else {
|
||||
let shapes = [
|
||||
SyntaxShape::Int,
|
||||
SyntaxShape::Number,
|
||||
@ -2071,6 +2084,7 @@ pub fn parse_value(
|
||||
Some(ParseError::Expected("any shape".into(), span)),
|
||||
)
|
||||
}
|
||||
}
|
||||
_ => (garbage(span), Some(ParseError::IncompleteParser(span))),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user