Skip to content

Commit 0097bfc

Browse files
committed
---
yaml --- r: 27707 b: refs/heads/try c: d704fc9 h: refs/heads/master i: 27705: 44c83ef 27703: 4732984 v: v3
1 parent 4d3fd28 commit 0097bfc

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
@@ -2,7 +2,7 @@
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5-
refs/heads/try: 96fdad2fb7210c73c1608c6d90f94a2b4335e0b7
5+
refs/heads/try: d704fc9196c9c80e1c29a04ef02d1165ad2cd760
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
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)