diff --git a/maud_macros/src/parse.rs b/maud_macros/src/parse.rs index 4a048dba..713eafc3 100644 --- a/maud_macros/src/parse.rs +++ b/maud_macros/src/parse.rs @@ -32,6 +32,9 @@ macro_rules! pound { macro_rules! dot { () => (TokenTree::Token(_, Token::Dot)) } +macro_rules! modsep { + () => (TokenTree::Token(_, Token::ModSep)) +} macro_rules! eq { () => (TokenTree::Token(_, Token::Eq)) } @@ -337,6 +340,12 @@ impl<'cx, 'i> Parser<'cx, 'i> { tts.push(dot.clone()); tts.push(num.clone()); }, + // Munch path lookups e.g. `$some_mod::Struct` + [ref sep @ modsep!(), ref ident @ ident!(_, _), ..] => { + self.shift(2); + tts.push(sep.clone()); + tts.push(ident.clone()); + }, // Munch function calls `()` and indexing operations `[]` [TokenTree::Delimited(sp, ref d), ..] if d.delim != DelimToken::Brace => { self.shift(1); diff --git a/maud_macros/tests/tests.rs b/maud_macros/tests/tests.rs index 9973f8f6..265cc004 100644 --- a/maud_macros/tests/tests.rs +++ b/maud_macros/tests/tests.rs @@ -318,3 +318,15 @@ fn tuple_accessors() { assert_eq!(s, "ducks"); } +#[test] +fn splice_with_path() { + mod inner { + pub fn name() -> &'static str { + "Maud" + } + } + + let mut s = String::new(); + html!(s, $inner::name()).unwrap(); + assert_eq!(s, "Maud"); +}