directive: simplify parameter representation

This commit is contained in:
Branden J Brown 2024-10-12 08:08:32 -04:00
parent 8c737b8c0d
commit e72763c418
1 changed files with 10 additions and 32 deletions

View File

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