Cleanup parsing of use and hide commands (#705)

This commit is contained in:
Jakub Žádník
2022-01-10 03:39:25 +02:00
committed by GitHub
parent 3a17b60862
commit 733b2836f1
6 changed files with 321 additions and 168 deletions

View File

@ -1,4 +1,5 @@
use super::{Expr, Operator, Statement};
use crate::ast::ImportPattern;
use crate::{engine::StateWorkingSet, BlockId, Signature, Span, Type, VarId, IN_VARIABLE_ID};
#[derive(Debug, Clone)]
@ -96,6 +97,13 @@ impl Expression {
}
}
pub fn as_import_pattern(&self) -> Option<ImportPattern> {
match &self.expr {
Expr::ImportPattern(pattern) => Some(pattern.clone()),
_ => None,
}
}
pub fn has_in_variable(&self, working_set: &StateWorkingSet) -> bool {
match &self.expr {
Expr::BinaryOp(left, _, right) => {

View File

@ -95,9 +95,9 @@ pub enum ShellError {
#[diagnostic(code(nu::shell::variable_not_found), url(docsrs))]
VariableNotFoundAtRuntime(#[label = "variable not found"] Span),
#[error("Environment variable not found")]
#[error("Environment variable '{0}' not found")]
#[diagnostic(code(nu::shell::env_variable_not_found), url(docsrs))]
EnvVarNotFoundAtRuntime(#[label = "environment variable not found"] Span),
EnvVarNotFoundAtRuntime(String, #[label = "environment variable not found"] Span),
#[error("Not found.")]
#[diagnostic(code(nu::parser::not_found), url(docsrs))]