]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/html-literals.rs
23970af957655f88019c3e924409535f93c936eb
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // A test of the macro system. Can we do HTML literals?
13 // ignore-test FIXME #20673
17 This is an HTML parser written as a macro. It's all CPS, and we have
18 to carry around a bunch of state. The arguments to macros all look like this:
20 { tag_stack* # expr* # tokens }
22 The stack keeps track of where we are in the tree. The expr is a list
23 of children of the current node. The tokens are everything that's
27 use HTMLFragment
::{tag, text}
;
31 parse_node
!( []; []; $
($body
)* )
35 macro_rules
! parse_node
{
37 [:$head
:ident ($
(:$head_nodes
:expr
),*)
38 $
(:$tags
:ident ($
(:$tag_nodes
:expr
),*))*];
40 </$tag
:ident
> $
($rest
:tt
)*
43 [$
(: $
tags ($
(:$tag_nodes
),*))*];
44 [$
(:$head_nodes
,)* :tag(stringify
!($head
).to_string(),
51 [$
(:$tags
:ident ($
(:$tag_nodes
:expr
),*) )*];
53 <$tag
:ident
> $
($rest
:tt
)*
56 [:$
tag ($
(:$nodes
)*) $
(: $
tags ($
(:$tag_nodes
),*) )*];
63 [$
(:$tags
:ident ($
(:$tag_nodes
:expr
),*) )*];
68 [$
(: $
tags ($
(:$tag_nodes
),*))*];
69 [$
(:$nodes
,)* :text(".".to_string())];
75 [$
(:$tags
:ident ($
(:$tag_nodes
:expr
),*) )*];
77 $word
:ident $
($rest
:tt
)*
80 [$
(: $
tags ($
(:$tag_nodes
),*))*];
81 [$
(:$nodes
,)* :text(stringify
!($word
).to_string())];
86 ( []; [:$e
:expr
]; ) => ( $e
);
92 <head
><title
>This is the title
.</title
></head
>
94 <p
>This is some text
</p
>
101 tag(String
, Vec
<HTMLFragment
> ),