forked from extern/nushell
Remove unwraps from the parser
I intend to add regression tests for these cases to the parser as a follow-up PR. Fixes #490 Fixes #494
This commit is contained in:
parent
34c042c4fc
commit
dfe452bbc4
@ -140,7 +140,15 @@ impl ShellError {
|
||||
use language_reporting::*;
|
||||
|
||||
match error {
|
||||
nom::Err::Incomplete(_) => unreachable!(),
|
||||
nom::Err::Incomplete(_) => {
|
||||
// TODO: Get span of EOF
|
||||
let diagnostic = Diagnostic::new(
|
||||
Severity::Error,
|
||||
format!("Parse Error: Unexpected end of line"),
|
||||
);
|
||||
|
||||
ShellError::diagnostic(diagnostic)
|
||||
}
|
||||
nom::Err::Failure(span) | nom::Err::Error(span) => {
|
||||
let diagnostic = Diagnostic::new(Severity::Error, format!("Parse Error"))
|
||||
.with_label(Label::new_primary(Span::from(span.0)));
|
||||
|
@ -231,12 +231,16 @@ pub fn baseline_parse_semantic_token(
|
||||
TokenNode::Call(_call) => unimplemented!(),
|
||||
TokenNode::Delimited(delimited) => baseline_parse_delimited(delimited, context, source),
|
||||
TokenNode::Pipeline(_pipeline) => unimplemented!(),
|
||||
TokenNode::Operator(_op) => unreachable!(),
|
||||
TokenNode::Flag(_flag) => Err(ShellError::unimplemented(
|
||||
"passing flags is not supported yet.",
|
||||
TokenNode::Operator(op) => Err(ShellError::syntax_error(
|
||||
"Unexpected operator".tagged(op.tag),
|
||||
)),
|
||||
TokenNode::Flag(flag) => Err(ShellError::syntax_error("Unexpected flag".tagged(flag.tag))),
|
||||
TokenNode::Member(span) => Err(ShellError::syntax_error(
|
||||
"BUG: Top-level member".tagged(span),
|
||||
)),
|
||||
TokenNode::Whitespace(span) => Err(ShellError::syntax_error(
|
||||
"BUG: Whitespace found during parse".tagged(span),
|
||||
)),
|
||||
TokenNode::Member(_span) => unreachable!(),
|
||||
TokenNode::Whitespace(_span) => unreachable!(),
|
||||
TokenNode::Error(error) => Err(*error.item.clone()),
|
||||
TokenNode::Path(path) => baseline_parse_path(path, context, source),
|
||||
}
|
||||
@ -304,7 +308,11 @@ pub fn baseline_parse_path(
|
||||
TokenNode::Member(span) => span.slice(source),
|
||||
|
||||
// TODO: Make this impossible
|
||||
other => unreachable!("{:?}", other),
|
||||
other => {
|
||||
return Err(ShellError::syntax_error(
|
||||
format!("{} in path", other.type_name()).tagged(other.span()),
|
||||
))
|
||||
}
|
||||
}
|
||||
.to_string();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user