Make kw!(foo.bar/bar.baz) work.

This commit is contained in:
Nick Alexander 2018-07-06 14:18:48 -07:00
parent 07c5d733d6
commit f65512158b
2 changed files with 24 additions and 8 deletions

View file

@ -12,7 +12,7 @@ authors = [
"Thom Chiovoloni <tchiovoloni@mozilla.com>", "Thom Chiovoloni <tchiovoloni@mozilla.com>",
] ]
name = "mentat" name = "mentat"
version = "0.8.0" version = "0.8.1"
build = "build/version.rs" build = "build/version.rs"
[features] [features]

View file

@ -83,22 +83,36 @@ macro_rules! var {
/// https://github.com/rust-lang/rust/issues/29638. /// https://github.com/rust-lang/rust/issues/29638.
#[macro_export] #[macro_export]
macro_rules! kw { macro_rules! kw {
( : $n:ident ) => { ( : $ns:ident$(. $nss:ident)+ / $nn:ident$(. $nns:ident)+ ) => {
$crate::Keyword::plain( $crate::Keyword::namespaced(
stringify!($n) concat!(stringify!($ns) $(, ".", stringify!($nss))*),
concat!(stringify!($nn) $(, ".", stringify!($nns))*),
) )
}; };
( : $ns:ident / $n:ident ) => { ( : $ns:ident$(. $nss:ident)+ / $nn:ident ) => {
$crate::Keyword::namespaced(
concat!(stringify!($ns) $(, ".", stringify!($nss))*),
stringify!($nn)
)
};
( : $ns:ident / $nn:ident$(. $nns:ident)+ ) => {
$crate::Keyword::namespaced( $crate::Keyword::namespaced(
stringify!($ns), stringify!($ns),
stringify!($n) concat!(stringify!($nn) $(, ".", stringify!($nns))*),
) )
}; };
( : $ns:ident$(. $nss:ident)+ / $n:ident ) => { ( : $ns:ident / $nn:ident ) => {
$crate::Keyword::namespaced( $crate::Keyword::namespaced(
concat!(stringify!($ns) $(, ".", stringify!($nss))+), stringify!($ns),
stringify!($nn)
)
};
( : $n:ident ) => {
$crate::Keyword::plain(
stringify!($n) stringify!($n)
) )
}; };
@ -181,6 +195,8 @@ mod tests {
fn test_kw() { fn test_kw() {
assert_eq!(kw!(:foo/bar), Keyword::namespaced("foo", "bar")); assert_eq!(kw!(:foo/bar), Keyword::namespaced("foo", "bar"));
assert_eq!(kw!(:org.mozilla.foo/bar_baz), Keyword::namespaced("org.mozilla.foo", "bar_baz")); assert_eq!(kw!(:org.mozilla.foo/bar_baz), Keyword::namespaced("org.mozilla.foo", "bar_baz"));
assert_eq!(kw!(:_foo_/_bar_._baz_), Keyword::namespaced("_foo_", "_bar_._baz_"));
assert_eq!(kw!(:_org_._mozilla_._foo_/_bar_._baz_), Keyword::namespaced("_org_._mozilla_._foo_", "_bar_._baz_"));
} }
#[test] #[test]