124 lines
3.2 KiB
Rust
124 lines
3.2 KiB
Rust
/// 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<Param>,
|
|
/// Fixed infix term.
|
|
/// Can only be present if the prefix parameter exists.
|
|
infix: Option<String>,
|
|
/// The type of the infix parameter.
|
|
/// Can only be present if the infix term exists.
|
|
infix_param: Option<Param>,
|
|
/// Fixed suffix term.
|
|
suffix: Option<String>,
|
|
/// The type of the suffix parameter.
|
|
/// Can only be present if the suffix exists.
|
|
suffix_param: Option<Param>,
|
|
/// The type of the elements of the list parameter, if supported.
|
|
list_param: Option<Param>,
|
|
// 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<String>,
|
|
/// Type required for the argument.
|
|
typ: Type,
|
|
/// Nuance parameter for list parameters.
|
|
nuance: Option<Box<Param>>,
|
|
}
|
|
|
|
/// 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<String> },
|
|
/// Enumeration of literal options.
|
|
Enum(Vec<String>),
|
|
}
|
|
|
|
// Serialized representation of directives.
|
|
mod serial {
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Deserialize)]
|
|
#[serde(rename_all = "snake_case", deny_unknown_fields)]
|
|
struct Document {
|
|
types: Vec<Type>,
|
|
directives: Vec<Directive>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
#[serde(rename_all = "snake_case", deny_unknown_fields, tag = "kind")]
|
|
enum TypeKind {
|
|
Text,
|
|
Speech,
|
|
Character,
|
|
Duration,
|
|
Asset {
|
|
tags: Vec<String>,
|
|
},
|
|
Enum {
|
|
#[serde(rename = "enum")]
|
|
enm: Vec<String>,
|
|
},
|
|
}
|
|
|
|
#[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<String>,
|
|
#[serde(rename = "type")]
|
|
typ: String,
|
|
nuance: Option<Box<Param>>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
#[serde(rename_all = "snake_case", deny_unknown_fields)]
|
|
struct Directive {
|
|
name: String,
|
|
doc: String,
|
|
prefix: String,
|
|
prefix_param: Option<Param>,
|
|
infix: Option<String>,
|
|
infix_param: Option<Param>,
|
|
suffix: Option<String>,
|
|
suffix_param: Option<Param>,
|
|
list_param: Option<Param>,
|
|
}
|
|
}
|
|
|
|
static DIRECTIVE_PREDECLARED: &str = include_str!("directive-predeclared.json");
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use rstest::rstest;
|
|
}
|