diff --git a/do_with_in_base/src/lib.rs b/do_with_in_base/src/lib.rs index 4d5d70b..d372bb0 100644 --- a/do_with_in_base/src/lib.rs +++ b/do_with_in_base/src/lib.rs @@ -1735,6 +1735,7 @@ use std::path::{Path, PathBuf}; use std::ffi::OsStr; use std::fs::File; pub fn importHandler(c: Configuration, v: Variables, data: Option, t: TokenStream2) -> (Variables, TokenStream2) { + let mut reset = false; let base = match c.clone().file { Some(x) => x, None => file!().to_string(), @@ -1751,15 +1752,31 @@ pub fn importHandler(c: Configuration, v: Variables(&segment.clone().to_string()) { - Ok(x) => path.push(x.value()), - _ => panic!("oqwiefhawlkfhLQIPLE"), - }; - } else { - cont = false; - } + match stream.next() { + Some(TokenTree2::Literal(segment)) => { + match syn::parse_str::(&segment.clone().to_string()) { + Ok(x) => { + if reset { + path = Path::new(&x.value()).to_path_buf(); + reset = false; + } else { + path.push(x.value()); + } + }, + _ => panic!("oqwiefhawlkfhLQIPLE"), + }; + }, + Some(TokenTree2::Ident(id)) if id.to_string() == "Base" => { + reset = true; + }, + _ => { + cont = false; + }, + }; } + if reset { + return (v, quote!{compile_error!{ "Path finished with a 'Base'; we need an actual file reference." }}); + }; let mut f = match File::open(path.clone()) { Ok(s) => s, Err(e) => { diff --git a/do_with_in_internal_macros/tests/do_with_in_test.rs b/do_with_in_internal_macros/tests/do_with_in_test.rs index ae8e7ea..7809bed 100644 --- a/do_with_in_internal_macros/tests/do_with_in_test.rs +++ b/do_with_in_internal_macros/tests/do_with_in_test.rs @@ -517,6 +517,41 @@ fn import_test2() { assert_eq!(a, 1); } +#[test] +fn import_test3() { + do_with_in!{ + sigil: $ + do + $(import Base "do_with_in_internal_macros" "tests" "import.$") + + let $b = $a; + }; + assert_eq!(c, 1); +} + +#[test] +fn import_test4() { + do_with_in!{ + sigil: $ + do + $(import Base "import_base_test.$") + + let $b = $a; + }; + assert_eq!(c, 1); +} + +#[test] +fn import_test5() { + do_with_in!{ + sigil: $ + do + $(import Base "import_base_test2.$") + let $z = $c; + }; + assert_eq!(twelve, 12); +} + /*#[test] fn for_test1() { do_with_in!{ diff --git a/do_with_in_internal_macros/tests/import_2.$ b/do_with_in_internal_macros/tests/import_2.$ new file mode 100644 index 0000000..6c01c8a --- /dev/null +++ b/do_with_in_internal_macros/tests/import_2.$ @@ -0,0 +1,5 @@ +$(let + a = {3} + b = {4} + z = {twelve} + ) diff --git a/import_base_test.$ b/import_base_test.$ new file mode 100644 index 0000000..08f6cbd --- /dev/null +++ b/import_base_test.$ @@ -0,0 +1,4 @@ +$(let + a = {1} + b = {c} +) diff --git a/import_base_test2.$ b/import_base_test2.$ new file mode 100644 index 0000000..5644e2a --- /dev/null +++ b/import_base_test2.$ @@ -0,0 +1,4 @@ +$(import "do_with_in_internal_macros" "tests" "import_2.$") + +$(var c = {$(arithmetic u8 $a * $b)}) +