]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/html-literals.rs
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?
15 This is an HTML parser written as a macro. It's all CPS, and we have
16 to carry around a bunch of state. The arguments to macros all look like this:
18 { tag_stack* # expr* # tokens }
20 The stack keeps track of where we are in the tree. The expr is a list
21 of children of the current node. The tokens are everything that's
25 use HTMLFragment
::{tag, text}
;
29 parse_node
!( []; []; $
($body
)* )
33 macro_rules
! parse_node
{
35 [:$head
:ident ($
(:$head_nodes
:expr
),*)
36 $
(:$tags
:ident ($
(:$tag_nodes
:expr
),*))*];
38 </$tag
:ident
> $
($rest
:tt
)*
41 [$
(: $
tags ($
(:$tag_nodes
),*))*];
42 [$
(:$head_nodes
,)* :tag(stringify
!($head
).to_string(),
49 [$
(:$tags
:ident ($
(:$tag_nodes
:expr
),*) )*];
51 <$tag
:ident
> $
($rest
:tt
)*
54 [:$
tag ($
(:$nodes
)*) $
(: $
tags ($
(:$tag_nodes
),*) )*];
61 [$
(:$tags
:ident ($
(:$tag_nodes
:expr
),*) )*];
66 [$
(: $
tags ($
(:$tag_nodes
),*))*];
67 [$
(:$nodes
,)* :text(".".to_string())];
73 [$
(:$tags
:ident ($
(:$tag_nodes
:expr
),*) )*];
75 $word
:ident $
($rest
:tt
)*
78 [$
(: $
tags ($
(:$tag_nodes
),*))*];
79 [$
(:$nodes
,)* :text(stringify
!($word
).to_string())];
84 ( []; [:$e
:expr
]; ) => ( $e
);
90 <head
><title
>This is the title
.</title
></head
>
92 <p
>This is some text
</p
>
99 tag(String
, Vec
<HTMLFragment
> ),