[go: up one dir, main page]

duplicate 2.0.1

Provides macros for duplication of code with variable substitution.
Documentation
#![cfg_attr(not(feature = "pretty_errors"), allow(dead_code))]

/// For when substitution parameters aren't enclosed in brackets
pub(crate) const BRACKET_SUB_PARAM: &'static str = r#"Substitution parameters should be enclosed in '[]' each.
Example:
    sub_ident( [ parameter1 ] , [ paramter2 ] )
              ^^^          ^^^ ^^^         ^^^
"#;

/// For when neither syntaxes get any invocation input
pub(crate) const NO_INVOCATION: &'static str =
	"substitution_identifier (short syntax) or substitution group (verbose syntax)";

/// Basic message for when no substitution group is given, but at least one must
/// be given
pub(crate) const NO_GROUPS: &'static str = r#"Expected substitution group."#;

/// Hint for when no substitution group is given, but at least one must be given
pub(crate) const NO_GROUPS_HINT: &'static str = "Must specify at least one substitution group, \
                                                 otherwise use 'substitute!' or 'substitute_item'";

/// For when short syntax has declared substitution identifiers but no
/// substitution groups.
pub(crate) const SHORT_SYNTAX_NO_GROUPS: &'static str = r#"Add a substitution group after the substitution identifiers.
Example:
	name;
	[SomeSubstitution];
	^^^^^^^^^^^^^^^^^^^
"#;

/// For when short syntax substitutions aren't enclosed in brackets
pub(crate) const SHORT_SYNTAX_MISSING_SUB_BRACKET: &'static str = r#"Each substitution should be enclosed in '[]'.
Example:
    ident1 ident2;
    [ sub1 ] [ sub2 ] ;
   ^^^    ^^^^^    ^^^
"#;

/// For when short syntax substitution group has too few or too many
/// substitutions
pub(crate) const SHORT_SYNTAX_SUBSTITUTION_COUNT: &'static str = r#"Number of substitutions must match the number of substitutions identifiers.
Example:
    ident1 ident2;
   1^^^^^^ ^^^^^^2
    [sub1] [sub2];
   1^^^^^^ ^^^^^^2
"#;

/// For when verbose syntax substitution group has too few or too many
/// substitutions
pub(crate) const VERBOSE_SYNTAX_SUBSTITUTION_IDENTIFIERS: &'static str = r#"All substitution groups must define the same substitution identifiers.
Example:
    [
        ident1  [sub1]
        ident2  [sub2]
    ]
    [
        ident1  [sub3]
        ident2  [sub4]
    ]
"#;

/// For when verbose syntax substitution identifier has too few or too many
/// arguments
pub(crate) const VERBOSE_SYNTAX_SUBSTITUTION_IDENTIFIERS_ARGS: &'static str = r#"The same substitution identifier must take the same number of argument across all substitution groups.
Example:
[
        ident1(arg1, arg2)  [sub1 arg1 arg2]
               ^^^^^^^^^^
    ]
    [
        ident1(arg1, arg2)  [arg1 arg2 sub2]
               ^^^^^^^^^^
    ]
"#;

/// For when verbose syntax substitution pair is followed by a semicolon
pub(crate) const VERBOSE_SEMICOLON: &'static str = r#"Verbose syntax does not accept semicolons between substitutions.
Example:
    [
        name    [sub1] // No semicolon
        ty      [u32] // No semicolon
    ]
"#;

/// For when global substitutions aren't followed by ';'
pub(crate) const GLOBAL_SUB_SEMICOLON: &'static str = r#"Each global substitution should end with ';'
Example:
    name   [sub1];
    typ    [sub2];
"#;

/// For when module disambiguation cannot find a substitution identifier to use
/// for disambiguation
#[cfg_attr(not(feature = "module_disambiguation"), allow(dead_code))]
pub(crate) const MOD_DISAMB_NO_UNIQUE_SUB: &'static str = r#"There must be a substitution identifier that is substituted by a single and unique identifier for each duplicate.
Example:
    invalid               valid;
    [i32]                 [som_ident];
    [Some<Complex<Type>>] [som_other_ident];
"#;