Skip to content

Commit

Permalink
Merge pull request #27 from Nemo157/path-in-splice
Browse files Browse the repository at this point in the history
Allow path lookups in un-delimited splices
  • Loading branch information
lambda-fairy committed Feb 2, 2016
2 parents 124766b + 6b0b7a0 commit 0440f5c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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 @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions maud_macros/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 0440f5c

Please sign in to comment.