From 5e31eafdfb160813b566ed604cc169777d350b53 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Thu, 17 Oct 2024 11:16:05 -0400 Subject: [PATCH] script: syntax model --- src/directive.rs | 4 +-- src/main.rs | 1 + src/script.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/script.rs diff --git a/src/directive.rs b/src/directive.rs index 1097f20..99309c5 100644 --- a/src/directive.rs +++ b/src/directive.rs @@ -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, diff --git a/src/main.rs b/src/main.rs index 66c7228..196895c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ mod directive; +mod script; fn main() { println!("Hello, world!"); diff --git a/src/script.rs b/src/script.rs new file mode 100644 index 0000000..01022bd --- /dev/null +++ b/src/script.rs @@ -0,0 +1,64 @@ +use std::time; + +use crate::directive; + +/// A line of VijiN script. +pub enum Line { + Spoken { + speaker: Vec, + directive: Option>, + speech: Vec, + }, + Directive(Vec), + 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, + infix: Option, + suffix: Option, + list: Vec, +} + +/// Single argument to a directive. +pub enum Arg { + Text(Vec), + Speech(Vec), + Character(String), + Duration(time::Duration), + Asset(String), + Enumerant(String), +} + +/// List argument, possibly including nuance. +pub struct ListArg { + arg: Arg, + nuance: Option, +} + +/// 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), + Emphasis(Vec), + Yell(Vec), + Whisper(Vec), +}