@@ -2,8 +2,8 @@ use crate::{
22 exportable:: Exportable ,
33 parse_block,
44 parser:: {
5- CallKind , compile_block, compile_block_with_id, parse_attribute, parse_redirection ,
6- redirecting_builtin_error,
5+ ArgumentParsingLevel , CallKind , compile_block, compile_block_with_id, parse_attribute,
6+ parse_redirection , redirecting_builtin_error,
77 } ,
88 type_check:: { check_block_input_output, type_compatible} ,
99} ;
@@ -41,7 +41,7 @@ use crate::{
4141 lite_parser:: { LiteCommand , lite_parse} ,
4242 parser:: {
4343 ParsedInternalCall , garbage, garbage_pipeline, parse, parse_call, parse_expression,
44- parse_full_signature, parse_import_pattern, parse_internal_call, parse_string, parse_value ,
44+ parse_full_signature, parse_import_pattern, parse_internal_call, parse_string,
4545 parse_var_with_opt_type, trim_quotes,
4646 } ,
4747 unescape_unquote_string,
@@ -290,7 +290,13 @@ pub fn parse_for(working_set: &mut StateWorkingSet, lite_command: &LiteCommand)
290290 call,
291291 output,
292292 call_kind,
293- } = parse_internal_call ( working_set, spans[ 0 ] , & spans[ 1 ..] , decl_id) ;
293+ } = parse_internal_call (
294+ working_set,
295+ spans[ 0 ] ,
296+ & spans[ 1 ..] ,
297+ decl_id,
298+ ArgumentParsingLevel :: Full ,
299+ ) ;
294300
295301 if working_set
296302 . parse_errors
@@ -608,6 +614,7 @@ fn parse_def_inner(
608614 Span :: concat ( command_spans) ,
609615 rest_spans,
610616 decl_id,
617+ ArgumentParsingLevel :: Full ,
611618 ) ;
612619
613620 if working_set
@@ -864,6 +871,7 @@ fn parse_extern_inner(
864871 Span :: concat ( command_spans) ,
865872 rest_spans,
866873 decl_id,
874+ ArgumentParsingLevel :: Full ,
867875 ) ;
868876 working_set. exit_scope ( ) ;
869877
@@ -1159,6 +1167,7 @@ pub fn parse_alias(
11591167 Span :: concat ( command_spans) ,
11601168 rest_spans,
11611169 decl_id,
1170+ ArgumentParsingLevel :: Full ,
11621171 ) ;
11631172
11641173 working_set
@@ -1455,7 +1464,13 @@ pub fn parse_export_in_block(
14551464 call,
14561465 output,
14571466 call_kind,
1458- } = parse_internal_call ( working_set, parts[ 0 ] , & parts[ 1 ..] , decl_id) ;
1467+ } = parse_internal_call (
1468+ working_set,
1469+ parts[ 0 ] ,
1470+ & parts[ 1 ..] ,
1471+ decl_id,
1472+ ArgumentParsingLevel :: Full ,
1473+ ) ;
14591474
14601475 if call_kind != CallKind :: Valid {
14611476 return Pipeline :: from_vec ( vec ! [ Expression :: new(
@@ -1741,7 +1756,13 @@ pub fn parse_export_env(
17411756 call,
17421757 output,
17431758 call_kind,
1744- } = parse_internal_call ( working_set, spans[ 0 ] , & [ spans[ 1 ] ] , decl_id) ;
1759+ } = parse_internal_call (
1760+ working_set,
1761+ spans[ 0 ] ,
1762+ & [ spans[ 1 ] ] ,
1763+ decl_id,
1764+ ArgumentParsingLevel :: Full ,
1765+ ) ;
17451766
17461767 if call_kind != CallKind :: Valid {
17471768 return (
@@ -2242,7 +2263,7 @@ pub fn parse_module(
22422263 1
22432264 } ;
22442265
2245- let ( call, call_span) = match working_set. find_decl ( b"module" ) {
2266+ let ( mut call, call_span) = match working_set. find_decl ( b"module" ) {
22462267 Some ( decl_id) => {
22472268 let ( command_spans, rest_spans) = spans. split_at ( split_id) ;
22482269
@@ -2255,6 +2276,7 @@ pub fn parse_module(
22552276 Span :: concat ( command_spans) ,
22562277 rest_spans,
22572278 decl_id,
2279+ ArgumentParsingLevel :: FirstK { k : 1 } ,
22582280 ) ;
22592281
22602282 let call_span = Span :: concat ( spans) ;
@@ -2281,52 +2303,52 @@ pub fn parse_module(
22812303 }
22822304 } ;
22832305
2284- let ( module_name_or_path, module_name_or_path_span, module_name_or_path_expr) =
2285- if let Some ( name) = call. positional_nth ( 0 ) {
2286- if let Some ( s) = name. as_string ( ) {
2287- if let Some ( mod_name) = module_name
2288- && s. as_bytes ( ) == mod_name
2289- {
2290- working_set. error ( ParseError :: NamedAsModule (
2291- "module" . to_string ( ) ,
2292- s,
2293- "mod" . to_string ( ) ,
2294- name. span ,
2295- ) ) ;
2296- return (
2297- Pipeline :: from_vec ( vec ! [ Expression :: new(
2298- working_set,
2299- Expr :: Call ( call) ,
2300- call_span,
2301- Type :: Any ,
2302- ) ] ) ,
2303- None ,
2304- ) ;
2305- }
2306- ( s, name. span , name. clone ( ) )
2307- } else {
2308- working_set. error ( ParseError :: UnknownState (
2309- "internal error: name not a string" . into ( ) ,
2310- Span :: concat ( spans) ,
2306+ let ( module_name_or_path, module_name_or_path_span) = if let Some ( name) = call. positional_nth ( 0 )
2307+ {
2308+ if let Some ( s) = name. as_string ( ) {
2309+ if let Some ( mod_name) = module_name
2310+ && s. as_bytes ( ) == mod_name
2311+ {
2312+ working_set. error ( ParseError :: NamedAsModule (
2313+ "module" . to_string ( ) ,
2314+ s,
2315+ "mod" . to_string ( ) ,
2316+ name. span ,
23112317 ) ) ;
2312- return ( garbage_pipeline ( working_set, spans) , None ) ;
2318+ return (
2319+ Pipeline :: from_vec ( vec ! [ Expression :: new(
2320+ working_set,
2321+ Expr :: Call ( call) ,
2322+ call_span,
2323+ Type :: Any ,
2324+ ) ] ) ,
2325+ None ,
2326+ ) ;
23132327 }
2328+ ( s, name. span )
23142329 } else {
23152330 working_set. error ( ParseError :: UnknownState (
2316- "internal error: missing positional " . into ( ) ,
2331+ "internal error: name not a string " . into ( ) ,
23172332 Span :: concat ( spans) ,
23182333 ) ) ;
23192334 return ( garbage_pipeline ( working_set, spans) , None ) ;
2320- } ;
2321-
2322- let pipeline = Pipeline :: from_vec ( vec ! [ Expression :: new (
2323- working_set ,
2324- Expr :: Call ( call ) ,
2325- call_span ,
2326- Type :: Any ,
2327- ) ] ) ;
2335+ }
2336+ } else {
2337+ working_set . error ( ParseError :: UnknownState (
2338+ "internal error: missing positional" . into ( ) ,
2339+ Span :: concat ( spans ) ,
2340+ ) ) ;
2341+ return ( garbage_pipeline ( working_set , spans ) , None ) ;
2342+ } ;
23282343
23292344 if spans. len ( ) == split_id + 1 {
2345+ let pipeline = Pipeline :: from_vec ( vec ! [ Expression :: new(
2346+ working_set,
2347+ Expr :: Call ( call) ,
2348+ call_span,
2349+ Type :: Any ,
2350+ ) ] ) ;
2351+
23302352 if let Some ( module_id) = parse_module_file_or_dir (
23312353 working_set,
23322354 module_name_or_path. as_bytes ( ) ,
@@ -2389,19 +2411,7 @@ pub fn parse_module(
23892411 Type :: Block ,
23902412 ) ;
23912413
2392- let module_decl_id = working_set
2393- . find_decl ( b"module" )
2394- . expect ( "internal error: missing module command" ) ;
2395-
2396- let call = Box :: new ( Call {
2397- head : Span :: concat ( & spans[ ..split_id] ) ,
2398- decl_id : module_decl_id,
2399- arguments : vec ! [
2400- Argument :: Positional ( module_name_or_path_expr) ,
2401- Argument :: Positional ( block_expr) ,
2402- ] ,
2403- parser_info : HashMap :: new ( ) ,
2404- } ) ;
2414+ call. set_kth_argument ( 1 , Argument :: Positional ( block_expr) ) ;
24052415
24062416 (
24072417 Pipeline :: from_vec ( vec ! [ Expression :: new(
@@ -2463,6 +2473,7 @@ pub fn parse_use(
24632473 Span :: concat ( command_spans) ,
24642474 rest_spans,
24652475 decl_id,
2476+ ArgumentParsingLevel :: Full ,
24662477 ) ;
24672478
24682479 let call_span = Span :: concat ( spans) ;
@@ -2681,7 +2692,13 @@ pub fn parse_hide(working_set: &mut StateWorkingSet, lite_command: &LiteCommand)
26812692 call,
26822693 output,
26832694 call_kind,
2684- } = parse_internal_call ( working_set, spans[ 0 ] , & spans[ 1 ..] , decl_id) ;
2695+ } = parse_internal_call (
2696+ working_set,
2697+ spans[ 0 ] ,
2698+ & spans[ 1 ..] ,
2699+ decl_id,
2700+ ArgumentParsingLevel :: Full ,
2701+ ) ;
26852702
26862703 if call_kind != CallKind :: Valid {
26872704 return Pipeline :: from_vec ( vec ! [ Expression :: new(
@@ -3284,8 +3301,13 @@ pub fn parse_let(working_set: &mut StateWorkingSet, spans: &[Span]) -> Pipeline
32843301 }
32853302 }
32863303 }
3287- let ParsedInternalCall { call, output, .. } =
3288- parse_internal_call ( working_set, spans[ 0 ] , & spans[ 1 ..] , decl_id) ;
3304+ let ParsedInternalCall { call, output, .. } = parse_internal_call (
3305+ working_set,
3306+ spans[ 0 ] ,
3307+ & spans[ 1 ..] ,
3308+ decl_id,
3309+ ArgumentParsingLevel :: Full ,
3310+ ) ;
32893311
32903312 return Pipeline :: from_vec ( vec ! [ Expression :: new(
32913313 working_set,
@@ -3445,8 +3467,13 @@ pub fn parse_const(working_set: &mut StateWorkingSet, spans: &[Span]) -> (Pipeli
34453467 }
34463468 }
34473469 }
3448- let ParsedInternalCall { call, output, .. } =
3449- parse_internal_call ( working_set, spans[ 0 ] , & spans[ 1 ..] , decl_id) ;
3470+ let ParsedInternalCall { call, output, .. } = parse_internal_call (
3471+ working_set,
3472+ spans[ 0 ] ,
3473+ & spans[ 1 ..] ,
3474+ decl_id,
3475+ ArgumentParsingLevel :: Full ,
3476+ ) ;
34503477
34513478 return (
34523479 Pipeline :: from_vec ( vec ! [ Expression :: new(
@@ -3567,8 +3594,13 @@ pub fn parse_mut(working_set: &mut StateWorkingSet, spans: &[Span]) -> Pipeline
35673594 }
35683595 }
35693596 }
3570- let ParsedInternalCall { call, output, .. } =
3571- parse_internal_call ( working_set, spans[ 0 ] , & spans[ 1 ..] , decl_id) ;
3597+ let ParsedInternalCall { call, output, .. } = parse_internal_call (
3598+ working_set,
3599+ spans[ 0 ] ,
3600+ & spans[ 1 ..] ,
3601+ decl_id,
3602+ ArgumentParsingLevel :: Full ,
3603+ ) ;
35723604
35733605 return Pipeline :: from_vec ( vec ! [ Expression :: new(
35743606 working_set,
@@ -3619,7 +3651,13 @@ pub fn parse_source(working_set: &mut StateWorkingSet, lite_command: &LiteComman
36193651 call,
36203652 output,
36213653 call_kind,
3622- } = parse_internal_call ( working_set, spans[ 0 ] , & spans[ 1 ..] , decl_id) ;
3654+ } = parse_internal_call (
3655+ working_set,
3656+ spans[ 0 ] ,
3657+ & spans[ 1 ..] ,
3658+ decl_id,
3659+ ArgumentParsingLevel :: Full ,
3660+ ) ;
36233661
36243662 if call_kind == CallKind :: Help {
36253663 return Pipeline :: from_vec ( vec ! [ Expression :: new(
@@ -3631,10 +3669,8 @@ pub fn parse_source(working_set: &mut StateWorkingSet, lite_command: &LiteComman
36313669 }
36323670
36333671 // Command and one file name
3634- if spans. len ( ) >= 2 {
3635- let expr = parse_value ( working_set, spans[ 1 ] , & SyntaxShape :: Any ) ;
3636-
3637- let val = match eval_constant ( working_set, & expr) {
3672+ if let Some ( expr) = call. positional_nth ( 0 ) {
3673+ let val = match eval_constant ( working_set, expr) {
36383674 Ok ( val) => val,
36393675 Err ( err) => {
36403676 working_set. error ( err. wrap ( working_set, Span :: concat ( & spans[ 1 ..] ) ) ) ;
@@ -3778,7 +3814,13 @@ pub fn parse_where_expr(working_set: &mut StateWorkingSet, spans: &[Span]) -> Ex
37783814 call,
37793815 output,
37803816 call_kind,
3781- } = parse_internal_call ( working_set, spans[ 0 ] , & spans[ 1 ..] , decl_id) ;
3817+ } = parse_internal_call (
3818+ working_set,
3819+ spans[ 0 ] ,
3820+ & spans[ 1 ..] ,
3821+ decl_id,
3822+ ArgumentParsingLevel :: Full ,
3823+ ) ;
37823824
37833825 if call_kind != CallKind :: Valid {
37843826 return Expression :: new ( working_set, Expr :: Call ( call) , Span :: concat ( spans) , output) ;
0 commit comments