Merge pull request #499 from nushell/remove-parser-unwraps

Remove unwraps from the parser
This commit is contained in:
Jonathan Turner 2019-08-28 10:29:03 +12:00 committed by GitHub
commit 8e95508353
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View file

@ -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)));

View file

@ -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();