Remove shape-directed import pattern parsing (#7570)

This commit is contained in:
Jakub Žádník
2022-12-22 16:36:13 +02:00
committed by GitHub
parent 74656bf976
commit 23a5c5dc09
12 changed files with 121 additions and 81 deletions

View File

@ -17,7 +17,12 @@ impl Command for ExportUse {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("export use")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.required("pattern", SyntaxShape::ImportPattern, "import pattern")
.required("module", SyntaxShape::String, "Module or module file")
.optional(
"members",
SyntaxShape::Any,
"Which members of the module to import",
)
.category(Category::Core)
}

View File

@ -15,7 +15,12 @@ impl Command for Hide {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("hide")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.required("pattern", SyntaxShape::ImportPattern, "import pattern")
.required("module", SyntaxShape::String, "Module or module file")
.optional(
"members",
SyntaxShape::Any,
"Which members of the module to import",
)
.category(Category::Core)
}
@ -44,7 +49,7 @@ This command is a parser keyword. For details, check:
let env_var_name = if let Some(Expression {
expr: Expr::ImportPattern(pat),
..
}) = call.positional_nth(0)
}) = call.parser_info_nth(0)
{
Spanned {
item: String::from_utf8_lossy(&pat.head.name).to_string(),

View File

@ -66,7 +66,7 @@ impl Command for OverlayUse {
let mut name_arg: Spanned<String> = call.req(engine_state, caller_stack, 0)?;
name_arg.item = trim_quotes_str(&name_arg.item).to_string();
let maybe_origin_module_id = if let Some(overlay_expr) = call.positional_nth(0) {
let maybe_origin_module_id = if let Some(overlay_expr) = call.parser_info_nth(0) {
if let Expr::Overlay(module_id) = overlay_expr.expr {
module_id
} else {

View File

@ -20,7 +20,12 @@ impl Command for Use {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("use")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.required("pattern", SyntaxShape::ImportPattern, "import pattern")
.required("module", SyntaxShape::String, "Module or module file")
.optional(
"members",
SyntaxShape::Any,
"Which members of the module to import",
)
.category(Category::Core)
}
@ -43,7 +48,7 @@ impl Command for Use {
let import_pattern = if let Some(Expression {
expr: Expr::ImportPattern(pat),
..
}) = call.positional_nth(0)
}) = call.parser_info_nth(0)
{
pat
} else {

View File

@ -45,7 +45,7 @@ impl Command for Source {
) -> Result<PipelineData, ShellError> {
// Note: this hidden positional is the block_id that corresponded to the 0th position
// it is put here by the parser
let block_id: i64 = call.req(engine_state, stack, 1)?;
let block_id: i64 = call.req_parser_info(engine_state, stack, 0)?;
let block = engine_state.get_block(block_id as usize).clone();
eval_block(

View File

@ -42,7 +42,7 @@ impl Command for SourceEnv {
// Note: this hidden positional is the block_id that corresponded to the 0th position
// it is put here by the parser
let block_id: i64 = call.req(engine_state, caller_stack, 1)?;
let block_id: i64 = call.req_parser_info(engine_state, caller_stack, 0)?;
// Set the currently evaluated directory (file-relative PWD)
let mut parent = if let Some(path) =