Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow path lookups in un-delimited splices #27

Merged
merged 1 commit into from
Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions maud_macros/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -328,6 +331,12 @@ impl<'cx, 'i> Parser<'cx, 'i> {
tts.push(dot.clone());
tts.push(ident.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);
Expand Down
14 changes: 14 additions & 0 deletions maud_macros/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,17 @@ fn issue_23() {
let s = to_string!(p { "Hi, " $name "!" });
assert_eq!(s, "<p>Hi, Lyra!</p>");
}

#[test]
fn splice_with_path() {
mod inner {
pub fn name() -> &'static str {
"Rusticle"
}
}

let mut s = String::new();
html!(s, $inner::name()).unwrap();
assert_eq!(s, "Rusticle");
}