Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove def-env and export def-env #10999

Merged
merged 5 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 0 additions & 65 deletions crates/nu-cmd-lang/src/core_commands/def_env.rs

This file was deleted.

94 changes: 0 additions & 94 deletions crates/nu-cmd-lang/src/core_commands/export_def_env.rs

This file was deleted.

4 changes: 0 additions & 4 deletions crates/nu-cmd-lang/src/core_commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod collect;
mod const_;
mod continue_;
mod def;
mod def_env;
mod describe;
mod do_;
mod echo;
Expand All @@ -13,7 +12,6 @@ mod export;
mod export_alias;
mod export_const;
mod export_def;
mod export_def_env;
mod export_extern;
mod export_module;
mod export_use;
Expand Down Expand Up @@ -43,7 +41,6 @@ pub use collect::Collect;
pub use const_::Const;
pub use continue_::Continue;
pub use def::Def;
pub use def_env::DefEnv;
pub use describe::Describe;
pub use do_::Do;
pub use echo::Echo;
Expand All @@ -52,7 +49,6 @@ pub use export::ExportCommand;
pub use export_alias::ExportAlias;
pub use export_const::ExportConst;
pub use export_def::ExportDef;
pub use export_def_env::ExportDefEnv;
pub use export_extern::ExportExtern;
pub use export_module::ExportModule;
pub use export_use::ExportUse;
Expand Down
2 changes: 0 additions & 2 deletions crates/nu-cmd-lang/src/default_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub fn create_default_context() -> EngineState {
Const,
Continue,
Def,
DefEnv,
Describe,
Do,
Echo,
Expand All @@ -31,7 +30,6 @@ pub fn create_default_context() -> EngineState {
ExportCommand,
ExportConst,
ExportDef,
ExportDefEnv,
ExportExtern,
ExportUse,
ExportModule,
Expand Down
5 changes: 1 addition & 4 deletions crates/nu-cmd-lang/src/example_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ mod test_examples {
check_example_input_and_output_types_match_command_signature,
};
use crate::{
Break, Collect, Def, DefEnv, Describe, Echo, ExportCommand, ExportDef, ExportDefEnv, If,
Let, Module, Mut, Use,
Break, Collect, Def, Describe, Echo, ExportCommand, ExportDef, If, Let, Module, Mut, Use,
};
use nu_protocol::{
engine::{Command, EngineState, StateWorkingSet},
Expand Down Expand Up @@ -69,12 +68,10 @@ mod test_examples {
working_set.add_decl(Box::new(Break));
working_set.add_decl(Box::new(Collect));
working_set.add_decl(Box::new(Def));
working_set.add_decl(Box::new(DefEnv));
working_set.add_decl(Box::new(Describe));
working_set.add_decl(Box::new(Echo));
working_set.add_decl(Box::new(ExportCommand));
working_set.add_decl(Box::new(ExportDef));
working_set.add_decl(Box::new(ExportDefEnv));
working_set.add_decl(Box::new(If));
working_set.add_decl(Box::new(Let));
working_set.add_decl(Box::new(Module));
Expand Down
80 changes: 10 additions & 70 deletions crates/nu-parser/src/parse_keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub fn parse_def_predecl(working_set: &mut StateWorkingSet, spans: &[Span]) {
return;
};

if def_type_name != b"def" && def_type_name != b"def-env" && def_type_name != b"extern" {
if def_type_name != b"def" && def_type_name != b"extern" {
return;
}

Expand Down Expand Up @@ -372,7 +372,7 @@ pub fn parse_def(
};

let def_call = working_set.get_span_contents(name_span).to_vec();
if def_call != b"def" && def_call != b"def-env" {
if def_call != b"def" {
working_set.error(ParseError::UnknownState(
"internal error: Wrong call name for def function".into(),
span(spans),
Expand Down Expand Up @@ -569,7 +569,7 @@ pub fn parse_def(
let calls_itself = block_calls_itself(block, decl_id);
block.recursive = Some(calls_itself);
block.signature = signature;
block.redirect_env = def_call == b"def-env" || has_env;
block.redirect_env = has_env;

if block.signature.input_output_types.is_empty() {
block
Expand Down Expand Up @@ -1049,7 +1049,7 @@ pub fn parse_export_in_block(
let full_name = if lite_command.parts.len() > 1 {
let sub = working_set.get_span_contents(lite_command.parts[1]);
match sub {
b"alias" | b"def" | b"def-env" | b"extern" | b"use" | b"module" | b"const" => {
b"alias" | b"def" | b"extern" | b"use" | b"module" | b"const" => {
[b"export ", sub].concat()
}
_ => b"export".to_vec(),
Expand Down Expand Up @@ -1108,7 +1108,7 @@ pub fn parse_export_in_block(

match full_name.as_slice() {
b"export alias" => parse_alias(working_set, lite_command, None),
b"export def" | b"export def-env" => parse_def(working_set, lite_command, None).0,
b"export def" => parse_def(working_set, lite_command, None).0,
b"export const" => parse_const(working_set, &lite_command.parts[1..]),
b"export use" => {
let (pipeline, _) = parse_use(working_set, &lite_command.parts);
Expand Down Expand Up @@ -1224,66 +1224,6 @@ pub fn parse_export_in_module(

result
}
b"def-env" => {
let lite_command = LiteCommand {
comments: lite_command.comments.clone(),
parts: spans[1..].to_vec(),
};
let (pipeline, _) = parse_def(working_set, &lite_command, Some(module_name));

let export_def_decl_id = if let Some(id) = working_set.find_decl(b"export def-env")
{
id
} else {
working_set.error(ParseError::InternalError(
"missing 'export def-env' command".into(),
export_span,
));
return (garbage_pipeline(spans), vec![]);
};

// Trying to warp the 'def' call into the 'export def' in a very clumsy way
if let Some(PipelineElement::Expression(
_,
Expression {
expr: Expr::Call(ref def_call),
..
},
)) = pipeline.elements.first()
{
call = def_call.clone();

call.head = span(&spans[0..=1]);
call.decl_id = export_def_decl_id;
} else {
working_set.error(ParseError::InternalError(
"unexpected output from parsing a definition".into(),
span(&spans[1..]),
));
};

let mut result = vec![];

let decl_name = match spans.get(2) {
Some(span) => working_set.get_span_contents(*span),
None => &[],
};
let decl_name = trim_quotes(decl_name);

if let Some(decl_id) = working_set.find_decl(decl_name) {
result.push(Exportable::Decl {
name: decl_name.to_vec(),
id: decl_id,
});
} else {
working_set.error(ParseError::InternalError(
"failed to find added declaration".into(),
span(&spans[1..]),
));
}

result
}
b"extern" => {
let lite_command = LiteCommand {
comments: lite_command.comments.clone(),
Expand Down Expand Up @@ -1563,7 +1503,7 @@ pub fn parse_export_in_module(
}
_ => {
working_set.error(ParseError::Expected(
"def, def-env, alias, use, module, const or extern keyword",
"def, alias, use, module, const or extern keyword",
spans[1],
));

Expand All @@ -1572,9 +1512,9 @@ pub fn parse_export_in_module(
}
} else {
working_set.error(ParseError::MissingPositional(
"def, def-env, alias, use, module, const or extern keyword".to_string(),
"def, alias, use, module, const or extern keyword".to_string(),
Span::new(export_span.end, export_span.end),
"def, def-env, alias, use, module, const or extern keyword".to_string(),
"def, alias, use, module, const or extern keyword".to_string(),
));

vec![]
Expand Down Expand Up @@ -1743,7 +1683,7 @@ pub fn parse_module_block(
let name = working_set.get_span_contents(command.parts[0]);

match name {
b"def" | b"def-env" => {
b"def" => {
block.pipelines.push(
parse_def(
working_set,
Expand Down Expand Up @@ -1898,7 +1838,7 @@ pub fn parse_module_block(
}
_ => {
working_set.error(ParseError::ExpectedKeyword(
"def, const, def-env, extern, alias, use, module, export or export-env keyword".into(),
"def, const, extern, alias, use, module, export or export-env keyword".into(),
command.parts[0],
));

Expand Down
2 changes: 1 addition & 1 deletion crates/nu-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5085,7 +5085,7 @@ pub fn parse_builtin_commands(
let name = working_set.get_span_contents(lite_command.parts[0]);

match name {
b"def" | b"def-env" => parse_def(working_set, lite_command, None).0,
b"def" => parse_def(working_set, lite_command, None).0,
b"extern" => parse_extern(working_set, lite_command, None),
b"let" => parse_let(working_set, &lite_command.parts),
b"const" => parse_const(working_set, &lite_command.parts),
Expand Down