/// The definition of a standard directive. /// /// Note that this type is an input to the parser, not an output. pub struct Directive { /// The provider's name for the directive. name: String, /// Description of the directive. doc: String, /// Fixed prefix term. prefix: String, /// The type of the prefix parameter, if there is one. prefix_param: Option, /// Fixed infix term. /// Can only be present if the prefix parameter exists. infix: Option, /// The type of the infix parameter. /// Can only be present if the infix term exists. infix_param: Option, /// Fixed suffix term. suffix: Option, /// The type of the suffix parameter. /// Can only be present if the suffix exists. suffix_param: Option, /// The type of the elements of the list parameter, if supported. list_param: Option, // TODO(zeph): macro expansion? } /// Directive parameter. pub struct Param { /// Name to which the compiler maps the argument. name: String, /// Description of the parameter's meaning in the context of the directive. doc: Option, /// Type required for the argument. typ: Type, /// Nuance parameter for list parameters. nuance: Option>, } /// Types expected by directive arguments. pub enum Type { /// Arbitrary text. Text, /// Speech text, possibly containing emphasis, shout, or whisper markers. Speech, /// Character in the current scene. Character, /// Duration. Duration, /// Asset requiring particular tags. Asset { tags: Vec }, /// Enumeration of literal options. Enum(Vec), } // Serialized representation of directives. mod serial { use serde::Deserialize; #[derive(Deserialize)] #[serde(rename_all = "snake_case", deny_unknown_fields)] struct Document { types: Vec, directives: Vec, } #[derive(Deserialize)] #[serde(rename_all = "snake_case", deny_unknown_fields, tag = "kind")] enum TypeKind { Text, Speech, Character, Duration, Asset { tags: Vec, }, Enum { #[serde(rename = "enum")] enm: Vec, }, } #[derive(Deserialize)] #[serde(rename_all = "snake_case", deny_unknown_fields)] struct Type { name: String, doc: String, kind: TypeKind, } #[derive(Deserialize)] #[serde(rename_all = "snake_case", deny_unknown_fields)] struct Param { name: String, doc: Option, #[serde(rename = "type")] typ: String, nuance: Option>, } #[derive(Deserialize)] #[serde(rename_all = "snake_case", deny_unknown_fields)] struct Directive { name: String, doc: String, prefix: String, prefix_param: Option, infix: Option, infix_param: Option, suffix: Option, suffix_param: Option, list_param: Option, } } static DIRECTIVE_PREDECLARED: &str = include_str!("directive-predeclared.json"); #[cfg(test)] mod tests { use super::*; use rstest::rstest; }