/// Parse the attributes starting from something like:
///     id="app" class=*CSS>
///
/// As soon as we see
///     >
/// We know that the element has no more attributes and our loop will end
Parse the attributes starting from something like:
id="app" class=*CSS>

As soon as we see
>
We know that the element has no more attributes and our loop will end
Parse the attributes starting from something like : id = " app " class = * CSS > As soon as we see > We know that the element has no more attributes and our loop will end
fn parse_attributes(input: &mut ParseStream) -> Result<Vec<Attr>> {
    let mut attrs = Vec::new();
    // Do we see an identifier such as `id`? If so proceed
    while input.peek(Ident) || input.peek(Token![type]) {
        // <link rel="stylesheet" type="text/css"
        //   .. type needs to be handled specially since it's a keyword
        let maybe_type_key: Option<Token![type]> = input.parse()?;
        let key = if maybe_type_key.is_some() {
            Ident::new("type", maybe_type_key.unwrap().span())
        } else {
            input.parse()?
        };
        // =
        input.parse::<Token![=]>()?;
        // Continue parsing tokens until we see the next attribute or a closing > tag
        let mut value_tokens = TokenStream::new();
        loop {
            let tt: TokenTree = input.parse()?;
            value_tokens.extend(Some(tt));
            let has_attrib_key = input.peek(Ident) || input.peek(Token![type]);
            let peek_start_of_next_attr = has_attrib_key && input.peek2(Token![=]);
            let peek_end_of_tag = input.peek(Token![>]);
            let peek_self_closing = input.peek(Token![/]);
            if peek_end_of_tag || peek_start_of_next_attr || peek_self_closing {
                break;
            }
        }
        let value: Expr = syn::parse2(value_tokens)?;
        attrs.push(Attr { key, value });
    }
    Ok(attrs)
}
fn parse_attributes ( input : & mut ParseStream ) -> Result < Vec < Attr > > { let mut attrs = Vec :: new ( ) ; // Do we see an identifier such as `id`? If so proceed while input . peek ( Ident ) || input . peek ( Token ! [ type ] ) { // <link rel="stylesheet" type="text/css" //   .. type needs to be handled specially since it's a keyword let maybe_type_key : Option < Token ! [ type ] > = input . parse ( ) ? ; let key = if maybe_type_key . is_some ( ) { Ident :: new ( " " , maybe_type_key . unwrap ( ) . span ( ) ) } else { input . parse ( ) ? } ; // = input . parse :: < Token ! [ ] > ( ) ? ; // Continue parsing tokens until we see the next attribute or a closing > tag let mut value_tokens = TokenStream :: new ( ) ; loop { let tt : TokenTree = input . parse ( ) ? ; value_tokens . extend ( Some ( tt ) ) ; let has_attrib_key = input . peek ( Ident ) || input . peek ( Token ! [ type ] ) ; let peek_start_of_next_attr = has_attrib_key && input . peek2 ( Token ! [ ] ) ; let peek_end_of_tag = input . peek ( Token ! [ ] ) ; let peek_self_closing = input . peek ( Token ! [ ] ) ; if peek_end_of_tag || peek_start_of_next_attr || peek_self_closing { break ; } } let value : Expr = syn :: parse2 ( value_tokens ) ? ; attrs . push ( Attr { key , value } ) ; } Ok ( attrs ) }
Parse the attributes starting from something like:
id="app" class=*CSS>
Parse the attributes starting from something like : id = " app " class = * CSS >
input
&mut ParseStream