mirror of
https://github.com/nushell/nushell.git
synced 2024-12-28 09:59:36 +01:00
Merge pull request #499 from nushell/remove-parser-unwraps
Remove unwraps from the parser
This commit is contained in:
commit
8e95508353
@ -140,7 +140,15 @@ impl ShellError {
|
|||||||
use language_reporting::*;
|
use language_reporting::*;
|
||||||
|
|
||||||
match error {
|
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) => {
|
nom::Err::Failure(span) | nom::Err::Error(span) => {
|
||||||
let diagnostic = Diagnostic::new(Severity::Error, format!("Parse Error"))
|
let diagnostic = Diagnostic::new(Severity::Error, format!("Parse Error"))
|
||||||
.with_label(Label::new_primary(Span::from(span.0)));
|
.with_label(Label::new_primary(Span::from(span.0)));
|
||||||
|
@ -231,12 +231,16 @@ pub fn baseline_parse_semantic_token(
|
|||||||
TokenNode::Call(_call) => unimplemented!(),
|
TokenNode::Call(_call) => unimplemented!(),
|
||||||
TokenNode::Delimited(delimited) => baseline_parse_delimited(delimited, context, source),
|
TokenNode::Delimited(delimited) => baseline_parse_delimited(delimited, context, source),
|
||||||
TokenNode::Pipeline(_pipeline) => unimplemented!(),
|
TokenNode::Pipeline(_pipeline) => unimplemented!(),
|
||||||
TokenNode::Operator(_op) => unreachable!(),
|
TokenNode::Operator(op) => Err(ShellError::syntax_error(
|
||||||
TokenNode::Flag(_flag) => Err(ShellError::unimplemented(
|
"Unexpected operator".tagged(op.tag),
|
||||||
"passing flags is not supported yet.",
|
)),
|
||||||
|
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::Error(error) => Err(*error.item.clone()),
|
||||||
TokenNode::Path(path) => baseline_parse_path(path, context, source),
|
TokenNode::Path(path) => baseline_parse_path(path, context, source),
|
||||||
}
|
}
|
||||||
@ -304,7 +308,11 @@ pub fn baseline_parse_path(
|
|||||||
TokenNode::Member(span) => span.slice(source),
|
TokenNode::Member(span) => span.slice(source),
|
||||||
|
|
||||||
// TODO: Make this impossible
|
// TODO: Make this impossible
|
||||||
other => unreachable!("{:?}", other),
|
other => {
|
||||||
|
return Err(ShellError::syntax_error(
|
||||||
|
format!("{} in path", other.type_name()).tagged(other.span()),
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user