rxml_proc-0.12.1/.cargo_vcs_info.json0000644000000001470000000000100131240ustar { "git": { "sha1": "1b760bb07a385b3cb4a88eddc782204670a5d820" }, "path_in_vcs": "rxml_proc" }rxml_proc-0.12.1/.gitignore000064400000000000000000000000231046102023000136750ustar 00000000000000/target Cargo.lock rxml_proc-0.12.1/COPYING000064400000000000000000000020431046102023000127440ustar 00000000000000Copyright (c) 2021 Jonas Schäfer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rxml_proc-0.12.1/Cargo.lock0000644000000024500000000000100110760ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 [[package]] name = "proc-macro2" version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] name = "rxml_proc" version = "0.12.1" dependencies = [ "quote", "rxml_validation", "syn", ] [[package]] name = "rxml_validation" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "826e80413b9a35e9d33217b3dcac04cf95f6559d15944b93887a08be5496c4a4" [[package]] name = "syn" version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" rxml_proc-0.12.1/Cargo.toml0000644000000022140000000000100111170ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "rxml_proc" version = "0.12.1" authors = ["Jonas Schäfer "] build = false autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Macros to, at compile time, validate strings against the CData, Name and NCName productions from the XML 1.0 grammar." readme = "README.md" keywords = ["xml"] categories = ["parsing"] license = "MIT" repository = "https://codeberg.org/jssfr/rxml" [lib] name = "rxml_proc" path = "src/lib.rs" proc-macro = true [dependencies.quote] version = "^1" [dependencies.rxml_validation] version = "^0.11.0" default-features = false [dependencies.syn] version = "^2" rxml_proc-0.12.1/Cargo.toml.orig000064400000000000000000000010251046102023000145770ustar 00000000000000[package] name = "rxml_proc" version = "0.12.1" authors = ["Jonas Schäfer "] license = "MIT" edition = "2021" description = "Macros to, at compile time, validate strings against the CData, Name and NCName productions from the XML 1.0 grammar." repository = "https://codeberg.org/jssfr/rxml" keywords = ["xml"] categories = ["parsing"] readme = true [dependencies] syn = { version = "^2" } rxml_validation = { version = "^0.11.0", default-features = false } quote = { version = "^1" } [lib] proc-macro = true rxml_proc-0.12.1/README.md000064400000000000000000000013031046102023000131660ustar 00000000000000# `rxml_proc` — Compile-time validation of CData, Name and NCName strings This crate is supplementary to the `rxml` crate. It provides three macros (`xml_cdata!`, `xml_name!` and `xml_ncname!`) which convert a normal `&str` into the corresponding `rxml` string type for strong typing of XML string flavors. [![crate badge](https://img.shields.io/crates/v/rxml_proc.svg)](https://crates.io/crates/rxml_proc) [![docs badge](https://docs.rs/rxml_proc/badge.svg)](https://docs.rs/rxml_proc/) Please see the [rxml](https://crates.io/crates/rxml) crate for more information. ## Example ```rust use rxml::NCNameStr; use rxml_proc::xml_ncname; const XML_PREFIX: &'static NCNameStr = xml_ncname!("xml"); ``` rxml_proc-0.12.1/src/lib.rs000064400000000000000000000053201046102023000136150ustar 00000000000000/*! # Macros for XML strings This crate provides macros to check XML string syntax at compile time. ## Example ```rust,ignore use rxml::{NcNameStr, xml_cdata, xml_ncname}; const XML_PREFIX: &'static NcNameStr = xml_ncname!("xml"); const XML_QNAME: &'static NameStr = xml_name!("xml:lang"); ``` ## See also This crate bases on the [`rxml_validation`] crate and it primarily intended for use with the [`rxml`](https://docs.rs/rxml) crate. */ use proc_macro::TokenStream; use quote::quote; use rxml_validation::{validate_name, validate_ncname}; use syn::{ parse::{Parse, ParseStream}, *, }; struct Input { data: LitStr, ty_mod: Path, } impl Parse for Input { fn parse(input: ParseStream) -> Result { let data = input.parse()?; input.parse::()?; let ty_mod = input.parse()?; if input.peek(Token![,]) { // consume a trailing comma input.parse::()?; } Ok(Self { data, ty_mod }) } } /** XML 1.0 Name compliant string # Example ```rust,ignore use rxml::{NameStr, xml_name}; const FORBIDDEN: &'static NameStr = xml_name!("xmlns:xml"); ``` # Safety The raw version of this macro, as exported by the `rxml_proc` crate (*not* by the `rxml` crate!), expects a second argument which must be a path pointing at the `rxml` crate. If another path is passed, the behaviour of the generated is literally undefined, as the generated code then contains a transmute with the wrong type argument. */ #[proc_macro] pub fn xml_name(input: TokenStream) -> TokenStream { let Input { data, ty_mod } = parse_macro_input!(input); let s = data.value(); let tokens = match validate_name(&s) { Ok(()) => quote! { core::mem::transmute::<_, &#ty_mod::NameStr>(#s) }, Err(e) => { let err = format!("invalid Name string {:?}: {}", s, e); quote! { compile_error!(#err) } } }; tokens.into() } /** Namespaces for XML 1.0 NCName compliant string # Example ```rust,ignore use rxml::{NcNameStr, xml_ncname}; const XML_PREFIX: &'static NCNameStr = xml_ncname!("xml"); ``` # Safety The raw version of this macro, as exported by the `rxml_proc` crate (*not* by the `rxml` crate!), expects a second argument which must be a path pointing at the `rxml` crate. If another path is passed, the behaviour of the generated is literally undefined, as the generated code then contains a transmute with the wrong type argument. */ #[proc_macro] pub fn xml_ncname(input: TokenStream) -> TokenStream { let Input { data, ty_mod } = parse_macro_input!(input); let s = data.value(); let tokens = match validate_ncname(&s) { Ok(()) => quote! { core::mem::transmute::<_, &#ty_mod::NcNameStr>(#s) }, Err(e) => { let err = format!("invalid NCName string {:?}: {}", s, e); quote! { compile_error!(#err) } } }; tokens.into() }