3 #![allow(non_camel_case_types)]
4 // A test of the macro system. Can we do HTML literals?
8 This is an HTML parser written as a macro. It's all CPS, and we have
9 to carry around a bunch of state. The arguments to macros all look like this:
11 { tag_stack* # expr* # tokens }
13 The stack keeps track of where we are in the tree. The expr is a list
14 of children of the current node. The tokens are everything that's
18 use HTMLFragment::{tag, text};
22 parse_node!( []; []; $($body)* )
26 macro_rules! parse_node {
28 [:$head:ident ($(:$head_nodes:expr),*)
29 $(:$tags:ident ($(:$tag_nodes:expr),*))*];
31 </$tag:ident> $($rest:tt)*
34 [$(: $tags ($(:$tag_nodes),*))*];
35 [$(:$head_nodes,)* :tag(stringify!($head).to_string(),
42 [$(:$tags:ident ($(:$tag_nodes:expr),*) )*];
44 <$tag:ident> $($rest:tt)*
47 [:$tag ($(:$nodes)*) $(: $tags ($(:$tag_nodes),*) )*];
54 [$(:$tags:ident ($(:$tag_nodes:expr),*) )*];
59 [$(: $tags ($(:$tag_nodes),*))*];
60 [$(:$nodes,)* :text(".".to_string())];
66 [$(:$tags:ident ($(:$tag_nodes:expr),*) )*];
68 $word:ident $($rest:tt)*
71 [$(: $tags ($(:$tag_nodes),*))*];
72 [$(:$nodes,)* :text(stringify!($word).to_string())];
77 ( []; [:$e:expr]; ) => ( $e );
83 <head><title>This is the title.</title></head>
85 <p>This is some text</p>
92 tag(String, Vec<HTMLFragment> ),