Skip to content

Commit 0453c08

Browse files
committed
refactor
1 parent 083d5b5 commit 0453c08

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

crates/nu-parser/src/parse_keywords.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ pub fn parse_export_in_block(
13681368
&parts[2..]
13691369
},
13701370
decl_id,
1371-
false,
1371+
true,
13721372
);
13731373
// don't need errors generated by parse_internal_call
13741374
// further error will be generated by detail `parse_xxx` function.
@@ -2343,7 +2343,7 @@ pub fn parse_module(
23432343
1
23442344
};
23452345

2346-
let (call, call_span) = match working_set.find_decl(b"module") {
2346+
let (mut call, call_span) = match working_set.find_decl(b"module") {
23472347
Some(decl_id) => {
23482348
let (command_spans, rest_spans) = spans.split_at(split_id);
23492349

@@ -2431,12 +2431,7 @@ pub fn parse_module(
24312431
};
24322432

24332433
if spans.len() == split_id + 1 {
2434-
let call = Box::new(Call {
2435-
head: Span::concat(&spans[..split_id]),
2436-
decl_id: call.decl_id,
2437-
arguments: vec![Argument::Positional(module_name_or_path_expr)],
2438-
parser_info: HashMap::new(),
2439-
});
2434+
call.set_arguments(vec![Argument::Positional(module_name_or_path_expr)]);
24402435

24412436
let pipeline = Pipeline::from_vec(vec![Expression::new(
24422437
working_set,
@@ -2507,19 +2502,10 @@ pub fn parse_module(
25072502
Type::Block,
25082503
);
25092504

2510-
let module_decl_id = working_set
2511-
.find_decl(b"module")
2512-
.expect("internal error: missing module command");
2513-
2514-
let call = Box::new(Call {
2515-
head: Span::concat(&spans[..split_id]),
2516-
decl_id: module_decl_id,
2517-
arguments: vec![
2518-
Argument::Positional(module_name_or_path_expr),
2519-
Argument::Positional(block_expr),
2520-
],
2521-
parser_info: HashMap::new(),
2522-
});
2505+
call.set_arguments(vec![
2506+
Argument::Positional(module_name_or_path_expr),
2507+
Argument::Positional(block_expr),
2508+
]);
25232509

25242510
(
25252511
Pipeline::from_vec(vec![Expression::new(

crates/nu-parser/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ pub fn parse_internal_call(
12701270
continue;
12711271
}
12721272

1273-
// HACK: avoid repeated parsing of argument values for special cases
1273+
// HACK: avoid repeated parsing of argument values in special cases
12741274
// see https://github.com/nushell/nushell/issues/16398
12751275
let arg = if lite {
12761276
Expression::garbage(working_set, spans[spans_idx])

crates/nu-protocol/src/ast/call.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ impl Call {
222222
self.parser_info.insert(name, val)
223223
}
224224

225+
pub fn set_arguments(&mut self, args: Vec<Argument>) {
226+
self.arguments = args;
227+
}
228+
225229
pub fn get_flag_expr(&self, flag_name: &str) -> Option<&Expression> {
226230
for name in self.named_iter().rev() {
227231
if flag_name == name.0.item {

0 commit comments

Comments
 (0)