directive: simplify parameter representation
This commit is contained in:
parent
8c737b8c0d
commit
e72763c418
@ -9,13 +9,13 @@ pub struct Directive {
|
||||
/// Fixed prefix term.
|
||||
prefix: String,
|
||||
/// The type of the prefix argument, if there is one.
|
||||
prefix_arg: Option<Type>,
|
||||
prefix_arg: Option<Param>,
|
||||
/// Fixed infix term.
|
||||
/// Can only be present if the prefix argument exists.
|
||||
infix: Option<String>,
|
||||
/// The type of the infix argument.
|
||||
/// Can only be present if the infix term exists.
|
||||
infix_arg: Option<Type>,
|
||||
infix_arg: Option<Param>,
|
||||
/// Fixed suffix term.
|
||||
/// Can only be present if the infix argument exists.
|
||||
/// Note that this implies directives which have two terms have a prefix
|
||||
@ -23,37 +23,21 @@ pub struct Directive {
|
||||
suffix: Option<String>,
|
||||
/// The type of the suffix argument.
|
||||
/// Can only be present if the suffix exists.
|
||||
suffix_arg: Option<Type>,
|
||||
suffix_arg: Option<Param>,
|
||||
/// The type of the elements of the list argument, if supported.
|
||||
list_arg: Option<Type>,
|
||||
list_arg: Option<Param>,
|
||||
// TODO(zeph): macro expansion?
|
||||
}
|
||||
|
||||
/// Directive parameter type.
|
||||
pub enum Type {
|
||||
Named {
|
||||
name: String,
|
||||
doc: String,
|
||||
underlying: Param,
|
||||
},
|
||||
Literal(Param),
|
||||
}
|
||||
|
||||
impl Type {
|
||||
pub fn underlying(&self) -> &Param {
|
||||
match self {
|
||||
Self::Named {
|
||||
underlying,
|
||||
name: _,
|
||||
doc: _,
|
||||
} => underlying,
|
||||
Self::Literal(underlying) => underlying,
|
||||
}
|
||||
}
|
||||
/// Directive parameter.
|
||||
pub struct Param {
|
||||
name: String,
|
||||
doc: String,
|
||||
typ: Type,
|
||||
}
|
||||
|
||||
/// Types expected by directive arguments.
|
||||
pub enum Param {
|
||||
pub enum Type {
|
||||
/// Arbitrary text.
|
||||
Text,
|
||||
/// Speech text, possibly containing emphasis, shout, or whisper markers.
|
||||
@ -72,10 +56,4 @@ pub enum Param {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rstest::rstest;
|
||||
|
||||
const DIRECTIVE_JSON: &str = r#"{
|
||||
"name": "kessoku",
|
||||
"prefix": "bocchi",
|
||||
"prefix_arg":
|
||||
}"#;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user