diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 3cad00023d..e68bbc41de 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -513,7 +513,8 @@ pub fn parse_use( .into_iter() .map(|(name, id)| { let mut new_name = import_pattern.head.to_vec(); - new_name.push(b'.'); + new_name.push(b':'); + new_name.push(b':'); new_name.extend(&name); (new_name, id) }) @@ -628,7 +629,8 @@ pub fn parse_hide( .into_iter() .map(|name| { let mut new_name = import_pattern.head.to_vec(); - new_name.push(b'.'); + new_name.push(b':'); + new_name.push(b':'); new_name.extend(&name); new_name }) @@ -639,7 +641,8 @@ pub fn parse_hide( .filter(|n| n == name) .map(|n| { let mut new_name = import_pattern.head.to_vec(); - new_name.push(b'.'); + new_name.push(b':'); + new_name.push(b':'); new_name.extend(&n); new_name }) @@ -660,7 +663,8 @@ pub fn parse_hide( .filter_map(|n| if n == name { Some(n.clone()) } else { None }) .map(|n| { let mut new_name = import_pattern.head.to_vec(); - new_name.push(b'.'); + new_name.push(b':'); + new_name.push(b':'); new_name.extend(n); new_name }) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 893c5f492e..7ba36d127f 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -1698,7 +1698,7 @@ pub fn parse_import_pattern( let source = working_set.get_span_contents(span); let mut error = None; - let (tokens, err) = lex(source, span.start, &[], &[b'.']); + let (tokens, err) = lex(source, span.start, &[], &[b':']); error = error.or(err); if tokens.is_empty() { @@ -1713,7 +1713,7 @@ pub fn parse_import_pattern( let head = working_set.get_span_contents(tokens[0].span).to_vec(); - if let Some(tail) = tokens.get(2) { + if let Some(tail) = tokens.get(3) { // FIXME: expand this to handle deeper imports once we support module imports let tail_span = tail.span; let tail = working_set.get_span_contents(tail.span); diff --git a/src/tests.rs b/src/tests.rs index fa2d323065..30bc49f383 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -389,7 +389,7 @@ fn better_block_types() -> TestResult { #[test] fn module_imports_1() -> TestResult { run_test( - r#"module foo { export def a [] { 1 }; def b [] { 2 } }; use foo; foo.a"#, + r#"module foo { export def a [] { 1 }; def b [] { 2 } }; use foo; foo::a"#, "1", ) } @@ -397,7 +397,7 @@ fn module_imports_1() -> TestResult { #[test] fn module_imports_2() -> TestResult { run_test( - r#"module foo { export def a [] { 1 }; def b [] { 2 } }; use foo.a; a"#, + r#"module foo { export def a [] { 1 }; def b [] { 2 } }; use foo::a; a"#, "1", ) } @@ -405,7 +405,7 @@ fn module_imports_2() -> TestResult { #[test] fn module_imports_3() -> TestResult { run_test( - r#"module foo { export def a [] { 1 }; export def b [] { 2 } }; use foo.*; b"#, + r#"module foo { export def a [] { 1 }; export def b [] { 2 } }; use foo::*; b"#, "2", ) } @@ -413,7 +413,7 @@ fn module_imports_3() -> TestResult { #[test] fn module_imports_4() -> TestResult { fail_test( - r#"module foo { export def a [] { 1 }; export def b [] { 2 } }; use foo.c"#, + r#"module foo { export def a [] { 1 }; export def b [] { 2 } }; use foo::c"#, "not find import", ) } @@ -421,7 +421,7 @@ fn module_imports_4() -> TestResult { #[test] fn module_imports_5() -> TestResult { run_test( - r#"module foo { export def a [] { 1 }; def b [] { 2 }; export def c [] { 3 } }; use foo.[a, c]; c"#, + r#"module foo { export def a [] { 1 }; def b [] { 2 }; export def c [] { 3 } }; use foo::[a, c]; c"#, "3", ) } @@ -429,7 +429,7 @@ fn module_imports_5() -> TestResult { #[test] fn module_import_uses_internal_command() -> TestResult { run_test( - r#"module foo { def b [] { 2 }; export def a [] { b } }; use foo; foo.a"#, + r#"module foo { def b [] { 2 }; export def a [] { b } }; use foo; foo::a"#, "2", ) } @@ -491,7 +491,7 @@ fn hide_twice_not_allowed() -> TestResult { #[test] fn hides_import_1() -> TestResult { fail_test( - r#"module spam { export def foo [] { "foo" } }; use spam; hide spam.foo; foo"#, + r#"module spam { export def foo [] { "foo" } }; use spam; hide spam::foo; foo"#, not_found_msg(), ) } @@ -499,7 +499,7 @@ fn hides_import_1() -> TestResult { #[test] fn hides_import_2() -> TestResult { fail_test( - r#"module spam { export def foo [] { "foo" } }; use spam; hide spam.*; foo"#, + r#"module spam { export def foo [] { "foo" } }; use spam; hide spam::*; foo"#, not_found_msg(), ) } @@ -507,7 +507,7 @@ fn hides_import_2() -> TestResult { #[test] fn hides_import_3() -> TestResult { fail_test( - r#"module spam { export def foo [] { "foo" } }; use spam; hide spam.[foo]; foo"#, + r#"module spam { export def foo [] { "foo" } }; use spam; hide spam::[foo]; foo"#, not_found_msg(), ) } @@ -515,7 +515,7 @@ fn hides_import_3() -> TestResult { #[test] fn hides_import_4() -> TestResult { fail_test( - r#"module spam { export def foo [] { "foo" } }; use spam.foo; hide foo; foo"#, + r#"module spam { export def foo [] { "foo" } }; use spam::foo; hide foo; foo"#, not_found_msg(), ) } @@ -523,7 +523,7 @@ fn hides_import_4() -> TestResult { #[test] fn hides_import_5() -> TestResult { fail_test( - r#"module spam { export def foo [] { "foo" } }; use spam.*; hide foo; foo"#, + r#"module spam { export def foo [] { "foo" } }; use spam::*; hide foo; foo"#, not_found_msg(), ) } @@ -539,7 +539,7 @@ fn def_twice_should_fail() -> TestResult { #[test] fn use_import_after_hide() -> TestResult { run_test( - r#"module spam { export def foo [] { "foo" } }; use spam.foo; hide foo; use spam.foo; foo"#, + r#"module spam { export def foo [] { "foo" } }; use spam::foo; hide foo; use spam::foo; foo"#, "foo", ) } @@ -547,7 +547,7 @@ fn use_import_after_hide() -> TestResult { #[test] fn hide_shadowed_decl() -> TestResult { run_test( - r#"module spam { export def foo [] { "bar" } }; def foo [] { "foo" }; do { use spam.foo; hide foo; foo }"#, + r#"module spam { export def foo [] { "bar" } }; def foo [] { "foo" }; do { use spam::foo; hide foo; foo }"#, "foo", ) }