// Copyright 2017-2018 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate 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.
// Substrate 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 Substrate. If not, see .
// tag::description[]
//! `decl_storage` macro
// end::description[]
use srml_support_procedural_tools::syn_ext as ext;
use syn::Ident;
use syn::token::CustomKeyword;
pub mod transformation;
/// Parsing usage only
#[derive(Parse, ToTokens, Debug)]
struct StorageDefinition {
pub hidden_crate: Option,
pub visibility: syn::Visibility,
pub trait_token: Token![trait],
pub ident: Ident,
pub for_token: Token![for],
pub module_ident: Ident,
pub mod_lt_token: Token![<],
pub mod_param: syn::GenericParam,
pub mod_gt_token: Token![>],
pub as_token: Token![as],
pub crate_ident: Ident,
pub content: ext::Braces>,
pub extra_genesis: Option,
}
#[derive(Parse, ToTokens, Debug)]
struct SpecificHiddenCrate {
pub keyword: ext::CustomToken,
pub ident: ext::Parens,
}
#[derive(Parse, ToTokens, Debug)]
struct AddExtraGenesis {
pub extragenesis_keyword: ext::CustomToken,
pub content: ext::Braces,
}
#[derive(Parse, ToTokens, Debug)]
struct AddExtraGenesisContent {
pub lines: ext::Punctuated,
}
#[derive(Parse, ToTokens, Debug)]
enum AddExtraGenesisLineEnum {
AddExtraGenesisLine(AddExtraGenesisLine),
AddExtraGenesisBuild(DeclStorageBuild),
}
#[derive(Parse, ToTokens, Debug)]
struct AddExtraGenesisLine {
pub attrs: ext::OuterAttributes,
pub config_keyword: ext::CustomToken,
pub extra_field: ext::Parens,
pub coldot_token: Token![:],
pub extra_type: syn::Type,
// FIXME #1570: use a custom ext::Option instead (syn option on '=' fails)
pub default_value: ext::Seq,
}
#[derive(Parse, ToTokens, Debug)]
struct DeclStorageLine {
// attrs (main use case is doc)
pub attrs: ext::OuterAttributes,
// visibility (no need to make optional
pub visibility: syn::Visibility,
// name
pub name: Ident,
pub getter: Option,
pub config: Option,
pub build: Option,
pub coldot_token: Token![:],
pub storage_type: DeclStorageType,
// FIXME #1570: use a custom ext::Option instead (syn option on '=' fails)
pub default_value: ext::Seq,
}
#[derive(Parse, ToTokens, Debug)]
struct DeclStorageGetter {
pub getter_keyword: ext::CustomToken,
pub getfn: ext::Parens,
}
#[derive(Parse, ToTokens, Debug)]
struct DeclStorageConfig {
pub config_keyword: ext::CustomToken,
pub expr: ext::Parens