forked from extern/nushell
Merge pull request #28 from jntrnr/smoother_list_parse_fail
Fail more gently for bad list/table parses
This commit is contained in:
commit
2055b83c34
@ -161,15 +161,14 @@ pub fn lex_item(
|
|||||||
|
|
||||||
let span = Span::new(span_offset + token_start, span_offset + *curr_offset);
|
let span = Span::new(span_offset + token_start, span_offset + *curr_offset);
|
||||||
|
|
||||||
// If there is still unclosed opening delimiters, close them and add
|
// If there is still unclosed opening delimiters, remember they were missing
|
||||||
// synthetic closing characters to the accumulated token.
|
|
||||||
if let Some(block) = block_level.last() {
|
if let Some(block) = block_level.last() {
|
||||||
let delim = block.closing();
|
let delim = block.closing();
|
||||||
let cause = ParseError::UnexpectedEof(
|
let cause = ParseError::UnexpectedEof(
|
||||||
(delim as char).to_string(),
|
(delim as char).to_string(),
|
||||||
Span {
|
Span {
|
||||||
start: span.end - 1,
|
start: span.end,
|
||||||
end: span.end,
|
end: span.end + 1,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -2050,26 +2050,40 @@ pub fn parse_value(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SyntaxShape::Any => {
|
SyntaxShape::Any => {
|
||||||
let shapes = [
|
if bytes.starts_with(b"[") {
|
||||||
SyntaxShape::Int,
|
let shapes = [SyntaxShape::Table];
|
||||||
SyntaxShape::Number,
|
for shape in shapes.iter() {
|
||||||
SyntaxShape::Range,
|
if let (s, None) = parse_value(working_set, span, shape) {
|
||||||
SyntaxShape::Filesize,
|
return (s, None);
|
||||||
SyntaxShape::Duration,
|
}
|
||||||
SyntaxShape::Block,
|
|
||||||
SyntaxShape::Table,
|
|
||||||
SyntaxShape::List(Box::new(SyntaxShape::Any)),
|
|
||||||
SyntaxShape::String,
|
|
||||||
];
|
|
||||||
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,
|
||||||
|
SyntaxShape::Range,
|
||||||
|
SyntaxShape::Filesize,
|
||||||
|
SyntaxShape::Duration,
|
||||||
|
SyntaxShape::Block,
|
||||||
|
SyntaxShape::Table,
|
||||||
|
SyntaxShape::List(Box::new(SyntaxShape::Any)),
|
||||||
|
SyntaxShape::String,
|
||||||
|
];
|
||||||
|
for shape in shapes.iter() {
|
||||||
|
if let (s, None) = parse_value(working_set, span, shape) {
|
||||||
|
return (s, None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(
|
||||||
|
garbage(span),
|
||||||
|
Some(ParseError::Expected("any shape".into(), span)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
(
|
|
||||||
garbage(span),
|
|
||||||
Some(ParseError::Expected("any shape".into(), span)),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
_ => (garbage(span), Some(ParseError::IncompleteParser(span))),
|
_ => (garbage(span), Some(ParseError::IncompleteParser(span))),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user