inline-xml-macros 0.2.0

Macros for the inline-xml crate
Documentation
// Copyright (C) 2023 Benjamin Stürz
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#![allow(dead_code)]
extern crate proc_macro;
use proc_macro::TokenStream;
use proc_macro2::{Ident, Punct, Span};
use quote::ToTokens;
use syn::{token::{Lt, Gt, Div, Eq, And, Semi, Pound, Colon, Sub}, LitStr, ExprBlock, LitInt, parse_macro_input, LitFloat};

mod parse;
mod gen;
mod impls;

struct Xml(Vec<Content>);

enum SimpleNameSeg {
    Ident(Ident),
    Minus(Sub),
}

#[derive(PartialEq)]
struct SimpleName(Vec<SimpleNameSeg>);

struct Name {
    namespace: Option<(SimpleName, Colon)>,
    name: SimpleName,
}

struct Tag {
    lt: Lt,
    name: Name,
    attrs: Vec<Attr>,
    tail: TagTail,
}

enum TagTail {
    Simple {
        slash: Div,
        gt: Gt,
    },
    Complex {
        gt: Gt,
        inner: Xml,
        lt: Lt,
        slash: Div,
        name2: Name,
        gt2: Gt,
    }
}

struct Attr {
    name: Name,
    eq: Eq,
    value: Value,
}

enum Value {
    Block(ExprBlock),
    Str(LitStr),
}

enum Content {
    Tag(Tag),
    Escape {
        amp: And,
        escape: Escape,
        semi: Semi,
    },
    Block(ExprBlock),
    Punct(Punct),
    Ident(Ident),
    Str(LitStr),
    Int(LitInt),
    Float(LitFloat),
}

enum Escape {
    Lt(Span),
    Gt(Span),
    Amp(Span),
    Apos(Span),
    Quot(Span),
    X {
        pound: Pound,
        x: Ident,
        value: u32
    },
    Int {
        pound: Pound,
        lit: LitInt,
    }
}


#[proc_macro]
pub fn xml(input: TokenStream) -> TokenStream {
    parse_macro_input!(input as Xml).into_token_stream().into()
}

#[proc_macro]
pub fn xml_tag(input: TokenStream) -> TokenStream {
    parse_macro_input!(input as Tag).into_token_stream().into()
}