Allow path lookups in un-delimited splices
This commit is contained in:
parent
3deb7a7625
commit
6b0b7a00d7
2 changed files with 23 additions and 0 deletions
|
@ -32,6 +32,9 @@ macro_rules! pound {
|
||||||
macro_rules! dot {
|
macro_rules! dot {
|
||||||
() => (TokenTree::Token(_, Token::Dot))
|
() => (TokenTree::Token(_, Token::Dot))
|
||||||
}
|
}
|
||||||
|
macro_rules! modsep {
|
||||||
|
() => (TokenTree::Token(_, Token::ModSep))
|
||||||
|
}
|
||||||
macro_rules! eq {
|
macro_rules! eq {
|
||||||
() => (TokenTree::Token(_, Token::Eq))
|
() => (TokenTree::Token(_, Token::Eq))
|
||||||
}
|
}
|
||||||
|
@ -328,6 +331,12 @@ impl<'cx, 'i> Parser<'cx, 'i> {
|
||||||
tts.push(dot.clone());
|
tts.push(dot.clone());
|
||||||
tts.push(ident.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 `[]`
|
// Munch function calls `()` and indexing operations `[]`
|
||||||
[TokenTree::Delimited(sp, ref d), ..] if d.delim != DelimToken::Brace => {
|
[TokenTree::Delimited(sp, ref d), ..] if d.delim != DelimToken::Brace => {
|
||||||
self.shift(1);
|
self.shift(1);
|
||||||
|
|
|
@ -309,3 +309,17 @@ fn issue_23() {
|
||||||
let s = to_string!(p { "Hi, " $name "!" });
|
let s = to_string!(p { "Hi, " $name "!" });
|
||||||
assert_eq!(s, "<p>Hi, Lyra!</p>");
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue