// Copyright 2017-2019 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 .
//! Parsing of decl_storage input.
use srml_support_procedural_tools::{ToTokens, Parse, syn_ext as ext};
use syn::{Ident, Token};
mod keyword {
syn::custom_keyword!(hiddencrate);
syn::custom_keyword!(add_extra_genesis);
syn::custom_keyword!(extra_genesis_skip_phantom_data_field);
syn::custom_keyword!(config);
syn::custom_keyword!(build);
syn::custom_keyword!(get);
syn::custom_keyword!(map);
syn::custom_keyword!(linked_map);
syn::custom_keyword!(double_map);
syn::custom_keyword!(blake2_256);
syn::custom_keyword!(blake2_128);
syn::custom_keyword!(twox_256);
syn::custom_keyword!(twox_128);
syn::custom_keyword!(twox_64_concat);
syn::custom_keyword!(hasher);
}
/// Parsing usage only
#[derive(Parse, ToTokens, Debug)]
struct StorageDefinition {
pub hidden_crate: ext::Opt,
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_generic: syn::Ident,
pub mod_param_bound_token: Option,
pub mod_param_bound: syn::Path,
pub mod_instance_param_token: Option,
pub mod_instance: Option,
pub mod_instantiable_token: Option,
pub mod_instantiable: Option,
pub mod_default_instance_token: Option,
pub mod_default_instance: Option,
pub mod_gt_token: Token![>],
pub as_token: Token![as],
pub crate_ident: Ident,
pub where_clause: Option,
pub content: ext::Braces>,
pub extra_genesis: ext::Opt,
}
#[derive(Parse, ToTokens, Debug)]
struct SpecificHiddenCrate {
pub keyword: keyword::hiddencrate,
pub ident: ext::Parens,
}
#[derive(Parse, ToTokens, Debug)]
struct AddExtraGenesis {
pub extragenesis_keyword: keyword::add_extra_genesis,
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: keyword::config,
pub extra_field: ext::Parens,
pub coldot_token: Token![:],
pub extra_type: syn::Type,
pub default_value: ext::Opt,
}
#[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: ext::Opt,
pub config: ext::Opt,
pub build: ext::Opt,
pub coldot_token: Token![:],
pub storage_type: DeclStorageType,
pub default_value: ext::Opt,
}
#[derive(Parse, ToTokens, Debug)]
struct DeclStorageGetterBody {
fn_keyword: Option,
ident: Ident,
}
#[derive(Parse, ToTokens, Debug)]
struct DeclStorageGetter {
pub getter_keyword: keyword::get,
pub getfn: ext::Parens,
}
#[derive(Parse, ToTokens, Debug)]
struct DeclStorageConfig {
pub config_keyword: keyword::config,
pub expr: ext::Parens