tag

Macro tag 

Source
macro_rules! tag {
    (<>) => { ... };
    (<>|$($tail:tt)*) => { ... };
    (</>) => { ... };
    (</>|$($tail:tt)*) => { ... };
    (<$tag:tt>) => { ... };
    (<$tag:tt>|$($tail:tt)*) => { ... };
    (</$tag:tt>) => { ... };
    (</$tag:tt>|$($tail:tt)*) => { ... };
}
Expand description

Helper macro that generates a pattern representing a Tag to make matching on Tags less verbose.

This macro accepts 4 forms:

  • tag!(<div>) where div can be any valid tag name. This matches a start tag where the tag name is “div”. If the tag name contains characters other than [a-zA-Z0-9_] then it should be quoted a <"div">.
  • tag!(</div>) where div can be any valid tag name. This matches a end tag where the tag name is “div”. If the tag name contains characters other than [a-zA-Z0-9_] then it should be quoted a </"div">.
  • tag!(<>). This matches any start tag (regardless of tag name).
  • tag!(</>). This matches any end tag (regardless of tag name).

Additionally any of the above can be freely combined with | to create an “or” match pattern. For example tag!(<head> | </>) will match a “head” start tag or any end tag.