script: syntax model

This commit is contained in:
Branden J Brown 2024-10-17 11:16:05 -04:00
parent ff5261ae60
commit 5e31eafdfb
3 changed files with 67 additions and 2 deletions

View File

@ -12,7 +12,7 @@ pub struct TypeSystem {
/// The definition of a standard directive.
///
/// Note that this type is an input to the parser, not an output.
#[derive(Debug, PartialEq, Eq, Default)]
#[derive(Debug, PartialEq, Eq, Default, Clone)]
pub struct Directive {
/// The provider's name for the directive.
name: String,
@ -39,7 +39,7 @@ pub struct Directive {
}
/// Directive parameter.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Param {
/// Name to which the compiler maps the argument.
name: String,

View File

@ -1,4 +1,5 @@
mod directive;
mod script;
fn main() {
println!("Hello, world!");

64
src/script.rs Normal file
View File

@ -0,0 +1,64 @@
use std::time;
use crate::directive;
/// A line of VijiN script.
pub enum Line {
Spoken {
speaker: Vec<TextFragment>,
directive: Option<Vec<Directive>>,
speech: Vec<SpeechFragment>,
},
Directive(Vec<Directive>),
Comment(String),
}
/// Call to a directive.
///
/// Each separate directive instance is a single call, even when using the
/// implicit prefix form. This allows the implicit prefix to still invoke a
/// different directive, e.g. `[Enter Bocchi, Ryo stage left.]`.
pub struct Directive {
target: directive::Directive,
prefix: Option<Arg>,
infix: Option<Arg>,
suffix: Option<Arg>,
list: Vec<ListArg>,
}
/// Single argument to a directive.
pub enum Arg {
Text(Vec<TextFragment>),
Speech(Vec<SpeechFragment>),
Character(String),
Duration(time::Duration),
Asset(String),
Enumerant(String),
}
/// List argument, possibly including nuance.
pub struct ListArg {
arg: Arg,
nuance: Option<Arg>,
}
/// Parsed fragment of text.
pub enum TextFragment {
/// Literal or quoted text.
/// May start and end with spaces.
Literal(String),
/// Reference to a variable of the given name.
/// Does not include the `{}` which marks it as a variable reference.
Variable(String),
}
/// Parsed fragment of speech text.
///
/// Fragments may start or end with spaces, but they do not include the syntax
/// used to delimit them.
pub enum SpeechFragment {
Plain(Vec<TextFragment>),
Emphasis(Vec<TextFragment>),
Yell(Vec<TextFragment>),
Whisper(Vec<TextFragment>),
}