Use shiny new slicing syntax
This commit is contained in:
parent
05c68067dd
commit
81cbfb9267
4 changed files with 18 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
||||||
#![crate_type = "dylib"]
|
#![crate_type = "dylib"]
|
||||||
#![feature(globs, plugin_registrar, quote, macro_rules)]
|
#![feature(globs, plugin_registrar, quote, macro_rules, slicing_syntax)]
|
||||||
|
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
|
@ -16,7 +16,7 @@ mod render;
|
||||||
fn expand_html<'cx>(cx: &'cx mut ExtCtxt, sp: Span, args: &[TokenTree]) -> Box<MacResult + 'cx> {
|
fn expand_html<'cx>(cx: &'cx mut ExtCtxt, sp: Span, args: &[TokenTree]) -> Box<MacResult + 'cx> {
|
||||||
match parse::parse(cx, args) {
|
match parse::parse(cx, args) {
|
||||||
Some(markups) => {
|
Some(markups) => {
|
||||||
let expr = render::render(cx, &*markups);
|
let expr = render::render(cx, markups[]);
|
||||||
MacExpr::new(expr)
|
MacExpr::new(expr)
|
||||||
},
|
},
|
||||||
None => DummyResult::any(sp),
|
None => DummyResult::any(sp),
|
||||||
|
|
|
@ -206,7 +206,7 @@ impl<'cx, 's, 'i> Parser<'cx, 's, 'i> {
|
||||||
match self.input {
|
match self.input {
|
||||||
[TtDelimited(_, ref d), ..] if d.delim == token::DelimToken::Brace => {
|
[TtDelimited(_, ref d), ..] if d.delim == token::DelimToken::Brace => {
|
||||||
self.shift(1);
|
self.shift(1);
|
||||||
Parser { cx: self.cx, input: &*d.tts }.markups()
|
Parser { cx: self.cx, input: d.tts[] }.markups()
|
||||||
.map(Markup::Block)
|
.map(Markup::Block)
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -228,7 +228,7 @@ fn lit_to_string(cx: &mut ExtCtxt, lit: Lit, minus: bool) -> Option<String> {
|
||||||
return None;
|
return None;
|
||||||
},
|
},
|
||||||
LitChar(c) => result.push(c),
|
LitChar(c) => result.push(c),
|
||||||
LitInt(x, _) => result.push_str(&*x.to_string()),
|
LitInt(x, _) => result.push_str(x.to_string()[]),
|
||||||
LitFloat(s, _) | LitFloatUnsuffixed(s) => result.push_str(s.get()),
|
LitFloat(s, _) | LitFloatUnsuffixed(s) => result.push_str(s.get()),
|
||||||
LitBool(b) => result.push_str(if b { "true" } else { "false" }),
|
LitBool(b) => result.push_str(if b { "true" } else { "false" }),
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,7 +27,7 @@ fn render_markup(cx: &mut ExtCtxt, markup: &Markup, w: Ident, out: &mut Vec<P<St
|
||||||
for markup in markups.iter() {
|
for markup in markups.iter() {
|
||||||
render_markup(cx, markup, w, out);
|
render_markup(cx, markup, w, out);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
Value(ref value) => {
|
Value(ref value) => {
|
||||||
let expr = render_value(cx, value, w, false);
|
let expr = render_value(cx, value, w, false);
|
||||||
out.push(quote_stmt!(cx, $expr));
|
out.push(quote_stmt!(cx, $expr));
|
||||||
|
@ -41,14 +41,15 @@ fn render_value(cx: &mut ExtCtxt, value: &Value, w: Ident, is_attr: bool) -> P<E
|
||||||
let &Value { ref value, escape } = value;
|
let &Value { ref value, escape } = value;
|
||||||
match *value {
|
match *value {
|
||||||
Literal(ref s) => {
|
Literal(ref s) => {
|
||||||
let s = &*match escape {
|
let s = match escape {
|
||||||
NoEscape => (&**s).into_cow(),
|
NoEscape => s[].into_cow(),
|
||||||
Escape => if is_attr {
|
Escape => if is_attr {
|
||||||
escape::attribute(&**s).into_cow()
|
escape::attribute(s[]).into_cow()
|
||||||
} else {
|
} else {
|
||||||
escape::non_attribute(&**s).into_cow()
|
escape::non_attribute(s[]).into_cow()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
let s = s[];
|
||||||
quote_expr!(cx, {
|
quote_expr!(cx, {
|
||||||
try!($w.write_str($s))
|
try!($w.write_str($s))
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,14 +7,14 @@ extern crate maud;
|
||||||
fn it_works() {
|
fn it_works() {
|
||||||
let template = html!("du\tcks" -23 3.14 '\n' "geese");
|
let template = html!("du\tcks" -23 3.14 '\n' "geese");
|
||||||
let s = maud::render(template);
|
let s = maud::render(template);
|
||||||
assert_eq!(&*s, "du\tcks-233.14\ngeese");
|
assert_eq!(s, "du\tcks-233.14\ngeese");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn escaping() {
|
fn escaping() {
|
||||||
let template = html!("<flim&flam>");
|
let template = html!("<flim&flam>");
|
||||||
let s = maud::render(template);
|
let s = maud::render(template);
|
||||||
assert_eq!(&*s, "<flim&flam>");
|
assert_eq!(s, "<flim&flam>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -27,7 +27,7 @@ fn blocks() {
|
||||||
}
|
}
|
||||||
" swans"
|
" swans"
|
||||||
});
|
});
|
||||||
assert_eq!(&*s, "hello ducks geese swans");
|
assert_eq!(s, "hello ducks geese swans");
|
||||||
}
|
}
|
||||||
|
|
||||||
mod splice {
|
mod splice {
|
||||||
|
@ -36,13 +36,13 @@ mod splice {
|
||||||
#[test]
|
#[test]
|
||||||
fn literal() {
|
fn literal() {
|
||||||
let s = maud::render(html! { $"<pinkie>" });
|
let s = maud::render(html! { $"<pinkie>" });
|
||||||
assert_eq!(&*s, "<pinkie>");
|
assert_eq!(s, "<pinkie>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn raw_literal() {
|
fn raw_literal() {
|
||||||
let s = maud::render(html! { $$"<pinkie>" });
|
let s = maud::render(html! { $$"<pinkie>" });
|
||||||
assert_eq!(&*s, "<pinkie>");
|
assert_eq!(s, "<pinkie>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -56,7 +56,7 @@ mod splice {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assert_eq!(&*s, "3628800");
|
assert_eq!(s, "3628800");
|
||||||
}
|
}
|
||||||
|
|
||||||
static BEST_PONY: &'static str = "Pinkie Pie";
|
static BEST_PONY: &'static str = "Pinkie Pie";
|
||||||
|
@ -64,7 +64,7 @@ mod splice {
|
||||||
#[test]
|
#[test]
|
||||||
fn statics() {
|
fn statics() {
|
||||||
let s = maud::render(html! { $BEST_PONY });
|
let s = maud::render(html! { $BEST_PONY });
|
||||||
assert_eq!(&*s, "Pinkie Pie");
|
assert_eq!(s, "Pinkie Pie");
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: See <https://github.com/rust-lang/rust/issues/15962>
|
// FIXME: See <https://github.com/rust-lang/rust/issues/15962>
|
||||||
|
@ -74,7 +74,7 @@ mod splice {
|
||||||
fn closure() {
|
fn closure() {
|
||||||
let best_pony = "Pinkie Pie";
|
let best_pony = "Pinkie Pie";
|
||||||
let s = maud::render(html! { $best_pony });
|
let s = maud::render(html! { $best_pony });
|
||||||
assert_eq!(&*s, "Pinkie Pie");
|
assert_eq!(s, "Pinkie Pie");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue