Skip to content

Commit

Permalink
Allow path lookups in un-delimited splices
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Feb 1, 2016
1 parent 3deb7a7 commit ed8c119
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions maud_macros/src/parse.rs
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 @@ -199,6 +202,7 @@ impl<'cx, 'i> Parser<'cx, 'i> {
// ???
_ => {
if let [ref tt, ..] = self.input {
println!("{:?}", tt);
parse_error!(self, tt.get_span(), "invalid syntax");
} else {
parse_error!(self, self.span, "unexpected end of block");
Expand Down Expand Up @@ -328,6 +332,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
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");
}

0 comments on commit ed8c119

Please sign in to comment.