Skip to content

Commit 2fda9b6

Browse files
committed
---
yaml --- r: 29729 b: refs/heads/incoming c: d704fc9 h: refs/heads/master i: 29727: 4e102a0 v: v3
1 parent 3b24a94 commit 2fda9b6

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 96fdad2fb7210c73c1608c6d90f94a2b4335e0b7
9+
refs/heads/incoming: d704fc9196c9c80e1c29a04ef02d1165ad2cd760
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// A test of the macro system. Can we do HTML literals?
2+
3+
// xfail-pretty
4+
// xfail-test
5+
6+
macro_rules! html {
7+
{ $($body:tt)* } => {
8+
let builder = HTMLBuilder();
9+
build_html!{builder := $($body)*};
10+
builder.getDoc()
11+
}
12+
}
13+
14+
macro_rules! build_html {
15+
{ $builder:expr := </$tag:ident> $($rest:tt)* } => {
16+
$builder.endTag(stringify!($tag));
17+
build_html!{ $builder := $($rest)* };
18+
};
19+
20+
{ $builder:expr := <$tag:ident> $($rest:tt)* } => {
21+
$builder.beginTag(stringify!($tag));
22+
build_html!{ $builder := $($rest)* };
23+
};
24+
25+
{ $builder:expr := . $($rest:tt)* } => {
26+
$builder.addText(~".");
27+
build_html!{ $builder := $($rest)* };
28+
};
29+
30+
{ $builder:expr := $word:ident $($rest:tt)* } => {
31+
$builder.addText(stringify!($word));
32+
build_html!{ $builder := $($rest)* };
33+
};
34+
35+
{ $builder:expr := } => { }
36+
}
37+
38+
fn main() {
39+
40+
let page = html! {
41+
<html>
42+
<head><title>This is the title.</title></head>
43+
<body>
44+
<p>This is some text</p>
45+
</body>
46+
</html>
47+
};
48+
49+
// When we can do this, we are successful:
50+
//
51+
//let page = tag(~"html", ~[tag(~"head", ~[...])])
52+
53+
}
54+
55+
enum HTMLFragment {
56+
}
57+
58+
struct HTMLBuilder {
59+
bar: ();
60+
fn getDoc() -> HTMLFragment { fail }
61+
fn beginTag(tag: ~str) { }
62+
fn endTag(tag: ~str) { }
63+
fn addText(test: ~str) { }
64+
}
65+
66+
fn HTMLBuilder() -> HTMLBuilder {
67+
HTMLBuilder { bar: () }
68+
}

0 commit comments

Comments
 (0)