data-encoding-macro-internal-0.1.7/Cargo.toml.orig010064000017500001750000000010361345743445500202470ustar0000000000000000[package] name = "data-encoding-macro-internal" version = "0.1.7" authors = ["Julien Cretin "] license = "MIT" edition = "2018" description = "Internal library for data-encoding-macro" readme = "README.md" repository = "https://github.com/ia0/data-encoding" include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"] [lib] proc-macro = true [features] stable = ["proc-macro-hack"] [dependencies] data-encoding = { version = "2.1", path = "../.." } proc-macro-hack = { version = "0.5", optional = true } syn = "0.15" data-encoding-macro-internal-0.1.7/Cargo.toml0000644000000020640000000000000145060ustar00# 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 believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "data-encoding-macro-internal" version = "0.1.7" authors = ["Julien Cretin "] include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"] description = "Internal library for data-encoding-macro" readme = "README.md" license = "MIT" repository = "https://github.com/ia0/data-encoding" [lib] proc-macro = true [dependencies.data-encoding] version = "2.1" [dependencies.proc-macro-hack] version = "0.5" optional = true [dependencies.syn] version = "0.15" [features] stable = ["proc-macro-hack"] data-encoding-macro-internal-0.1.7/Cargo.toml.orig0000644000000020650000000000000154460ustar00# 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 believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "data-encoding-macro-internal" version = "0.1.7" authors = ["Julien Cretin "] include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"] description = "Internal library for data-encoding-macro" readme = "README.md" license = "MIT" repository = "https://github.com/ia0/data-encoding" [lib] proc-macro = true [dependencies.data-encoding] version = "2.1" [dependencies.proc-macro-hack] version = "0.5" optional = true [dependencies.syn] version = "0.15" [features] stable = ["proc-macro-hack"] data-encoding-macro-internal-0.1.7/LICENSE010064000017500001750000000021341341316441000163440ustar0000000000000000The MIT License (MIT) Copyright (c) 2015-2017 Julien Cretin Copyright (c) 2017 Google Inc. 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. data-encoding-macro-internal-0.1.7/README.md010064000017500001750000000003621341316441000166170ustar0000000000000000Do **not** use this library. Use [data-encoding-macro] instead. This library is for internal use by data-encoding-macro because procedural macros require a separate crate. [data-encoding-macro]: https://crates.io/crates/data-encoding-macro data-encoding-macro-internal-0.1.7/src/lib.rs010064000017500001750000000142401345743440400172560ustar0000000000000000//! Internal library for data-encoding-macro //! //! Do **not** use this library. Use [data-encoding-macro] instead. //! //! This library is for internal use by data-encoding-macro because procedural //! macros require a separate crate. //! //! [data-encoding-macro]: https://crates.io/crates/data-encoding-macro #![warn(unused_results)] extern crate proc_macro; #[cfg(feature = "stable")] extern crate proc_macro_hack; extern crate syn; extern crate data_encoding; use proc_macro::token_stream::IntoIter; use proc_macro::{TokenStream, TokenTree}; #[cfg(feature = "stable")] use proc_macro_hack::proc_macro_hack; use std::collections::HashMap; use data_encoding::{BitOrder, Encoding, Specification, Translate, Wrap}; fn parse_op(tokens: &mut IntoIter, op: char, key: &str) { match tokens.next() { Some(TokenTree::Punct(ref x)) if x.as_char() == op => (), _ => panic!("expected {:?} after {}", op, key), } } fn parse_map(mut tokens: IntoIter) -> HashMap { let mut map = HashMap::new(); while let Some(key) = tokens.next() { let key = match key { TokenTree::Ident(ident) => format!("{}", ident), _ => panic!("expected key got {}", key), }; parse_op(&mut tokens, ':', &key); let value = match tokens.next() { None => panic!("expected value for {}", key), Some(value) => value, }; parse_op(&mut tokens, ',', &key); let _ = map.insert(key, value); } map } fn get_string(map: &mut HashMap, key: &str) -> String { let node = match map.remove(key) { None => return String::new(), Some(node) => node, }; match syn::parse::(node.into()) { Ok(result) => result.value(), _ => panic!("expected string for {}", key), } } fn get_usize(map: &mut HashMap, key: &str) -> usize { let node = match map.remove(key) { None => return 0, Some(node) => node, }; let literal = match node { TokenTree::Literal(literal) => literal, _ => panic!("expected literal for {}", key), }; match literal.to_string().parse() { Ok(result) => result, Err(error) => panic!("expected usize for {}: {}", key, error), } } fn get_padding(map: &mut HashMap) -> Option { let node = match map.remove("padding") { None => return None, Some(node) => node, }; if let Ok(result) = syn::parse::(node.clone().into()) { return Some(result.value()); } match syn::parse::(node.into()) { Ok(ref result) if result.to_string() == "None" => None, _ => panic!("expected None or char for padding"), } } fn get_bool(map: &mut HashMap, key: &str) -> Option { let node = match map.remove(key) { None => return None, Some(node) => node, }; match syn::parse::(node.into()) { Ok(result) => Some(result.value), _ => panic!("expected bool for padding"), } } fn get_bit_order(map: &mut HashMap) -> BitOrder { let node = match map.remove("bit_order") { None => return BitOrder::MostSignificantFirst, Some(node) => node, }; let msb = "MostSignificantFirst"; let lsb = "LeastSignificantFirst"; match node { TokenTree::Ident(ref ident) if format!("{}", ident) == msb => { BitOrder::MostSignificantFirst } TokenTree::Ident(ref ident) if format!("{}", ident) == lsb => { BitOrder::LeastSignificantFirst } _ => panic!("expected {} or {} for bit_order", msb, lsb), } } fn check_present(hash_map: &HashMap, key: &str) { if !hash_map.contains_key(key) { panic!("{} is required", key); } } fn get_encoding(mut hash_map: &mut HashMap) -> Encoding { check_present(&hash_map, "symbols"); let spec = Specification { symbols: get_string(&mut hash_map, "symbols"), bit_order: get_bit_order(&mut hash_map), check_trailing_bits: get_bool(&mut hash_map, "check_trailing_bits").unwrap_or(true), padding: get_padding(&mut hash_map), ignore: get_string(&mut hash_map, "ignore"), wrap: Wrap { width: get_usize(&mut hash_map, "wrap_width"), separator: get_string(&mut hash_map, "wrap_separator"), }, translate: Translate { from: get_string(&mut hash_map, "translate_from"), to: get_string(&mut hash_map, "translate_to"), }, }; spec.encoding().unwrap() } fn check_empty(hash_map: HashMap) { if !hash_map.is_empty() { panic!("Unexpected keys {:?}", hash_map.keys()); } } #[cfg_attr(feature = "stable", proc_macro_hack)] #[cfg_attr(not(feature = "stable"), proc_macro)] #[doc(hidden)] pub fn internal_new_encoding(input: TokenStream) -> TokenStream { let mut hash_map = parse_map(input.into_iter()); let encoding = get_encoding(&mut hash_map); check_empty(hash_map); format!("{:?}", encoding.internal_implementation()).parse().unwrap() } #[cfg(not(feature = "stable"))] #[proc_macro] #[doc(hidden)] pub fn internal_decode_array(input: TokenStream) -> TokenStream { let mut hash_map = parse_map(input.into_iter()); let encoding = get_encoding(&mut hash_map); check_present(&hash_map, "name"); let name = get_string(&mut hash_map, "name"); check_present(&hash_map, "input"); let input = get_string(&mut hash_map, "input"); check_empty(hash_map); let output = encoding.decode(input.as_bytes()).unwrap(); format!("{}: [u8; {}] = {:?};", name, output.len(), output).parse().unwrap() } #[cfg_attr(feature = "stable", proc_macro_hack)] #[cfg_attr(not(feature = "stable"), proc_macro)] #[doc(hidden)] pub fn internal_decode_slice(input: TokenStream) -> TokenStream { let mut hash_map = parse_map(input.into_iter()); let encoding = get_encoding(&mut hash_map); check_present(&hash_map, "input"); let input = get_string(&mut hash_map, "input"); check_empty(hash_map); format!("{:?}", encoding.decode(input.as_bytes()).unwrap()).parse().unwrap() } data-encoding-macro-internal-0.1.7/.cargo_vcs_info.json0000644000000001120000000000000165000ustar00{ "git": { "sha1": "cda5148da701c837b7bdc0aa9b5096823de2f3ac" } }