Skip to main content

MultilinearParser

Struct MultilinearParser 

Source
pub struct MultilinearParser(/* private fields */);
Expand description

A parser for multilinear system definitions, supporting incremental parsing across multiple files or input streams.

Implementations§

Source§

impl MultilinearParser

Source

pub fn parse_aspect_defaults(&mut self, path: &Path) -> Result<(), AspectError>

Parses aspect defaults from a file without parsing story content.

The format for each line is aspect_name: default_value. Empty lines are ignored.

§Arguments
  • path - Path to the aspects file (typically with .mla extension)
§Errors

Returns AspectError if the file cannot be opened, read, or contains invalid data.

Source

pub fn parse_directory_or_file( &mut self, path: &Path, namespace: &mut Vec<Box<str>>, ) -> Result<(), DirectoryOrFileError>

Recursively parses multilinear definitions from a file or directory tree.

If path is a file, it will be parsed directly (if it has the .mld extension). If path is a directory, all .mld files and subdirectories will be processed recursively.

§Namespace Building

When traversing directories, the directory names are appended to the namespace, creating a hierarchical structure. For example, a file at chapters/intro/scene.mld will receive the namespace ["chapters", "intro"] in addition to any existing namespace.

§Arguments
  • path - Path to a .mld file or directory containing .mld files
  • namespace - The current namespace stack (directory names are appended during traversal)
§Errors

Returns DirectoryOrFileError of this kind:

  • PathNotFound if the path doesn’t exist
  • OpeningFile if a file cannot be opened
  • Parsing if a file contains invalid data
  • ReadingDirectory if a directory cannot be read
§Example
use std::path::Path;
use multilinear_parser::MultilinearParser;

let mut parser = MultilinearParser::default();
let mut namespace = Vec::new();
parser.parse_directory_or_file(Path::new("story/"), &mut namespace).unwrap();
Source§

impl MultilinearParser

Source

pub fn add_new_aspect( &mut self, aspect_name: &str, default_name: &str, ) -> Result<Aspect, AspectAddingError>

Adds a new aspect and sets a default value.

Fails if aspect already exists or if the names aren’t valid.

Source

pub fn parse<R: Read>( &mut self, reader: R, parent_namespace: &[Box<str>], ) -> Result<(), Error>

Parses additional multilinear data from the given reader.

§Arguments
  • reader - The input source to parse from
  • namespace - Initial header context/path for events (e.g., vec!["Main Story".into()])
§Example
use std::fs::File;
use multilinear_parser::MultilinearParser;

let mut parser = MultilinearParser::default();
parser.parse(File::open("chapter1.mld").unwrap(), &[]).unwrap();
parser.parse(File::open("chapter2.mld").unwrap(), &[]).unwrap();
Source

pub fn into_info(self) -> NamedMultilinearInfo

Consumes the parser and returns the fully parsed data.

After calling this, the parser can no longer be used.

Trait Implementations§

Source§

impl Default for MultilinearParser

Source§

fn default() -> MultilinearParser

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.