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
impl MultilinearParser
Sourcepub fn parse_aspect_defaults(&mut self, path: &Path) -> Result<(), AspectError>
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.mlaextension)
§Errors
Returns AspectError if the file cannot be opened, read, or contains invalid data.
Sourcepub fn parse_directory_or_file(
&mut self,
path: &Path,
namespace: &mut Vec<Box<str>>,
) -> Result<(), DirectoryOrFileError>
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.mldfile or directory containing.mldfilesnamespace- The current namespace stack (directory names are appended during traversal)
§Errors
Returns DirectoryOrFileError of this kind:
PathNotFoundif the path doesn’t existOpeningFileif a file cannot be openedParsingif a file contains invalid dataReadingDirectoryif 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
impl MultilinearParser
Sourcepub fn add_new_aspect(
&mut self,
aspect_name: &str,
default_name: &str,
) -> Result<Aspect, AspectAddingError>
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.
Sourcepub fn parse<R: Read>(
&mut self,
reader: R,
parent_namespace: &[Box<str>],
) -> Result<(), Error>
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 fromnamespace- 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();Sourcepub fn into_info(self) -> NamedMultilinearInfo
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.